$(window).load(function() {
	/*$("#ajaxLoader").hide();
	$("#fadeInContent").fadeIn('slow');*/
	
	if ($('div#buttonTopLayer').length != 0) {
		$('div#buttonTopLayer').show();
		$('div#buttonTopLayer img').click(function() {
			//$("div#pageWrapper").scrollTop(0);
			$('html,body').animate({
				scrollTop: 0
			}, 350);
		});
	}

});
	
$(document).ready(function() {

	// pngFix
	$(document).pngFix();
	checkLayerSize();

	
	if ($('a.fancybox').length != 0) {
		$("a.fancybox").fancybox({
			'padding'			: 0,
			'titleShow'			: true,
			'titlePosition'		: 'outside',
			'cyclic'			: true,
			'overlayOpacity' 	: 0.8,
			'overlayColor' 		: '#333',
			'showNavArrows'		: 'true',
			'onComplete'		: function() {
				$("#fancybox-wrap").hover(function() {
					$("#fancybox-title").show();
				}, function() {
					$("#fancybox-title").hide();
				});
			}
		});
	}

	$("#somniumlogo img").mouseenter(function(){
		$(this).fadeTo(300,0.5);
	}).mouseleave(function() {
		$(this).fadeTo(300,1);
	});
	
	// Rollover Heart
	$("img#heart").hover(function(){
		this.src = this.src.replace('_off.gif','_on.gif');
	},function(){
		this.src = this.src.replace('_on.gif','_off.gif');
	});
	$("img#facebookfooter").hover(function(){
		this.src = this.src.replace('_off.jpg','_on.jpg');
	},function(){
		this.src = this.src.replace('_on.jpg','_off.jpg');
	});

	// Rollover Social Media
	$("div#socialmediaLayer img").hover(function(){
		this.src = this.src.replace('_off','_on');
	},function(){
		this.src = this.src.replace('_on','_off');
	});

	// Rollover Tabelle
	$("td.linkClass img").hover(function(){
		var src = $(this).attr("src").match(/[^\.]+/) + "_over.gif";
		$(this).attr("src",src);
	},function(){
		var src = $(this).attr("src").replace("_over","");
		$(this).attr("src", src);
	});

	$('table.listClass tr').bind({
		mouseenter: function() {
			$(this).children("td").css('backgroundColor','#f9f9f9');
			if($(this).attr("class") != "nolink") {
				$(this).css("cursor","pointer");
			}
		},
		mouseleave: function() {
			$(this).children("td").css('backgroundColor','transparent');
			$(this).css("cursor","auto");
		}
	});

	var tempCounter = 0;
	$('table.listClass tr').click(function() {
		tempCounter++;
		if (tempCounter == 1) {
			tempStr = $(this).children('td.linkClass').children("a.linkClass").attr('class');
			tempTarget = $(this).children('td.linkClass').children("a.linkClass").attr('target');
			tempLink = $(this).children('td.linkClass').children("a.linkClass").attr('href');
			if (tempStr == "linkClass fancybox") {
				$(this).children('td.linkClass').children("a.linkClass").trigger('click');
			} else if (tempStr == "linkClass") {
				if (tempTarget == "_blank") {
					projectWindow = window.open(tempLink, "projectWindow");
					projectWindow.focus();
				} else {
					document.location.href = tempLink;
				}
			} else {
				//alert('kein Link');
			}
		}
		tempCounter = 0;
	});

});

function checkLayerSize() {
	// Definition Abmessungen
	vpH = $(window).height();					// viewport height
	layoutH = $('div#layoutWrapper').height();	// page height

	// Anpassung bodyWrapper
	var dH = layoutH-vpH;
	if (dH < 0) {
		$('div#bodyWrapper').css('height', function() {
			return $('div#bodyWrapper').height() + Math.abs(dH);
		});
	}
}

function loadingAjax(div_id, filename)  
{  
  $("#ajaxLoader").show();
  $("#"+div_id).html();
  $.ajax({  
      type: "POST",  
      url: filename,  
      data: "",  
      success: function(msg){  
      	$("#ajaxLoader").hide();
      	$("#"+div_id).hide().html(msg).fadeIn();  
      }  
  });  
}  
