/***************************
 *@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 loadingStatus = 0;

//loading popup with jQuery magic!
function loadLoading(){
	//loads popup only if it is disabled
	if(loadingStatus==0){
		$j("#panel_background").css({
			"opacity": "0.7"
		});
		$j("#panel_background").fadeIn("slow");
		$j("#loading_image").fadeIn("slow");
		loadingStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disableLoading(){
	//disables popup only if it is enabled
	if(loadingStatus==1){
		$j("#panel_background").fadeOut("slow");
		$j("#loading_image").fadeOut("slow");
		loadingStatus = 0;
	}
}

//centering popup
function centerLoading(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $j("#loading_image").height();
	var popupWidth = $j("#loading_image").width();
	
	//Adjust for scrolling (keep centered even during scroll)
	var scroll_position = 0;
	if (window.innerHeight) //Firefox Support
		scroll_position = window.pageYOffset;
	else
		scroll_position = document.body.scrollTop;
		
	//centering
	$j("#loading_image").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/1.5)+scroll_position,
		"left": (windowWidth/2-popupWidth/2)-30
	});
	//only need force for IE6
	
	$j("#panel_background").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$j(document).ready(function(){
	
	//centering with css
	centerLoading();

	
	$j(".order-image, .order-link").click(function(){
		loadLoading();
	});
				
	//CLOSING POPUP
	//Press Escape event!
	$j(document).keypress(function(e){
		if(e.keyCode==27 && loadingStatus==1){
			disableLoading();
		}
	});

});

//Keep centered during scroll and resize of window
$j(window).scroll( centerLoading );
$j(window).resize( centerLoading );