/***************************/
//@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 popupStatus = new Array();


function loadPopup(background, galleryid, backgroundid){
	//hide all Popups
	disableAllPopups();
	
	//Show new Popup
	$(backgroundid).css({
		"opacity": "0.5"
	});
	if (background==true)
	{
		$(backgroundid).fadeIn("def");
	}
	$(galleryid).fadeIn("def");
	popupStatus[galleryid] = 1;
}

//disabling popup with jQuery magic!
function disablePopup(galleryid,backgroundid){
	$(backgroundid).fadeOut("def");
	$(galleryid).fadeOut("def");
	popupStatus[galleryid] = 0;
}

function disableAllPopups()
{
	for (var id in popupStatus) 
	{
		var backgroundid = "#background_"+id;
		var galleryid = "#gallery_"+id;
		
		$(backgroundid).hide();
		$(galleryid).hide();
		popupStatus[id] = 0;
	}
}

//centering popup
function centerPopup(galleryid,backgroundid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(galleryid).height();
	var popupWidth = $(galleryid).width();
	var top =  windowHeight/2-popupHeight/2;
	var left = windowWidth/2-popupWidth/2;
	if (top < 0)
		top = 0;
	if (left < 0)
		left = 0;
	//centering
	$(galleryid).css({
		"position": "fixed",
		"top": top,
		"left": left
	});
	
	//only need force for IE6
	
	$(backgroundid).css({
		"height": windowHeight
	});
	
}

function setPopupPosition(item,popup){
	var pos = item.offset();
	var width = item.width();
	pos.left -= 0;
	pos.top -= 14;
	popup.css({
		"position": "absolute",
		"top": pos.top + "px",
		"left": pos.left + "px"
	});
}


