var timeout = 500;
var closetimer = 0;

function init()
{
	$("#nav li a.share, #dropdown").bind('mouseover', open);
	$("#nav li a.share, #dropdown ").bind('mouseout', closeTimer);
	
	$("#related-content ul li a").each(function() {
		if( $(this).parent().next().length > 0 )
		{
			$(this).parent().next().hide();
			$(this).bind("click", function(){
				$(this).toggleClass("expanded");
				$(this).parent().next().toggle();
				return false;
			});
		}
	});
}

function open()
{
	cancelTimer();
	close();
	$("#dropdown").show();
}

function close()
{
	$("#dropdown").hide();
}

function closeTimer()
{
	closetimer = window.setTimeout(close, timeout);
}

function cancelTimer()
{
	if( closetimer )
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function RecentItem(parent)
{	
	this.html = $("<li></li>");
	
	this.init = function(text, color) {
		this.html.html("<a href=\"#\">"+text+"</a>");
		this.html.css("background-color",color);
		$(parent).append(this.html);
	}
}

$(document).ready( function() {
	init();
});