﻿/***************************/
//@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;
var popupStatus2 = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled	
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popup").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopup2(){
	//loads popup only if it is disabled	
	if(popupStatus2==0){
		$("#backgroundPopup2").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup2").fadeIn("slow");
		$("#popup2").fadeIn("slow");
		popupStatus2 = 1;
	}
}








//disabling popup with jQuery magic!
function disablePopup(element){
	//disables popup only if it is enabled
	element.focus();
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popup").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopup2(element){
	//disables popup only if it is enabled
	element.focus();
	if(popupStatus2==1){
		$("#backgroundPopup2").fadeOut("slow");
		$("#popup2").fadeOut("slow");
		popupStatus2 = 0;
	}
}







//centering popup
function centerPopup(str_top, str_left){
	//request data for centering
	//$("#popupContent").html(str);
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	var popupWidth = $("#popup").width();
	//centering
	/*$("#popup").css({
		"position": "absolute",
		"top": 1005,
		"left": (windowWidth/2-popupWidth/2)+340
	});
	*/
	$("#popup").css({
		"position": "absolute",
		"top": str_top+10,
		"left": str_left-150
	});
	//only need force for IE6
	
	/*$("#backgroundPopup").css({
		"height": popupHeight
	});*/
	
}
function centerPopup2(){
	//alert('testing');
	//request data for centering
	//$("#popupContent").html(str);
	var popupHeight = $("#popup2").height();
	var popupWidth = $("#popup2").width(); 
	
	var windowWidth;
	if(window.innerWidth != undefined) { windowWidth = window.innerWidth; }
	else {
		var windowElmnt = document.documentElement;
		if(windowElmnt) { 
			windowWidth = windowElmnt.clientWidth; 
		}
	}
	
	//var windowWidth = window.innerWidth || document.getElementByTagName('html').clientWidth;
	//alert(windowWidth + ' : ' + popupWidth);
	$("#popup2").css({
		"position": "absolute",
		"top": 100,
		"left": (windowWidth/2 - popupWidth/2 )
		
	});
	
}



//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//Click the x event!
	$("#frm_invite_cancel").click(function(){
		//str_name2 = document.entryForm.name2.value;	
		//str_name3 = document.entryForm.name3.value;
	
	
			disablePopup(this);
		
	});
	$("#frm_newsletter_cancel").click(function(){
		//str_name2 = document.entryForm.name2.value;	
		//str_name3 = document.entryForm.name3.value;
	
	
			disablePopup2(this);
		
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup(this);
	});
	//Click out event!
	$("#backgroundPopup2").click(function(){
		disablePopup2(this);
	});
	//Press Escape event!
	$(document).keypress(function(e){
		//disablePopup();
	});

});
