var popupStatus = 0;


/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;


//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("div#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("div#backgroundPopup").fadeIn("slow");
		$("div#detailLayer").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("div#backgroundPopup").fadeOut("slow");
		$("div#detailLayer").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("div#detailLayer").height();
	var popupWidth = $("div#detailLayer").width();
	//centering
	$("div#detailLayer").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": 330
		//"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("div#backgroundPopup").css({
		"height": windowHeight
	});
	
}


$(document).ready(function() {
    $('div#mainTeaser1 ul').cycle({
		//fx: 'scrollRight', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: 2000,
		timeout:7000,
		pause:   0
	}); 
	
	setTimeout(function(){ 
		$('div#mainTeaser2 ul').cycle({
	
			//fx: 'scrollRight', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			speed: 2000,
			timeout:7000,
			pause:   0
		});
  		}, 1200 ); 
	
		$("div.referenzTeaser a").click(function() {
		      url = $(this).attr("href");
			   $.ajax({
			   	type: "POST",
			   	url: url,
			   	cache: false,
			   	data: "&type=101",
			  	success: function(html){			  				
			    			$("div#detailLayer").html(html);
			    			centerPopup();
			    			loadPopup();
			    			return false;
			  			 },
			  	statusCode: {
					404: function() {
			  				alert('page not found');
						}
						}
			 })
			return false;
		 });
	//Click out event!
	$("div#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});


