/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(ggg){
	//loads popup only if it is disabled
	//alert($(ggg));
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(ggg).next().fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".div_enter").fadeOut("slow");
		$(".div_vip").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(elem){
	//request data for centering
	var windowWidth = ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.scrollWidth );
	var windowHeight = ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.scrollHeight );
	var popupHeight = $(elem).next().height();
	var popupWidth = $(elem).next().width();
	//centering
//windowWidth = (windowWidth + 50);
var sssss = $(window).scrollTop();

	//alert(windowWidth);
	$(elem).next().css({
		"position": "absolute",
		"top": sssss + 150,
		"left": (windowWidth/2-35)-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight,
		"width": (windowWidth)
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//alert(document.body.clientHeight);
	//alert(document.body.offsetHeight);
	//alert(document.body.scrollHeight);

	//LOADING POPUP
	//Click the button event!
	$(".enter").click(function(){
		//centering with css
		centerPopup(this);
		//load popup
		loadPopup(this);
	});
	
	$(".vip_link").click(function(){
		//centering with css
		centerPopup(this);
		//load popup
		loadPopup(this);
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".type_close").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
