//popup boolean
var popupStatus = 0;  
var url = '';
var popup = '';
$(document).ready(function() {
	$(".popupLink").live('click', function () {
		popup = $(this).attr('id');
		popupUrl = $(this).attr('href');
		return loadPopup();
	});
});

function loadPopup(){  
//loads popup only if it is disabled  
	if(popupStatus==0){
		if (popup == 'navlink') { 
			url = "register.php?pop";
		} else if (popup == 'login') {
			url = "login.php?pop";
		} else {
			url = popupUrl + "&pop";
		}
		$("body").prepend("<div class='popup' style='" +
		"position: absolute;" +  
		"width: 600px;" + 
		"height: 220px;" + 
		"background: rgb(40,40,40);" + 
		"background: rgba(40,40,40,.9);" + 
		"padding: 10px;" +
		"visibility: hidden;" + 
		"border-radius: 15px;" +
		"-moz-border-radius: 15px;" +
		"margin-top: 50px;" + 
		"z-index: 6;" + 
		"box-shadow: 2px 2px 5px #000;'><center><img src='aesthetics/ajaxloader.gif' style='margin-top: 100px;' /></center></div>");
		$("<div>").load(url, function () {
			$(".popup").html(this);
			$('.popup').prepend("<a href='#' class='popupLink' style='float: right; color: #56ea33; font-size: 18px;'>x</a>");
			$(".loginuser").select();
			
		});
		centerPopup();
		popupStatus = 1;  
	} else if (popupStatus == 1){
		disablePopup();
	}
	return false;	
}  
 
function disablePopup(){  
	//disables popup only if it is enabled  
	if(popupStatus==1){  
		$(".popup").fadeOut("slow", function() { $(".popup").remove(); });  
		popupStatus = 0;  
	}  
}  

    
function centerPopup(){  
	//centering popup  
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;  
    var windowHeight = document.documentElement.clientHeight;  
    var popupHeight = $(".popup").height();  
    var popupWidth = $(".popup").width();  
    //centering  
    $(".popup").css({  
    "position": "absolute",  
    "top": windowHeight/2-popupHeight/2,  
    "left": windowWidth/2-popupWidth/2,
	"visibility": "visible"
    });  
    //only need force for IE6  
      
}  
