function articleVote(aid, vote)
{
	var url = "community.php?action=article-vote&aid="+aid+"&vote="+vote;
	var requester = new Ajax.Request(
		url,
		{
			method: 'get',
			onSuccess: function(transport)
			{
				updateScore(aid);			
			}
		}
	);
}

function undoArticleVote(aid)
{
	var url = "community.php?action=undo-article-vote&aid="+aid;
	var requester = new Ajax.Request(
		url,
		{
			method: 'get',
			onSuccess: function(transport)
			{
				updateScore(aid);			
			}
		}
	);
}

function updateScore(aid)
{
	var updater = new Ajax.Updater(
		"article-score",
		"community.php?action=get-article-votes&aid=" + aid,
		{
			method: 'get',
			onSuccess: function(transport)
			{
				if($("score-options"))
				{
					Effect.Fade("score-options", { duration: 1.0 });
				}
			}
		}
	);
}

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';
	}
}

document.getElementsByClassName  = function(className, parentElement)  {
  if (Prototype.BrowserFeatures.XPath) {
    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
    return document._getElementsByXPath(q, parentElement);
  } else {
    var children = ($(parentElement) || document.body).getElementsByTagName('*');
    var elements = [], child;
    for (var i = 0, length = children.length; i < length; i++) {
      child = children[i];
      if (Element.hasClassName(child, className))
        elements.push(Element.extend(child));
    }
    return elements;
  }
};

function showContent(position)
{
	var blocks = document.getElementsByClassName("related-block");
	for(i = 0; i < blocks.length; i++)
	{
		blocks[i].style.display = "none";
	}	
	$("related-block-" + position).style.display = "block";

	var blocks = document.getElementsByClassName("related-game");
	for(i = 0; i < blocks.length; i++)
	{
		blocks[i].className = "related-game";
	}	
	$("tab-" + position + "-container").className = "related-game on";


	/*
	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 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);
}