﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
//
//@Fork ^^
//@author: eka808
//@website : http://www.itheac.fr
//@licence : copyleft
/***************************/

//SETTING UP OUR Popin
//0 means disabled; 1 means enabled;
var PopinStatus = 0;

//loading Popin with jQuery magic!
function loadPopin(num){
	//loads Popin only if it is disabled
	if(PopinStatus==0){
		//Gestion de l'arrière plan
		$("#back_popin").css({
			"opacity": "0.7"
		});
		$("#back_popin").fadeIn("slow");
		
		//Affichage du Popin
		$("#lepopin_"+num).fadeIn("slow");
		PopinStatus = 1;
	}
}

//disabling Popin with jQuery magic!
function disablePopin(num){
	//disables Popin only if it is enabled
	if(PopinStatus==1){
		$("#back_popin").fadeOut("slow");
		$(".lepopin").fadeOut("slow");
		PopinStatus = 0;
	}
}

/**Centrage du Popin
 *@modify : 15/05/09 (gestion du scrolltop
 */
function centerPopin(num){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var PopinHeight = $("#lepopin_"+num).height();
	var PopinWidth = $("#lepopin_"+num).width();
	var ScrollTop = $(document).scrollTop(); //Pour gérer décalage si lien depuis page avec ascensceur
	//centering
	$("#lepopin_"+num).css({
		"position": "absolute",
/*		"top": ScrollTop + ( windowHeight/2-PopinHeight/2 ),	// pour scrolling avec centrage*/
		"top": 20 + ScrollTop,  //Pour scrolling sans centrage  
		"left": windowWidth/2-PopinWidth/2
	});
	//only need force for IE6
	
	$("#back_popin").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING Popin
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopin(1);
		//load Popin
		loadPopin(1);
	});
				
	//CLOSING Popin
	//Click the x event!
	$(".popinContactClose").click(function(){
		disablePopin(1);
	});
	//Click out event! du background
	$("#back_popin").click(function(){
		disablePopin(1);
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && PopinStatus==1){
			disablePopin(1);
		}
	});

});