/***************************/
//@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;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupKoko").fadeIn("slow");
		popupStatus = 1;
	}
}

//LOAD ORIGINAL///////////////////////////////////////
function loadPopup_orig(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup_orig").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_orig").fadeIn("slow");
		$("#popupKoko_orig").fadeIn("slow");
		popupStatus = 1;
	}
}

//LOAD BIGBITE///////////////////////////////////////
function loadPopup_big(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup_big").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_big").fadeIn("slow");
		$("#popupKoko_big").fadeIn("slow");
		popupStatus = 1;
	}
}

//LOAD PIGGY///////////////////////////////////////
function loadPopup_piggy(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup_piggy").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_piggy").fadeIn("slow");
		$("#popupKoko_piggy").fadeIn("slow");
		popupStatus = 1;
	}
}

//LOAD SEASON///////////////////////////////////////
function loadPopup_season(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup_season").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_season").fadeIn("slow");
		$("#popupKoko_season").fadeIn("slow");
		popupStatus = 1;
	}
}

//LOAD CONTACTS///////////////////////////////////////
function loadPopup_contacts(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup_contacts").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_contacts").fadeIn("slow");
		$("#popupKoko_contacts").fadeIn("slow");
		popupStatus = 1;
	}
}

//LOAD FAQ///////////////////////////////////////
function loadPopup_faq(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup_faq").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_faq").fadeIn("slow");
		$("#popupKoko_faq").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupKoko").fadeOut("slow");
		popupStatus = 0;
	}
}

//DISABLE ORIGINAL////////////////////////////////
function disablePopup_orig(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup_orig").fadeOut("slow");
		$("#popupKoko_orig").fadeOut("slow");
		popupStatus = 0;
	}
}

//DISABLE BIGBITE////////////////////////////////
function disablePopup_big(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup_big").fadeOut("slow");
		$("#popupKoko_big").fadeOut("slow");
		popupStatus = 0;
	}
}

//DISABLE PIGGY////////////////////////////////
function disablePopup_piggy(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup_piggy").fadeOut("slow");
		$("#popupKoko_piggy").fadeOut("slow");
		popupStatus = 0;
	}
}

//DISABLE SEASON////////////////////////////////
function disablePopup_season(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup_season").fadeOut("slow");
		$("#popupKoko_season").fadeOut("slow");
		popupStatus = 0;
	}
}

//DISABLE CONTACTS////////////////////////////////
function disablePopup_contacts(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup_contacts").fadeOut("slow");
		$("#popupKoko_contacts").fadeOut("slow");
		popupStatus = 0;
	}
}

//DISABLE FAQ////////////////////////////////
function disablePopup_faq(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup_faq").fadeOut("slow");
		$("#popupKoko_faq").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupKoko").height();
	var popupWidth = $("#popupKoko").width();
	//centering
	$("#popupKoko").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		
		//load popup
		loadPopup();
	});
	
	
	//ORIGINAL
	$("#button_orig").click(function(){
		
		//load popup
		loadPopup_orig();
	});			
		
		
	//BIGBITE
	$("#button_big").click(function(){
		
		//load popup
		loadPopup_big();
	});		
	
		//PIGGY
	$("#button_piggy").click(function(){
		
		//load popup
		loadPopup_piggy();
	});
		
		//SEASON
	$("#button_season").click(function(){
		
		//load popup
		loadPopup_season();
	});
			
		//CONTACTS
	$(".button_contacts").click(function(){
		
		//load popup
		loadPopup_contacts();
	});
		
		//FAQ
	$(".button_faq").click(function(){
		
		//load popup
		loadPopup_faq();
	});
		
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupKokoClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backKokoPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	
	//CLOSING ORIGINAL
	//Click the x event!
	$("#popupKokoClose_orig").click(function(){
		disablePopup_orig();
	});
	//Click out event!
	$("#backKokoPopup_orig").click(function(){
		disablePopup_orig();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup_orig();
		}
	});
	
	//CLOSING BIGBITE
	//Click the x event!
	$("#popupKokoClose_big").click(function(){
		disablePopup_big();
	});
	//Click out event!
	$("#backKokoPopup_big").click(function(){
		disablePopup_big();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup_big();
		}
	});
	
	//CLOSING PIGGY
	//Click the x event!
	$("#popupKokoClose_piggy").click(function(){
		disablePopup_piggy();
	});
	//Click out event!
	$("#backKokoPopup_piggy").click(function(){
		disablePopup_piggy();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup_piggy();
		}
	});
	
	//CLOSING SEASON
	//Click the x event!
	$("#popupKokoClose_season").click(function(){
		disablePopup_season();
	});
	//Click out event!
	$("#backKokoPopup_season").click(function(){
		disablePopup_season();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup_season();
		}
	});
	
	//CLOSING CONTACTS
	//Click the x event!
	$("#popupKokoClose_contacts").click(function(){
		disablePopup_contacts();
	});
	//Click out event!
	$("#backKokoPopup_contacts").click(function(){
		disablePopup_contacts();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup_contacts();
		}
	});
	
	//CLOSING FAQ
	//Click the x event!
	$("#popupKokoClose_faq").click(function(){
		disablePopup_faq();
	});
	//Click out event!
	$("#backKokoPopup_faq").click(function(){
		disablePopup_faq();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup_faq();
		}
	});

});
