// JavaScript Document
$(document).ready(
function()
{
	
	for (var divid in popupStatuses)
	{
		if ($(divid + 'Close').length != 0)
		{
			$(divid + 'Close').click(function() {disableAllMyBoxes(divid);});
		}

		if ($(divid+'Lightbox').length == 0)
		{
			var Lightbox  = document.createElement("div");
			Lightbox.style.display = 'none';
			Lightbox.id = divid.substr(1,divid.length-1)+'Lightbox';
			document.body.appendChild(Lightbox);
		}
		if ($(divid + 'Lightbox').length != 0)
		$(divid + 'Lightbox').click(function() {disableMyBox(divid);});
	}
	$(document).keypress(function(e){
		for (var divid in popupStatuses)
		{
			if(e.keyCode==27 && popupStatuses[divid]==1)
			{
				disableMyBox(divid);
			}
		}
		
	});
}
);
					
function showMyBox(divid)
{
	
	centerMyBox(divid);
		//load popup
	loadMyBox(divid);	
}

function centerMyBox(divid)
{
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(divid).height();
	var popupWidth = $(divid).width();
	
	var topHeight = 0;
	topHeight = windowHeight/2-popupHeight/2;
	
	
	$(divid).css({
		"position": "absolute",
		"top": topHeight,
		"left": windowWidth/2 - popupWidth/2,
		"z-index": "1001"
	});
	
	
	
	$(divid+'Lightbox').css({
		"height": windowHeight,
		"width": windowWidth,
		"z-index": "1000",
		"position":"fixed",
		"_position":"absolute", /* hack for internet explorer 6*/  
		"top":"0",
		"left":"0",
		"background-color" : "black",
		"border":"1px solid #cecece"
	});
	window.scroll(0,-100);
}


function loadMyBox(divid){
	//loads popup only if it is disabled
	if(popupStatuses[divid]==0){
		$(divid+'Lightbox').css({
			"opacity": "0.7"
			
		});
		
		$(divid+'Lightbox').fadeIn("fast");
		$(divid).fadeIn("fast");
		popupStatuses[divid] = 1;
	}
}


function disableMyBox(divid){
	//disables popup only if it is enabled
	if(popupStatuses[divid]==1)
	{
		$(divid+'Lightbox').fadeOut("slow");
		$(divid).fadeOut("slow");
		popupStatuses[divid]=0;
	}
}

function disableAllMyBoxes(){
	//disables popup only if it is enabled
	for (var divid in popupStatuses)
	{
		if(popupStatuses[divid]==1)
		{
			$(divid+'Lightbox').fadeOut("slow");
			$(divid).fadeOut("slow");
			popupStatuses[divid]=0;
		}
	}
}