﻿/***************************/
//@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_me = 0;

//loading popup with jQuery magic!
function loadPopup_me(){
	//loads popup only if it is disabled
	if(popupStatus_me==0){
		$("#backgroundPopup_me").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_me").fadeIn("slow");
		$("#popupContact_me").fadeIn("slow");
		popupStatus_me = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup_me(){
	//disables popup only if it is enabled
	if(popupStatus_me==1){
		$("#backgroundPopup_me").fadeOut("slow");
		$("#popupContact_me").fadeOut("slow");
		popupStatus_me = 0;
	}
}

//centering popup
function centerPopup_me(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact_me").height();
	var popupWidth = $("#popupContact_me").width();
	//centering
	$("#popupContact_me").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup_me").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button_me").click(function(){
		//centering with css
		centerPopup_me();
		//load popup
		loadPopup_me();
	});
	//on_page_load - display popup even -- added by sankar_10/OCT2009 (this load function)
	$("#button_me").load(function(){
		//centering with css
		centerPopup_me();
		//load popup
		loadPopup_me();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose_me").click(function(){
		disablePopup_me();
	});
	//Click out event!
	$("#backgroundPopup_me").click(function(){
		disablePopup_me();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus_me==1){
			disablePopup_me();
		}
	});

});
