﻿
var popupStatus = 0;

function loadPopup(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#InscriptionPop").fadeIn("slow");
		popupStatus = 1;
	}
}

function FermerPop(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#InscriptionPop").fadeOut("slow");
		popupStatus = 0;
	}
}

function centrerPopup(){

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#InscriptionPop").height();
	var popupWidth = $("#InscriptionPop").width();

	$("#InscriptionPop").css({"position": "absolute","top": windowHeight/2-popupHeight/2,"left": windowWidth/2-popupWidth/2});
	$("#backgroundPopup").css({"height": windowHeight});
}

$(document).ready(function(){

	var nbre_popup = $("input.compteur").val();
	
	for(i=0 ; i<=nbre_popup ; i++)
	{ 
		$("#Ouvrir_"+i).click(function(){
			$('html,body').animate({scrollTop: 0}, 'slow');
				centrerPopup();
				loadPopup();
		});
	}

	$("#Fermer").click(function(){
		FermerPop();
	});

	$("#backgroundPopup").click(function(){
		FermerPop();
	});

});
