﻿/***************************/
//@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 loadPopupCovergrain(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupCovergrain").css({
			"opacity": "0"
		});
		$("#backgroundPopupCovergrain").fadeIn("slow");
		$("#popupCovergrain").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopupNicolas(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupNicolas").css({
			"opacity": "0"
		});
		$("#backgroundPopupNicolas").fadeIn("slow");
		$("#popupNicolas").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopupSimonm(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupSimonm").css({
			"opacity": "0"
		});
		$("#backgroundPopupSimonm").fadeIn("slow");
		$("#popupSimonm").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopupSimonl(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupSimonl").css({
			"opacity": "0"
		});
		$("#backgroundPopupSimonl").fadeIn("slow");
		$("#popupSimonl").fadeIn("slow");
		popupStatus = 1;
	}
}


//disabling popup with jQuery magic!
function disablePopupCovergrain(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupCovergrain").fadeOut("slow");
		$("#popupCovergrain").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopupNicolas(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupNicolas").fadeOut("slow");
		$("#popupNicolas").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopupSimonm(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupSimonm").fadeOut("slow");
		$("#popupSimonm").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopupSimonl(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupSimonl").fadeOut("slow");
		$("#popupSimonl").fadeOut("slow");
		popupStatus = 0;
	}
}


//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").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!
	$("#covergrain").click(function(){
		loadPopupCovergrain();
	});
	$("#nicolas").click(function(){
		loadPopupNicolas();
	});
	$("#simonm").click(function(){
		loadPopupSimonm();
	});
	$("#simonl").click(function(){
		loadPopupSimonl();
	});

				
	//CLOSING POPUP
	//Click the x event!
	$("#popupCovergrainClose").click(function(){
		disablePopupCovergrain();
	});
	$("#popupNicolasClose").click(function(){
		disablePopupNicolas();
	});
	$("#popupSimonmClose").click(function(){
		disablePopupSimonm();
	});
	$("#popupSimonlClose").click(function(){
		disablePopupSimonl();
	});
	
	//Click out event!
	$("#backgroundPopupCovergrain").click(function(){
		disablePopupCovergrain();
	});
	$("#backgroundPopupNicolas").click(function(){
		disablePopupNicolas();
	});
	$("#backgroundPopupSimonm").click(function(){
		disablePopupSimonm();
	});
	$("#backgroundPopupSimonl").click(function(){
		disablePopupSimonl();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopupCovergrain();
		}
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopupNicolas();
		}
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopupSimonm();
		}
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopupSimonl();
		}
	});

});
