$(document).ready(function() {
	// "EXPANDO" BOXES
	$(".expando h2").click(function() {
		if ($(this).parent(".expando").attr("class").indexOf("open") < 0) {
			$(".expando-content").stop();
			//close open box
			$(".expando.open .expando-content").animate({height:"0"}, {queue:false, duration:100, complete: function() {
				$(this).hide().css("height","auto");
				$(".expando.open").removeClass("open");
			}});
			//open box
			$(".expando-content", $(this).parent(".expando")).hide().css("height","").slideDown(100, function() {
				$(this).parent(".expando").addClass("open");
			});
		}
	});
	
	//NAVIGATION
	$("#nav .level1>li").hover(function() {
		//$("div.level2").stop();
		$("div.level2").slideUp(1).removeClass("open");
		$("div.level2", this).addClass("open").slideDown(150);
	}, function() {
		$("div.level2", this).hide().removeClass("open");
	});
	
	//TABS
	$("ul.tabs li a").click(function() {
		if ($(this).parent("li").attr("class").indexOf("active") >= 0) {
			return false;
		} else {
			return true;
		}
	});
	 
	//LEVEL 4 NAV
	$(".nav-level4 a").click(function() {
		if ($(this).parent("li").attr("class").indexOf("active") < 0) {
			$("#" + $(".nav-level4 li.active a").attr("rel")).removeClass("active");
			$(".nav-level4 li.active").removeClass("active");
			$(this).parent("li").addClass("active");
			$("#" + $(this).attr("rel")).addClass("active");
		}
		return false;
	});
	$(".nav-next a").click(function() {
		//get index of active item
			var activeIndex = $(".nav-level4 li").index($(".nav-level4 li.active"));
		if ($(".nav-level4 li").length - activeIndex <= 1) activeIndex = -1;
		$("a", $(".nav-level4 li")[activeIndex + 1]).click();
		return false;
	});
	
	//Search
	$("input[name='search']").focus(function() {
		if ($(this).attr("value")=="Search for...") {
			$(this).attr("value","");
		}
	}).blur(function() {
		if (jQuery.trim($(this).attr("value"))=="") {
			$(this).attr("value","Search for...");
		}
	});
	
});
