var timeout = null;

window.addEvent("load", function ()
{
	$$("a").each(function (obj)
	{
		if (obj.href && obj.rel == "external")
		{
			obj.target = "_blank";
		}
	});
	
	$$("div.box-content").addEvent("mouseover", function ()
	{
		clearTimeout(timeout);
		
		closeOther(this);
		toggleLayer(this, true);
	});
	
	$$("div.box-content").addEvent("mouseout", function ()
	{
		timeout = setTimeout("toggleLayer($(\"" + this.id + "\"), false);", 50);
	});
});

function toggleLayer(layer, show)
{
	if (!show || !layer.hasClass("opened"))
	{
		if (show)
		{
			layer.addClass("opened");
		}
		
		var height = layer.getSize().size.y;
		var start = (show) ? 70 : height;
		var finish = (show) ? height : 70;
		
		var animation = new Fx.Style(layer.getParent(), "height",
		{
			"duration": 250,
			"transition": Fx.Transitions.Cubic.easeInOut
		})
		.addEvent("onComplete", function ()
		{
			if (!show)
			{
				layer.removeClass("opened");
			}
		})
		.start(start, finish);
	}
}

function closeOther(layer)
{
	$$("div.box-content").each(function (obj)
	{
		if (obj.id != layer.id && obj.hasClass("opened"))
		{
			toggleLayer(obj, false);
		}
	});
}
