$(document).ready(function() {
  $("a.lightbox").nyroModal({galleryCounts:null,modal:false});
  if(!$.browser.msie) { $(window).resize(doRezise); }
  doRezise();
  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 doRezise() {
  setFooter();
  setEmotion();
}

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

function setEmotion() {
  var w = $(window).width();
  $("#emotion_pic").find("#main").unwrap();
  if(w>1350) {
    if(w>(405*2)+977) { w = (405*2)+977; }
    var pos = Math.floor(((w-977)/2)+977-14);
    $("#main").wrap('<div id="emotion_pic" style="width:'+w+'px; background-position:'+pos+'px 0;"></div>');
  }
}

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 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("/TTZ/DE/flash/slideShow.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;
}

