﻿/***************************/
//@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(bg,pop){
	//loads popup only if it is disabled
	if(popupStatus==0){
		bg.css({
			"opacity": "0.7"
		});
		bg.fadeIn("slow");
		pop.fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(bg,pop){
	//disables popup only if it is enabled
	if(popupStatus==1){
		bg.fadeOut("slow");
		pop.fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(bg,pop){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = pop.height();
	var popupWidth = pop.width();
	//centering
	pop.css({
		"position": "absolute",
		"top": 50,/* windowHeight/2-popupHeight/2,*/
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	bg.css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {





    //LOADING POPUP
    //Click the button event!
    $("#bLink1").click(function() {
        //centering with css
        centerPopup($("#backgroundPopup"), $("#popupContact1"));
        //load popup
        loadPopup($("#backgroundPopup"), $("#popupContact1"));
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose1").click(function() {
        disablePopup($("#backgroundPopup"), $("#popupContact1"));
    });
    //Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup($("#backgroundPopup"), $("#popupContact1"));
    });
    //Press Escape event!
   
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup($("#backgroundPopup"), $("#popupContact1"));
        }
    });

});