//2009 MDBLAB

//0 means disabled; 1 means enabled;
var popupStatus = 0;

//Events
$(document).ready(function()
{
	//
	//$("#popupContactClose").click(function()
	//{
	//	disablePopup();
	//});

	//Click out event!
	//$("#backgroundPopup").click(function()
	//{
	//	disablePopup();
	//});

	//Press Escape event!
	$(document).keypress(function(e)
	{
		if(e.keyCode==27 && popupStatus==1)
		{
			disablePopup();
		}
	});
});

function show_popup(_name,_img,_info)
{
	//
	document.getElementById('_name').innerHTML = _name;
	document.getElementById('_img').src='/catalog/'+_img;
	document.getElementById('_info').innerHTML = _info;
	//
	centerPopup();
	//
	loadPopup();
}

//
function centerPopup()
{
	//
	//document.getElementsByTagName('body')[0]
	//var windowWidth = $("#slave").width();
	//var windowHeight = $("#main").height();
	var windowWidth = document.getElementsByTagName('div')[0].scrollWidth;//offsetWidth;
	//var windowHeight = document.getElementsByTagName('div')[0].offsetHeight;//offsetWidth;
	var windowHeight = document.body.scrollHeight;
	var popupWidth = $("#popupbox").width();
	var popupHeight = $("#popupbox").height();


	if (getInternetExplorerVersion()==7)
	{
		$(".cover").css({"left":"0px"});
		$("#popupbox").css({"left":"0px"});
	}
	$(".cover").css({"height":windowHeight,"width":windowWidth});

	//
	$("#popupbox").css({"margin-left":(windowWidth/2)-(popupWidth/2),
		"margin-top":(windowHeight/2)-(popupHeight/2)});
	//$("#popupbox").css({"margin-left":(windowWidth/2)-(popupWidth/2),
	//	"margin-top":"10px"});
}

function loadPopup()
{
	//
	if(popupStatus==0)
	{
		$(".content").css({"opacity":"0.1"});
		
		$(".cover").css({"display":"block"});

		$("#popupbox").fadeIn('fast');
		
		popupStatus = 1;
	}
}

function disablePopup()
{
	//
	if(popupStatus==1)
	{
		$("#popupbox").fadeOut(20);

		$(".cover").css({"display":"none"});

		$(".content").css({"opacity": "1"});
		
		popupStatus = 0;
	}
}

function getInternetExplorerVersion()
{
   var rv = -1;
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}
