$(function(){

	var canChange = true;
	var actIndex = 0;

	/* top-dropdowns */
	$("li.toplevel").hover(
		function(){
			$("ul.submenu", this).show();
		},
		function(){
			$("ul.submenu", this).hide();
		}
	);

	$(".previous-titles li").hover(
		function() { 
			canChange = false; 
			actIndex  = $(".previous-titles li").index(this);
			$("#previous-images li:not(:eq("+actIndex+"))").fadeOut("fast");
			$("#previous-images li:eq("+actIndex+")").fadeIn("fast");
			$(this).find("a").addClass("on").parent().siblings().find("a.on").removeClass("on");
		},
		function() { canChange = true; }
	);
	
	$("#previous-images li").hover(
		function(){ canChange = false },
		function(){ canChange = true }
	).click(
		function(){
			$(this).find(".description a:first").trigger("click");
		}
	);
	
	setInterval(function(){
		if (canChange) {
			
			var active = $("#previous-images li:visible");
			var next   = $(active).next("li:first");
			
			$(active).fadeOut("slow");
			if($(next).length) {
				$(next).fadeIn("slow");
				actIndex = actIndex + 1;
			} else {
				$(active).siblings("li:first").fadeIn("slow");
				actIndex = 0;
			}
			
			$(".previous-titles a").removeClass("on").eq(actIndex).addClass("on");
		}
	}, 5000);
	
	$("#searchform input[name='s']")
		.focus(function(){
			if ($(this).val() == "search our site")
				$(this).val("");
		})
		.blur(function(){
			if ($(this).val() == "")
				$(this).val("search our site");
		});
		
	$(".submitform").click(function(e){
		e.preventDefault();
		$(this).closest("form").submit();
	});
	
	// Increase Height of Review Thumbnail Container, and Center Thumbnail
	//$(".module-box:eq(2) .omega").css({"height":"100%"}).find("p").center(true);
	
});