function accordion_ready()
{
	var imgs = $("img.nav_accordion"); 
	var sum = 0; 
	imgs.each(function(i)
	{
		sum += this.complete ? 1 : 0;
	});
	
	if (sum<imgs.length)
		window.setTimeout(accordion_ready, 100);
	else
	{
		var h = 10;
		var y = 0;
		var last_height = 0;
		
		imgs.each(function(i)
		{
			$(this).parent().css("top", y + "px");
			$(this).parent().css("z-index", 100 - i);
			$(this).siblings("a").data("startY", y);
			var img_height = $(this).height();
			if (img_height)
				last_height = img_height;
			else img_height = last_height;
			y += $(this).parent().height() - img_height;
			h += $(this).parent().height() - (i>0 ? img_height : 0)
		});
		$("img.nav_accordion").click(function()
		{
			window.location.href = $(this).siblings("a").get(0).href; 
		});
		$("#main_nav_1").height(h);
				
		$("img.nav_accordion ~ a").mouseover(function()
		{
			var li = $(this).parent();
			var img = $(this).siblings("img").height();
			
			$("li:lt(" + $("li",li.parent()).index(li) + ")", li.parent()).each(function(i)
			{
				var y = $("a", this).data("startY") - img;
				$(this).stop().animate({ top: y + "px"}, "fast", "swing", function(){ $(this).css("top", y + "px")});
			});
			
			$("li:gt(" + $("li",li.parent()).index(li) + ")", li.parent()).each(function(i)
			{
				var y = $("a", this).data("startY");
				$(this).stop().animate({ top: y + "px"}, "fast", "swing", function(){ $(this).css("top", y + "px")});
			});
			var startY = $(this).data("startY");
			$(this).parent().stop().animate({ top: startY + "px"}, "fast", "swing", function(){ $(this).css("top", startY + "px")});
		});
	}
}


$(document).ready(function()
{
	if ($("img.nav_accordion").length > 0)
		window.setTimeout(accordion_ready, 100);
});
