﻿/***************************/
//@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(divID,bkDivID){
	//loads popup only if it is disabled
    if (popupStatus == 0) {
        var backgroundDivID = "#" + bkDivID;
        $(backgroundDivID).css({
			"opacity": "0.7"});        $(backgroundDivID).fadeIn("medium");
        var div = "#" + divID;
		$(div).fadeIn("slow");
		popupStatus = 1;
		//$("#txtUserName").focus();
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupHome").fadeOut("slow");
		$("#popupContact").fadeOut("slow");	
		popupStatus = 0;
		
	}
}
function disablePopup2() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContactEditDescription").fadeOut("slow");
        popupStatus = 0;

    }
}


//centering popup
function centerPopup(divID){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;

	var div = "#" + divID;
	var popupHeight = $(div).height();
	var popupWidth = $(div).width();

	//centering
	$(div).css({
		"position": "absolute",
		"top": windowHeight/4-popupHeight/4,
		"left": windowWidth/4-popupWidth/4
});
	//only need force for IE6
	
	
}
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#buttonPop").click(function(){
		//centering with css
		centerPopup("popupContact");
		//load popup
		loadPopup("popupContact","backgroundPopupHome");
	});
	
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseHome").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopupHome").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
$(document).ready(function () {

    //LOADING POPUP
    //Click the button event!
    $("#buttonPopEditDescription").click(function () {
        //centering with css
        centerPopup("popupContactEditDescription");
        //load popup
        loadPopup("popupContactEditDescription", "backgroundPopup");
    });


    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function () {
        disablePopup2();
    });
    //Click out event!
    $("#backgroundPopup").click(function () {
        disablePopup2();
    });
    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
});
