/***************************/
//@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 = 0;

//loading popup with jQuery magic!
function loadPopup()
{
	//loads popup only if it is disabled
	if(popupStatus==0)
	{
		$("#backgroundPopup").css(
		{
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup()
{
	//disables popup only if it is enabled
	if(popupStatus==1)
	{
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
		$("#idshare").show();
		$("#idMediaButtons").show();
	}
}

//centering popup
function centerPopup()
{
	//request data for centering
	var windowHeight = document.documentElement.clientHeight;

	//only need force for IE6
	
	$("#backgroundPopup").css(
	{
		"height": windowHeight
	});
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function()
{
	//Click the button event!
	$("#loop").click(function()
	{
		//centering with css
		centerPopup();
		$("#popupContact").html("<div style='text-align:center;padding-top:200px;'><img src='"+$("#idProjectPath").text()+"/images/loading_image.gif'></div>");
		$("#idshare").hide();
		$("#idMediaButtons").hide();
		
		$.ajax(
		{
			// The link we are accessing.
			url: $("#idProjectPath").text()+"ajax/"+$("#idAjaxPage").text()+".php",
			data: "Action=PhotoGallery&ID="+$("#idID").text(),
			// The type of request.
			type: "post",
			
			// The type of data that is getting returned.
			dataType: "html",
			
			complete: function()
			{
				$("#RateArticleAjaxLoad").fadeOut(500);
			},
			
			success: function(msg)
			{
				$("#popupContact").html(msg);
			}
		});
		//load popup
		loadPopup();
	});
				
	//Click out event!
	$("#backgroundPopup").click(function()
	{
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e)
	{
		if(e.keyCode==27 && popupStatus==1)
		{
			disablePopup();
		}
	});
});