var dropdownTimer, slideshowTimer;
function showDropdown(dropdown)
{
	dropdown.slideDown(300);
}

function slideshow()
{
	if ($(".slideshow").length > 0)
	{
		var current = $(".slideshow li:visible");
		if (current.length == 0) current = $(".slideshow li:first");
		var next = current.next();
		if (next.length == 0) next = $(".slideshow li:first");
		
		current.fadeOut(500);
		next.fadeIn(500);
		
		var i = $(".slideshow li").index(next);
		
		slideshowTimer = setTimeout("slideshow()", 5000);
		$(".slideshow .slide-nav a.current").removeClass("current");
		$(".slideshow .slide-nav a:eq("+i+")").addClass("current");
	}
}

$(document).ready(function()
{
	$(".navigation ul.sub-menu").unwrap();
	$(".navigation ul ul").each(function()
	{
		var thisUL = $(this);
		if (thisUL.find("li").length == 0)
			thisUL.remove();
	});
	
	$(".navigation ul li:not(li li)").each(function()
	{
		if ($(this).find("li.current_page_item").length > 0)
			$(this).addClass("selected");
	});
	
	$(".navigation li:not(li li)").hover(
		function()
		{
			var dropdown = $(this).find("ul:first");
			dropdownTimer = setTimeout(function(){ showDropdown(dropdown) }, 200);
		},
		function()
		{
			clearTimeout(dropdownTimer);
			$(this).find("ul:first").slideUp(300);
		}
	);
	
	$(".slideshow li:first").show();
	$(".slideshow .slide-nav a:first").addClass("current");
	
	slideshowTimer = setTimeout("slideshow()", 5000);
	
	$(".slideshow .slide-nav a").click(function()
	{
		var i = $(".slideshow .slide-nav a").index($(this))
		$(".slideshow .slide-nav a.current").removeClass("current");
		$(this).addClass("current");
		
		var current = $(".slideshow li:visible");
		if (current.length == 0) current = $(".slideshow li:first");
		var next = $(".slideshow li:eq("+i+")");
		
		current.fadeOut(500);
		next.fadeIn(500);
		
		clearTimeout(slideshowTimer);
		slideshowTimer = setTimeout("slideshow()", 5000);
		
		return false;
	});
	
	if ($(window).width() < 1120)
	{
		$(".badge").css("right", -(1120 - $(window).width()) + "px");
	}
});

$(window).resize(function()
{
	if ($(window).width() < 1120)
	{
		$(".badge").css("right", -(1120 - $(window).width()) + "px");
	}
});
