$(document).ready(function() {
  $("a.lightbox").nyroModal({galleryCounts:null,modal:false});
  if(!$.browser.msie) { $(window).resize(setFooter); }
  setFooter();
  setColumns();
  justifyMaskPic("a[class^='mask'] img");
  var phrase = $("input#searchphrase").val();
  $("input#searchphrase").focus(function(){
    if($(this).val()==phrase) { $(this).val(''); }
  }).blur(function(){
    if($(this).val()=='') { $(this).val(phrase); }
  });
});

function setFooter() {
  var h = $(document).height();
  var m = $("#main").innerHeight();
  var f = $("#footer").innerHeight();
  if(f+m<h) { $("#main").height(h-f); }
}

function setColumns() {
  $("#content .column2main").each(function(){
    if($(this).find(".column .col_main").length && $(this).find(".column .col_main").length==2) {
      var h1 = $(this).find(".column .col_main:first").innerHeight();
      var h2 = $(this).find(".column .col_main:last").innerHeight();
      if(h1<h2) {
        h1 = $(this).find(".column .col_main:first").height() + (h2-h1);
        $(this).find(".column .col_main:first").height(h1);
      } else {
        h2 = $(this).find(".column .col_main:last").height() + (h1-h2);
        $(this).find(".column .col_main:last").height(h2);
      }
    }
  });
}

function justifyMaskPic(e) {
  $(e).each(function(){
    var h = $(this).innerHeight();
    if(h!=undefined && h>0) {
      justifyMaskFinal(this);
    } else {
      $(this).load(function(){ justifyMaskFinal(this); });
    }
  });
}

function justifyMaskFinal(e) {
  var msk = $(e).parent().innerHeight();
  var pic = $(e).innerHeight();
  var m = Math.round((msk-pic)/2);
  if(m!='' && m!=0) { $(e).css("margin-top",m); }  
  msk = $(e).parent().innerWidth();
  pic = $(e).innerWidth();
  m = Math.round((msk-pic)/2);
  if(m!='' && m!=0) { $(e).css("margin-left",m); }  
}

function submitOfferform() {
  if($("#offer_vorname").val()=='') {
    alert('Bitte geben Sie Ihren Vornamen an.');
    return false;
  }
  if($("#offer_nachname").val()=='') {
    alert('Bitte geben Sie Ihren Nachnamen an.');
    return false;
  }
  if($("#offer_strasse").val()=='') {
    alert('Bitte geben Sie Ihre Straße an.');
    return false;
  }
  if($("#offer_ort").val()=='') {
    alert('Bitte geben Sie Ihre Wohnort an.');
    return false;
  }
  if($("#offer_email").val()=='') {
    alert('Bitte geben Sie Ihre E-Mail Adresse an.');
    return false;
  }
  $("form.offerform").submit();
  return false;
}

function submitContactform() {
  if($("#contact_vorname").val()=='') {
    alert('Bitte geben Sie Ihren Vornamen an.');
    return false;
  }
  if($("#contact_nachname").val()=='') {
    alert('Bitte geben Sie Ihren Nachnamen an.');
    return false;
  }
  if($("#contact_email").val()=='' && ($("#contact_strasse").val()=='' || $("#contact_ort").val()=='')) {
    alert('Bitte geben Sie Ihre E-Mail Adresse oder Ihre Anschrift an.');
    return false;
  }
  if($("#contact_nachricht").val()=='') {
    alert('Bitte schreiben Sie eine Nachricht.');
    return false;
  }
  $("form.contactform").submit();
  return false;
}

function initSlideshow() {
  $(document).ready(function() {
    var so = new SWFObject("/BMT/DE/flash/slideShow.swf","flashhead","508","338","8","#ffffff");
    so.addParam("wmode", "transparent");
    so.write("slideshow");
  });
}

function initSlideshow2() {
  $(document).ready(function() {
    var so = new SWFObject("/BMT/DE/flash/slideShow_Kinderaktion.swf","flashhead","508","338","8","#ffffff");
    so.addParam("wmode", "transparent");
    so.write("slideshow");
  });
}

function slideshowInit(p) {
  $(document).ready(function() {
    var so = new SWFObject("/Fachklinik/flash/slideShow.swf","flashhead","508","338","8","#ffffff");
    so.addParam("wmode","transparent");
    so.addParam("flashvars","bildpfad="+p);
    so.write("slideshow");
  });
}

function doBM(s) {
  var u = encodeURIComponent(location.href);
  var t = encodeURIComponent(document.title);
  switch(s) {		
    case 'delicious': window.open('http://del.icio.us/post?url='+u+'&title='+t); break;
    case 'wong': window.open('http://www.mister-wong.de/index.php?action=addurl&bm_url='+u+'&bm_description='+t); break;
    case 'linkarena': window.open('http://linkarena.com/bookmarks/addlink/?url='+u+'&title='+t+'&desc=&tags='); break;
    case 'webnews': window.open('http://www.webnews.de/einstellen?url='+u+'&title='+t); break;
    case 'yigg': window.open('http://yigg.de/neu?exturl='+u+'&exttitle='+t); break;
    case 'google': window.open('http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+u+'&title='+t); break;
  }
  return false;
}

