﻿/***************************/
//@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(nom_popup){
	//loads popup only if it is disabled
	var popupStatus = 0;
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		//$("#popupContact").fadeIn("slow");
		$("#" + nom_popup).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(nom_popup){
	//disables popup only if it is enabled
	var popupStatus = 1;
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		//$("#popupContact").fadeOut("slow");
		$("#" + nom_popup).fadeOut("slow");
		//$("#compagnie_DE").fadeOut("slow");
		popupStatus = 0;
		//alert(nom_popup)
	}
}
http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/
//centering popup
function centerPopup(nom_popup){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	//var popupHeight = $("#popupContact").height();
	//var popupWidth = $("#popupContact").width();
	var popupHeight = $("#" + nom_popup).height();
	var popupWidth = $("#" + nom_popup).width();
	
	newHeight = Number((windowHeight/2)-(popupHeight/2));
	newWidth = Number((windowWidth/2)-(popupWidth/2));
	
	scrOfY = 0;
	scrOfX = 0;
	if( typeof( window.pageYOffset ) == 'number' ) 
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
  	} 
	else 
		if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
			{
				//DOM compliant
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
		  	} 
			else 
				if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
					{
						//IE6 standards compliant mode
						scrOfY = document.documentElement.scrollTop;
						scrOfX = document.documentElement.scrollLeft;
					}

	
	
	newHeight += Number(scrOfY)
	newWidth += Number(scrOfX)
	
	//alert(window.pageYOffset)
	//centering
	///$("#popupContact").css({
	$("#" + nom_popup).css({
		"position": "absolute",
		"top": newHeight,
		"left": newWidth
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function ouvrir_popup(nom_popup)
{
		
	centerPopup(nom_popup);
	loadPopup(nom_popup);
}
	

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
						   //Click out event!
	$("#backgroundPopup").click(function(){
		$("div[id^=div_pp]").each(function(i){ disablePopup(this.id)});
	});
/*	disablePopup(this.id)
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
*/
});

