/***************************/
//@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;

// Advance Option           --->        1

var popScreen = 0;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(ind) {
    //loads popup only if it is disabled

    

    if (popupStatus == 0) {
        popScreen = ind;
        //alert(ind);
        ResizePopup();
        
        $("#backgroundPopup").css({
            "opacity": "0.8"
        });

        $("#backgroundPopup").fadeIn("slow");

        if (ind == 1)
            $("#OptionpopupContact").fadeIn("slow");
        else if (ind == 2)
            $("#LnkGenpopupContact").fadeIn("slow");
        else if (ind == 3)
            $("#BugReportpopupContact").fadeIn("slow");
        else if (ind == 4)
            $("#LoginpopupContact").fadeIn("slow");
        else if (ind == 5)
            $("#WelcomepopupContact").fadeIn("slow");
        else if (ind == 6)
            $("#LogoutpopupContact").fadeIn("slow");

        popupStatus = 1;
    }

}

function ResizePopup() {

    var windowWidth = $(window).width(); // document.documentElement.clientWidth;
    var windowHeight = $(window).height(); // document.documentElement.clientHeight;

    if (popScreen == 1) {
        var popupHeight = $("#OptionpopupContact").height();
        var popupWidth = $("#OptionpopupContact").width();

        $("#OptionpopupContact").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    else if (popScreen == 2) {
        var popupHeight = $("#LnkGenpopupContact").height();
        var popupWidth = $("#LnkGenpopupContact").width();

        $("#LnkGenpopupContact").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    else if (popScreen == 3) {
        var popupHeight = $("#BugReportpopupContact").height();
        var popupWidth = $("#BugReportpopupContact").width();

        $("#BugReportpopupContact").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    else if (popScreen == 4) {
        var popupHeight = $("#LoginpopupContact").height();
        var popupWidth = $("#LoginpopupContact").width();

        $("#LoginpopupContact").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    else if (popScreen == 5) {
        var popupHeight = $("#WelcomepopupContact").height();
        var popupWidth = $("#WelcomepopupContact").width();

        $("#WelcomepopupContact").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    else if (popScreen == 6) {
        var popupHeight = $("#LogoutpopupContact").height();
        var popupWidth = $("#LogoutpopupContact").width();

        $("#LogoutpopupContact").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

//disabling popup with jQuery magic!
function disablePopup(ind) {
    //disables popup only if it is enabled

    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        //alert(ind + "    jjjjjjjj       " + popScreen);
        if (ind == 1)
            $("#OptionpopupContact").fadeOut("slow");
        else if (ind == 2)
            $("#LnkGenpopupContact").fadeOut("slow");
        else if (ind == 3)
            $("#BugReportpopupContact").fadeOut("slow");
        else if (ind == 4)
            $("#LoginpopupContact").fadeOut("slow");
        else if (ind == 5)
            $("#WelcomepopupContact").fadeOut("slow");
        else if (ind == 6)
            $("#LogoutpopupContact").fadeOut("slow");

        popupStatus = 0;
    }
}

//centering popup
function centerPopup(ind) {
    //request data for centering

    //centering


}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

    //LOADING POPUP
    //Click the button event!
    $("#button5").click(function() {
        //centering with css
        //centerPopup(1);
        //load popup
        loadPopup(1);
    });

    $("#button2").click(function() {
        //centering with css
        centerPopup(2);
        //load popup
        loadPopup(2);
    });

    //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(popScreen);
        }
    });

});
