﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//customizations to code by CSI Rachel 1.3.2011 see comments in the code
/***************************/

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.8" //make opacity higher
        });
        $("#backgroundPopup").fadeIn("fast"); //changed speed of fade
        $("#popupLogin").fadeIn("fast");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("fast"); //changed speed of fade
        $("#popupLogin").fadeOut("fast");
        popupStatus = 0;
    }
}

//centering popup -- remove code and control by CSS only
//function centerPopup() {
//request data for centering
//   var windowWidth = document.documentElement.clientWidth;
//   var windowHeight = document.documentElement.clientHeight;
//   var popupHeight = $("#popupLogin").height();
//   var popupWidth = $("#popupLogin").width();
//centering
//   $("#popupLogin").css({
//       "position": "absolute",
//       "top": windowHeight / 2 - popupHeight / 2,
//       "left": windowWidth / 2 - popupWidth / 2
//   });

//only need force for IE6
//    $("#backgroundPopup").css({
//    "height": windowHeight
//  });

//}

//controlling events in jQuery
$(document).ready(function () {

    //load popup
    $(".loginbtn").click(function () {
        //centerPopup(); removed because it is being controlled by CSS now
        loadPopup();
    });

    //close popup using x button
    $("#popupClose").click(function () {
        disablePopup();
    });

    //click on page background to close popup
    $("#backgroundPopup").click(function () {
        disablePopup();
    });

    //press escape to close
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
});
