﻿/***************************/
//@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 popupStatusShow = 0;

//loading popup with jQuery magic!
function loadShowPopup(){
	//loads popup only if it is disabled
	if(popupStatusShow==0){
		$("#backgroundPopupShow").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupShow").fadeIn("slow");
		$("#popupShow").fadeIn("slow");
		
		popupStatusShow = 1;
	}
}

//disabling popup with jQuery magic!
function disableShowPopup(){
	//disables popup only if it is enabled
	if(popupStatusShow==1){
		$("#backgroundPopupShow").fadeOut("slow");
		$("#popupShow").fadeOut("slow");
		popupStatusShow = 0;
	}
}

//centering popup
function centerShowPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupShow").height();
	var popupWidth = $("#popupShow").width();
	//centering
	$("#popupShow").css({
		"position": "absolute",
		"top": windowHeight / 2 - popupHeight / 2 + $(window).scrollTop() + "px",
		"left": windowWidth / 2 - popupWidth / 2 + $(window).scrollLeft() + "px"
	});
	//only need force for IE6
	
	$("#backgroundPopupShow").css({
		"height": windowHeight
	});
	
}

function popUpShow() {        
    //centering with css
    centerShowPopup();
    //load popup
    loadShowPopup();
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#ShowButton").click(function(){	    
		//centering with css		
		centerShowPopup();
		//load popup
		loadShowPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupShowClose").click(function(){
		disableShowPopup();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#btnSubmitShow").click(function() {
        disableShowPopup();
    });	
	
	//Click out event!
	$("#backgroundPopupShow").click(function(){
		disableShowPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusShow==1){
			disableShowPopup();
		}
	});

});