﻿/***************************/
//@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;
var PopID;
//loading popup with jQuery magic!
function loadPopup(obj) {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        /*$("#popupContact").fadeIn("slow");*/
        $(obj).fadeIn("slow");
        popupStatus = 1;
        $("#popupContactClose").css("display", "block");        
    }
}

//disabling popup with jQuery magic!
function disablePopup(obj) {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        /*$("#popupContact").fadeOut("slow");*/
        $(obj).fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup(obj) {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;    
    var popupHeight = $(obj).height();
    var popupWidth = $(obj).width();    
    //centering
    //if(obj != "#tblFeatures")
    //{    
        $(obj).css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2 - 10
        });
        $("#popupContactClose").css({
        "position": "absolute",    
        "padding": "10px", "top": windowHeight / 2 - popupHeight / 2 ,
        "left": windowWidth / 2 - popupWidth / 2,
        "z-index":"10"
        /*"text-align":"right"*/
        });
    //}
    //else
    //{
//        $(obj).css({
//            "position": "absolute",
//            "top": windowHeight / 2 - popupHeight / 2 + 35,
//            "left": windowWidth / 2 - popupWidth / 2 - 10
//        });
//        $("#popupContactClose").css({
//        "position": "absolute",    
//        "padding": "10px", "top": windowHeight / 2 - popupHeight / 2 + 35,
//        "left": windowWidth / 2 - popupWidth / 2,
//        "z-index":"10"
//        /*"text-align":"right"*/
//        });
 //   }
    //only need force for IE6
    $("#backgroundPopup").css({
        "height": windowHeight
    });
}
//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {
    //LOADING POPUP
    //Click the button event!
    $("#Features").click(function() {
        PopID = "#tbl" + this.id;
        $(PopID).css("display", "block");
        //centering with css
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    });
    $("#Benefit").click(function() {
        PopID = "#tbl" + this.id;
        //centering with css
        /*    $("#tbl" + this.id).css("display","block");    */
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    });
    $("#Products").click(function() {
        PopID = "#tbl" + this.id;
        //centering with css
        /*    $("#tbl" + this.id).css("display","block");    */
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    }); 
    $("#Platform").click(function() {
        PopID = "#tbl" + this.id;
        //centering with css
        /*    $("#tbl" + this.id).css("display","block");    */
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    });
    $("#News").click(function() {
        PopID = "#tbl" + this.id;
        //centering with css
        /*    $("#tbl" + this.id).css("display","block");    */
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    });
    $("#oGprice").click(function() {
        PopID = "#tbl" + this.id;
        //centering with css
        /*    $("#tbl" + this.id).css("display","block");    */
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    }); 
    $("#oGBus").click(function() {
        PopID = "#tbl" + this.id;
        //centering with css        
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    });
    
    $("#CaseStudy").click(function() {
        PopID = "#tbl" + this.id;
        //centering with css        
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    }); 
    $("#divSignin").click(function() {
        PopID = "#div" + this.id;
        //centering with css
        /*    $("#tbl" + this.id).css("display","block");    */
        centerPopup(PopID);
        //load popup
        loadPopup(PopID);
    });
    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function() {
    disablePopup(PopID);
    $("#popupContactClose").css("display", "none");
    });
    //Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup(PopID);
        $("#popupContactClose").css("display", "none");
    });
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup(PopID);
            $("#popupContactClose").css("display", "none");
        }
    });
});
