﻿/***************************/
//@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 show_hide(vis, hid, hid1, hid2) {
    $("#" + vis).css("display", "block");
    $("#" + hid).css("display", "none");
    $("#" + hid1).css("display", "none");
    $("#" + hid2).css("display", "none");
}

function show_quest(vis) {
    $("#" + vis).css("display", "block");
}

function show_hide_category(vis, hid) {
    alert($("#" + vis).html());
    $("#" + vis).css("display", "block");
    $("#" + hid).css("display", "none");
}

function loadPopup(){
 	if(popupStatus==0){ 	   
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
    }
}

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

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var ScreenHeight = screen.height;
	var ScreenWidth = screen.width;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();	
	var TopPos = Math.round((parseInt(screen.height) * 15) / 100);
	var LeftPos = Math.round((parseInt(screen.width) * 30) / 100);
	var TopHeight = Math.round((parseInt(windowHeight / 2.3) - parseInt(popupHeight / 2.3)));
	var LeftWidth = Math.round((parseInt(windowWidth / 2.3) - parseInt(popupWidth / 2.3)));

	var left = (screen.width / 2) - ($("#popupContact").width() / 2);
	var top = (screen.height / 2) - ($("#popupContact").height() / 2);
	
	//alert('ScreenHeight : ' + ScreenHeight + 'windowHeight : ' + windowHeight + 'ScreenWidth : ' + ScreenWidth + 'windowWidth : ' + windowWidth + 'TopHeight : ' + TopHeight + 'TopPos : ' + TopPos + 'LeftWidth : ' + LeftWidth + 'LeftPos : ' + LeftPos);	
	//centering
	$("#popupContact").css({
	"top": TopHeight,
	"left": LeftWidth
	});
	//only need force for IE6
	$("#backgroundPopup").css({
	    "height": ScreenHeight,
	    "display": "block",
	    "width": ScreenWidth
	});	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {
    //LOADING POPUP
    //Click the button event!
    $("img.img_queti").click(function() {
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function() {
        disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
});
