var mainHash = "";
var tempUrl = location.href.split("#");
var targetDiv = "";
var menuOpened = false;

function newHash(value)
{
	window.hash(value);
	return false;
}

function updateFlash(flashHash)
{
	// alert (flashHash);
	var flash = window.document.bluecastle;
	flash.SetVariable("hash", flashHash);
}

function openDiv(source)
{
	var temp = source.split(",");
	var positionY = temp[1];
	var source = temp[0];

	if (positionY)
	{
		document.getElementById("hoverDiv").style.top = positionY + "px";	
		// document.getElementById("hoverDiv").style.height = "630px";
	}
	else
	{
		document.getElementById("hoverDiv").style.top = "260px";
	}

	if (source != "false")
	{
		document.getElementById("hoverDiv").style.display = "block";
		document.getElementById("hoverDivContent").style.height = document.getElementById("hoverDiv").offsetHeight + "px";

		if (document.getElementById("hoverDivContent"))
		{
			ajax(source, "hoverDivContent");
		}
	}
}

function closeDiv()
{
	if (document.getElementById("hoverDivContent"))
	{
		document.getElementById("hoverDivContent").innerHTML = "";
	}

	if (document.getElementById("hoverDiv"))
	{
		document.getElementById("hoverDiv").style.display = "none";
	}
}

function ajax(page, resultDiv, opened)
{
	if (page != "false")
	{
		targetDiv = resultDiv;
		
		xmlHttpCustom = GetXmlHttpObjectCustom();

		if (xmlHttpCustom == null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}

		if (page.indexOf("?") > -1)
		{
			url = page + "&menuOpened=" + opened;
		}
		else
		{
			url = page + "?menuOpened=" + opened;
		}

		xmlHttpCustom.onreadystatechange = stateChanged;
		xmlHttpCustom.open("GET",url,true);
		xmlHttpCustom.send(null);

		return false;
	}
}

function stateChanged() 
{
	if (xmlHttpCustom.readyState == 4 || xmlHttpCustom.readyState == "complete")
	{
		document.getElementById(targetDiv).innerHTML = xmlHttpCustom.responseText;
		
		jQuery('iframe').load(function()
			{
				var height = this.contentWindow.document.body.offsetHeight + 60 + 'px';
				if (this.contentWindow.document.body.offsetHeight < 500) {
					height = "500px";
				}
				this.style.height =	height;
				if (document.getElementById('inner_container') != null) {
					document.getElementById('inner_container').style.height = height;
				}
			}
		);

	}
}

function GetXmlHttpObjectCustom()
{
	var xmlHttp = null;

	try
	{
		xmlHttp = new XMLHttpRequest();
	}
		catch (e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}

function swapImage(imageId)
{
	if (document.getElementById(imageId))
	{
		if (document.getElementById(imageId).src.indexOf("/images/basic/bullet_media.gif") > -1)
		{
			document.getElementById(imageId).src = "/images/basic/bullet_media_opened.gif";
			document.getElementById("subMenu").style.display = "block";
			menuOpened = true;
		}
		else
		{
			document.getElementById(imageId).src = "/images/basic/bullet_media.gif";
			document.getElementById("subMenu").style.display = "none";
			menuOpened = false;
		}

		document.getElementById(imageId).blur();

		return false;
	}
}

function sendEmail(itemId)
{
	window.location = "mailto:\?subject\=Blue Castle Games&body=Blue Castle Games: " + window.location + "|itemId," + itemId;

	return false;
}

function printableVersion(releaseId)
{
	window.open("/php/mediacentre/printrelease.php?releaseId="+releaseId+"&print=true", "printableVersion", "width=900, height=580, menubar=no, toolbars=no, resizable=no");

	return false;
}