//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.5"
		});
		$("#backgroundPopup").toggle();
		$("#popupContact").toggle();
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").toggle();
		$("#popupContact").toggle();
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var documentHeight;	
	if(navigator.appVersion.indexOf('MSIE 6.0') != -1)
	{
		documentHeight = document.body.clientHeight;
	}
	else
	{
		documentHeight = document.documentElement.clientHeight;
	}
	
	var windowHeight = document.documentElement.clientHeight;
	var windowWidth = document.documentElement.clientWidth;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//calculating percentage of visible screen to place the position top of the pop up
    var per_top = ((windowHeight * 10) /100);
	//centering
	$("#popupContact").css({
		//"position": "absolute",
		"top": per_top,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	
	$("#backgroundPopup").css({
		"height": documentHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	//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();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});

});	



function show_popup(name){
	centerPopup();
	loadPopup();
        document.getElementById(name).className = 'popupContactShow';
}

function close_popup(){
	if(document.getElementById('popupContent')){
		var div = document.getElementById('popupContent');
		var oKid = div.firstChild;
		while (oKid){
			oKid.className = 'popupContactHide';
			oKid = oKid.nextSibling;
	    }
	}
	
	return true;
}

function fillmypop(name){
	
	//var desc = document.getElementById("desc_" + name ).value;
	var desc = document.getElementById("desc_" + name ).innerHTML;
	var img = document.getElementById("img_" + name ).value;
	var namerecette = document.getElementById("name_" + name ).innerHTML;
	var titreCat = document.getElementById("titre_" + name).innerHTML;
	if(typeof(desc) != 'undefined' || desc != ''){
		document.getElementById('poprecettedesc').innerHTML = desc;
		document.getElementById('poprecettetitre').innerHTML = "<b>" + namerecette + "</b>";
		document.getElementById('poptitreRecette').innerHTML =  titreCat ;
		
		
	}
	
}
