/***************************/
//@Original Author: Adrian "yEnS" Mato Gondelle
//@updater: PHXX, Inc.
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(name){
	//loads popup only if it is disabled
	if(popupStatus==0){
        var bg_name = "#" + name + "-background";
        var fg_name = "#" + name;
		$j(bg_name).css({
			"opacity": "0.7"
		});
		$j(bg_name).fadeIn("slow");
		$j(fg_name).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(name){
	//disables popup only if it is enabled
    var bg_name = "#" + name + "-background";
    var fg_name = "#" + name;
	if(popupStatus==1){
		$j(bg_name).fadeOut("slow");
		$j(fg_name).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(name){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
    name = "#" + name;
	var popupHeight = $j(name).height();
	var popupWidth = $j(name).width();
	//centering
	$j(name).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$j(name).css({
	    "height": popupHeight
	});
	
}
function shutout() {
		//disable button on submit and darken screen

	$j('.storeContinue').css({"display":"none"});
	$j('#login-popup-background').css({
			"opacity": "0.7"
		});
	$j('#login-popup-background').fadeIn("slow");
    centerPopup("store-popup");
    loadPopup("store-popup");
	$j('#subber').submit();
	}

//CONTROLLING EVENTS IN jQuery
$j(document).ready(function(){
    $j(".login-popup").click(function(){
		//centering with css
		centerPopup("login-popup");
		//load popup
		loadPopup("login-popup");
    });
    //login popup
	$j("#login-button").click(function(){
		//centering with css
		centerPopup("login-popup");
		//load popup
		loadPopup("login-popup");
	});
	$j("#login-popup-close").click(function(){
		disablePopup("login-popup");
	});
	//Click out event!
	$j("#login-popup-background").click(function(){
		disablePopup("login-popup");
	});

    //register popup
	$j(".register-popup").click(function(){
		//centering with css
		centerPopup("register-popup");
		//load popup
		loadPopup("register-popup");
	});
    //register popup
	$j("#register-button").click(function(){
		//centering with css
		centerPopup("register-popup");
		//load popup
		loadPopup("register-popup");
	});
	$j("#register-popup-close").click(function(){
		disablePopup("register-popup");
	});
	//Click out event!
	$j("#register-popup-background").click(function(){
		disablePopup("register-popup");
	});
	
	// support popup
	$j("#support-button").click(function(){
		//centering with css
		centerPopup("support-popup");
		//load popup
		loadPopup("support-popup");
		setTimeout( "window.location.href = 'https://support.reachgaming.com'", 5*1000 );
	});

});
