// Visible browser dimensions
var visibleWidth   = Number(getWinSize(window).width);
var visibleHeight  = Number(getWinSize(window).height);

$(document).ready(function() {

	// Animate home
	if(document.getElementById('content-home') != null) {
		// Animate Loader
    $("div#loader").animate( { width:"100%" }, 3000, function(){
		  $("div#loader").fadeOut("fast");
    });
		// Fade in logo on home page
    $("img#logo-home").delay(500).fadeIn(10);

    // Overflow hidden to prevent body scrollbar
    $("body").css('overflow', 'hidden');

    // Animate content
		$("#content-home").css('margin-top', 2000);
		$("#content-home").delay(1000).animate( {  marginTop: '29px' }, 1500 );
	}

	// Animate Impressum, Vita and Portfolio
	if(document.getElementById('content') != null) {
    // Overflow hidden to prevent body scrollbar
    $("body").css('overflow', 'hidden');

    // Animate content
		$("#content").css('margin-top', '2000px');
		$("#content").animate( {  marginTop: '0px' }, 1000 , function(){
			$("body").css('overflow', 'auto');
		});
	}

	// Animate Kontakt
	if(document.getElementById('content-single') != null && (document.getElementById('tx-jbarts-pi1') == null)) {
		// Overflow hidden to prevent body scrollbar
    $("body").css('overflow', 'hidden');

    // Animate content
		$("#content-single").css('margin-top', '2000px');
		$("#content-single").animate( {  marginTop: '33px' }, 1000 , function(){
			$("body").css('overflow', 'auto');
		});
	}

	// Animate content buttons on mouseover
  $("div.tx-jbbuttons-pi1 img").mouseover(function(){
		$(this).stop();
  	$(this).animate( {marginTop : '0px'}, 200);
  });

  $("div.tx-jbbuttons-pi1 input").mouseover(function(){
    $(this).stop();
  	$(this).animate( {marginTop : '0px'}, 200);
  });

  // Animate content buttons on mouseout
  $("div.tx-jbbuttons-pi1 img").mouseout(function(){
		$(this).stop();
  	$(this).animate( {marginTop : '-24px'}, 200);
  });

  $("div.tx-jbbuttons-pi1 input").mouseout(function(){
    $(this).stop();
  	$(this).animate( {marginTop : '-24px'}, 200);
  });

  // Set width of navigation dynamically (for some dumb browsers like Opera)
  $("#navigation ul").css("width", $("#navigation ul").width());

  // Move nav points up to make them invisble
  $("#navigation ul li").each(function(){
  	$(this).css("marginTop", "-17px");
  });

  // Let nav points fall down asynchronously
  $("#navigation ul li").eachDelay(function(){
    $(this).animate( {marginTop: '0px'} );
  },150);

  // Animate nav points at mouseover/mouseout like a station clock
  $("#navigation ul li img").not("#navigation ul li.active img").mouseover(function(){
  	$(this).animate( {marginTop : '0px'},200 );
  });

  $("#navigation ul li img").not("#navigation ul li.active img").mouseout(function(){
  	$(this).animate( {marginTop : '-22px'},200 );
  });

  $("#footer ul li.page img").not("#footer ul li.page.active img").mouseover(function(){
  	$(this).animate( {marginTop : '0px'},200 );
  });

  $("#footer ul li.page img").not("#footer ul li.page.active img").mouseout(function(){
  	$(this).animate( {marginTop : '-15px'},200 );
  });

  // Empty contact form input fields on focus
  $('div.tx-jbcontactform-pi1 div.formentry input').focusin(function(){
  	if(eraseContactValues[this.name] == 1) {
  	  eraseContactValues[this.name] = 0;
  		this.value = '';
  	}
  });

  // Empty contact form textarea on focus
  $('div.tx-jbcontactform-pi1 div.formentry textarea').focusin(function(){
  	if(eraseContactValues[this.name] == 1) {
  	  eraseContactValues[this.name] = 0;
  		this.value = '';
  	}
  });


  if(document.getElementById('slideshow-image')) {
	  $('#slideshow-image .image').cycle({
	    fx:     'fade',
	    speed:  1500,
	    timeoutFn: function(currSlideElement, nextSlideElement, options, forwardFlag) {
				if(typeof nextSlideElement['alt'] != 'undefined')
	    	  $("#slideshow-title").html(nextSlideElement['alt']);
	    	return 7000;
	    },
	    pager: '.tx-jbslideshow-pi1 .navigation .paging',
	    before: animateSlideshowLoader(),
	    pagerClick: function(zeroBasedSlideIndex, slideElement) {
	    	$("#slideshow-loader").stop();
	    	$("#slideshow-loader").css("width", "0px");
		    $("#slideshow-loader").animate( {width:'100%'}, 7000, function(){
			    animateSlideshowLoader();
		    });
	    }
	  });
  }

}); // end $(document).ready


function animateSlideshowLoader() {
	$("#slideshow-loader").css("width", "0px");
	$("#slideshow-loader").animate( {width:'100%'}, 7000, function(){
		animateSlideshowLoader();
	});
}

function getWinSize(win) {
  if(!win) win = window;
  var s = new Object();

  if(typeof win.innerWidth != 'undefined') {
    s.width = win.innerWidth;
    s.height = win.innerHeight;
  }
  else {
    var obj = getBody(win);
    s.width = parseInt(obj.clientWidth);
    s.height = parseInt(obj.clientHeight);
  }
  return s;
}

function getBody(w) {
  return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}