﻿/* jQuery popup for Alsol.fr */

// Variables
var popupStatus = 0; // statut : 0 invisible / 1 visible

// Affiche la popup
function displayPopup(popupID){
	if(popupStatus==0){ // si elle est invisible
		$("#backgroundPopup").css({opacity:"0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$(popupID).fadeIn("slow");
		popupStatus = 1;
	}
}

// Cache la popup
function hidePopup(popupID, relocation){
	
		$("#backgroundPopup").fadeOut("slow");
		$(popupID).fadeOut("slow");
		popupStatus = 0;
		if(relocation)
		{
		document.location.href= relocation; // redirige vers la page envoyée en parametre
		}
}

//Centre la popup
function centerPopup(popupID, top){

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(popupID).height();
	var popupWidth = $(popupID).width();

	
		if(top)
		{
			$(popupID).css({
			top: top,
			left: windowWidth/2-popupWidth/2
			});
		}
		else
		{
			$(popupID).css({
			top: windowHeight/2-popupHeight/2,
			left: windowWidth/2-popupWidth/2
			});
		}
}

function myPopup(popupID, relocation, top) { // ID de la popup, Options adresse de redirection && positions

	$(document).ready(function()
	{
		centerPopup(popupID, top);
		displayPopup(popupID);
		
		// Fermeture de la popup
		$(".popupClose").click(function(){
			hidePopup(popupID, relocation);
		});
		$(".popupClose2").click(function(){
			hidePopup(popupID, relocation);
		});
		$("#backgroundPopup").click(function(){
			hidePopup(popupID, relocation);
		});
	});

}