﻿//SETTING UP OUR POPUP

//0 means disabled; 1 means enabled;

var popupStatus = new Array(100);

 

for(k=0; k<100; k++)
{
            popupStatus[k] = 0;
}
 
//loading popup with jQuery magic!

function loadPopup(ident){
            //loads popup only if it is disabled
            var id = ident.replace("button","");
            if(document.getElementById("popupClose"+id) != undefined)
            {           
                        if(popupStatus[id-1]==0){
                                   $("#backgroundPopup").css({
                                               "opacity": "0.8"
                                   });
                                   $("#backgroundPopup").fadeIn("slow");
                                   $("#popup" + id).fadeIn("slow");
                                   popupStatus[id-1] = 1;
                        }
            }else{
                        disablePopup(id);
            }
}
//disabling popup with jQuery magic!
function disablePopup(id){
            var divPopup = "#popup"  + id;
           //disables popup only if it is enabled
            if(popupStatus[id-1]==1){
                        $("#backgroundPopup").fadeOut("slow");
                        $(divPopup).fadeOut("slow");
                        popupStatus[id-1] = 0;
            }
}


function centerPopup(ident){

            var id = ident.replace("button","");
            var divPopup = "#popup"  + id;
     
	//request data for centering
	 var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight; 
	
 	var contenuWidth = document.getElementById("contenucentral").clientWidth;
 	var contenuHeight = document.getElementById("contenucentral").clientHeight;
	
	var windowTop = document.documentElement.scrollTop;
	//var windowLeft = document.documentElement.screenLeft;
   	
	var popupHeight = $(divPopup).height();
	var popupWidth = $(divPopup).width();

		var maxWidth = windowWidth/2;
		var maxHeight = windowHeight/2;
	 
	 
		
		var top = 0; 	  
		if(windowTop==0){
			top = 5;
		  }else{
			top = windowTop-popupHeight/2;
		  }
		  
	   $(divPopup).css({
	   	
						
						//	 "top": windowHeight/2-popupHeight/2, 
						//	 "left": windowLeft/2+contenuWidth/2-w/2
						// "left": windowWidth/2-popupWidth/2,
						 // "top":  windowTop/4,
						  
						  "position": "absolute",
						"top": top,
						   "left": 10
						 
					});
	   
	 		 
	 	 
	//only need force for IE6
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//centering popup Video

function centerPopupPlayer(ident){

            var id = ident.replace("button","");
            var divPopup = "#popup"  + id;
     
	//request data for centering
	 var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight; 
	
//	var contenuWidth = document.getElementById("contenucentral").clientWidth;
//	var contenuHeight = document.getElementById("contenucentral").clientHeight;
	
	var windowTop = document.documentElement.scrollTop;
//	var windowLeft = document.documentElement.screenLeft;
   	
	var popupHeight = $(divPopup).height();
	var popupWidth = $(divPopup).width();

	 
	   $(divPopup).css({
						"position": "absolute",
						/*"top": windowHeight/2-popupHeight/2,*/
						
						"top": windowTop-popupHeight/2,
						//"left": windowWidth/2-popupWidth/2
						"left": 10
					});
	 	 
	 	 
	//only need force for IE6
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
             //Click out event!
            $("#backgroundPopup").click(function(){
                        for (i=1; i<100; i++) {
                                   disablePopup(i);
                        }
            });
            //Press Escape event!
            $(document).keypress(function(e){
                        for (i=1; i<100; i++) {
                                   if(e.keyCode==27 && popupStatus[i-1]==1){
                                               disablePopup(i);
                                   }
                        }
            });

});
