function showGameBlock(game_id)
{
	if($('game-block-' + game_id))
	{
		$('game-block-' + game_id).style.display = 'block';
		$('hidden-game-block-' + game_id).style.display = 'none';
	}
}

function hideGameBlock(game_id)
{
	if($('game-block-' + game_id))
	{
		$('game-block-' + game_id).style.display = 'none';
		$('hidden-game-block-' + game_id).style.display = 'block';
	}
}

function showContent(link, position, element, article_id)
{
	var timestamp = new Date().getTime();
	$(element).innerHTML = "<img class='spinner' src='img/ArticlePage/indicator.gif'/>";
	$(element).style.display = "block";

	var blocks = $("related-games").getElementsByTagName("div");
	for(i = 0; i < blocks.length; i++)
	{

		if(blocks[i].id != "last")
		{
			blocks[i].className = "";
		}
	}

	var blocks = $("related-game-blocks").getElementsByTagName("div");
	for(i = 0; i < blocks.length; i++)
	{
		if(blocks[i].className == "related-block")
		{
			if(!(blocks[i].id == element))
			{
				blocks[i].style.display = "none";
			}
		}
	}

	var current_id = link.id.replace(/tab-/, "");
	var prev_id = current_id-0;
	var next_id = current_id-0;
	next_id = next_id+1;
	prev_id = prev_id-1;

	if($("tab-"+next_id+'-container'))
	{
		$("tab-"+next_id+'-container').className = "on";
		if($("last"))
		{
			$("last").style.display = "block";
			$("last").className = "last";
		}
	}
	else
	{
		//assume we're at the end
		if($("last"))
		{
			$("last").style.display = "block";
			$("last").className = "on";
		}
	}

	if($("tab-"+prev_id+'-container'))
	{
		$("tab-"+prev_id+'-container').className = "flipped";
	}

	$(link.id + "-container").className = "dark";

	params = "&article_id=" + article_id + "&position=" + position + "&action=related-game";
	var updater = new Ajax.Updater(
		element,
		"ajax.php?time=" + timestamp,
		{
			method: 'get',
			parameters: params
		}
	);
}

function hidePreview()
{
	$("blanket").style.display = "none";
	$("viewer").style.display = "none";
}

function showPreview(image, image_caption, image_link, image_width, image_height)
{
	$("caption").style.width = image_width + "px";
	$("caption").innerHTML = image_caption;

	$("illustration").src = image;
	$("illustration").width = image_width;
	$("illustration").height = image_height;
	$("gallery-link").href = image_link;

	viewport = getViewport();

	var side_margins	= Math.round((viewport[1] - image_width) / 2);
	var top_margins		= Math.round((viewport[2] - image_height) / 2);

	if(viewport[0] == "non-ie")
	{
		side_margins-= 8;
	}

	$("viewer").style.marginTop	= Math.round(top_margins-26) + "px";
	$("closer").style.right		= side_margins + "px";
	$("gallery-link").style.left	= side_margins + "px";

	$("blanket").style.display = "block";
	$("viewer").style.display = "block";
}

function getViewport()
{
	var myBrowser = "", myWidth = 0, myHeight = 0;

	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myBrowser = "non-ie";
		myWidth		= window.innerWidth;
		myHeight	= window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		myBrowser = "ie";
		myWidth 	= document.documentElement.clientWidth;
		myHeight	= document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myBrowser = "ie";
		myWidth		= document.body.clientWidth;
		myHeight	= document.body.clientHeight;
	}

	return new Array(myBrowser, myWidth, myHeight);
}

function spawnOverlay(pid, profile, width, height)
{
	// set up an overlay
	var overlay = document.createElement('div');
	overlay.setAttribute('id','video-overlay');

	overlay.innerHTML = "<div id='overlay-content'></div><a id='overlay-close'></a>";

	var notMoz = document.all?true:false;
	if(notMoz)
	{
		overlay.attachEvent("onclick", removeOverlay);
	}
	else
	{
		overlay.addEventListener("click", removeOverlay, false);
	}

	var browserDimensions = getBrowserDimensions();

	$("browserMaster").appendChild(overlay);

	$("overlay-content").style.top = parseInt((browserDimensions[1] - height) / 2) + "px";
	$("overlay-content").style.left = parseInt((browserDimensions[0] - width) / 2)-10 + "px";
	$("overlay-content").style.width = width + "px";
	$("overlay-content").style.height = height + "px";


	$("overlay-close").innerHTML = "Close player";
	$("overlay-close").href = "javascript:removeOverlay();";

	$("overlay-close").style.top = parseInt((browserDimensions[1] - height) / 2)-17 + "px";

	$("overlay-close").style.left = parseInt((browserDimensions[0] - width) / 2) + parseInt(width) - 69 + "px";


	// hide the ads
	switchAds("none");

	// create a flash object
	var so = new SWFObject(
		"egtv.swf?" +
		"playlist_id="+pid +
		"&profile_id="+profile,
		"egtv",
		width,
		height,
		"9.0.45",
		"#000000");

	so.useExpressInstall( "expressinstall.swf" );
	so.addParam( "quality", "high" );
	so.addParam( "allowScriptAccess", "always" );
	so.addParam( "loop", "false" );
	so.addParam( "allowFullScreen", "true" );

	so.addVariable( "playlist_id", pid );

	so.addVariable( "profile_id", profile );
	so.addVariable( "chapter", "0" );

	// write the video to the overlay
	so.write("overlay-content");

	return false;
}

function removeOverlay()
{
	while($("video-overlay"))
	{
		$("browserMaster").removeChild($("video-overlay"));
	}

	// show the ads
	switchAds("block");
}

function switchAds(status)
{
	var iframes = document.getElementsByTagName("iframe");
	for(i = 0; i < iframes.length; i++)
	{
		iframes[i].style.display = status;
	}
}
function getBrowserDimensions()
{
	var myWidth	= 0
	var myHeight	= 0;

	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return Array(myWidth, myHeight);
}