var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

var masks=new Array();
//specify random images below. You can have as many as you wish
masks[0]="mask1.png";
masks[1]="mask2.png";
masks[2]="mask3.png";
masks[3]="mask4.png";

//put the images in randowm order
masks.sort(randOrd);

function randOrd(){
	return (Math.round(Math.random())-0.5); 
}
$().ready( function() {
	$("body.home #mainNav li").hover(function(){
		$(this).children("span").animate({width: '249px'},200);
	}, function(){
		$(this).children("span").animate({width: '45px'},200);
	});
	
	// Prepend list items in the main body and the news archive with ">>" as a bullet
	$("#newsArchive li, #main #extras li").prepend('<span class="bullet">&gt;&gt;</span>');
	
	// parse homepage feature title and create <h2>
	var featuretxt = $("#extras h3.feature a").text();
	featuretxt = featuretxt.split(": ");
	$("#extras h3.feature a").text(featuretxt[1]);
	$("#extras h3.feature").before("<h2>"+featuretxt[0]+"</h2>");
	
	
	// Prepend list items in the related links with a "#" as a bullet
	$("#relatedLinks li").prepend('<span class="bullet">#</span>');
	
	// Prepend list items in the section nav with a "_" as a bullet
	$("#sectionNav ul li").prepend('<span class="bullet">_</span>');
	
	// Make sure that the appended "_" changes color on hover
	$("#sectionNav a").hover(function(){
		$(this).parent("li").addClass("hover");
	},function(){
		$(this).parent("li").removeClass("hover");
	});
	
	// Set state-saving nav class
	$('#sectionNav a').each(function() {
		var navlink = $(this).attr("href");
		if (navlink.toLowerCase()==location.href.toLowerCase()) {
			$(this).parent("li").addClass("selected");
		}
	});
	
	$("div.slide").each( function(i) {
		$(this).prepend('<img src="/assets/images/'+masks[i]+'" class="mask" />');
	});
	
	$("#main ul.departments li").hover(function(){
		$(this).children("span.slider").animate({width: '249px'},200);
	}, function(){
		$(this).children("span.slider").animate({width: '30px'},200);
	});
	
	
	
	// use the search form's label to fade in/out on click
	if ($("#q").val()=="") {
		$("#search label").css("visibility","visible");
	}
	$("#q").focus( function() {
		$("#search label").fadeOut("fast");
	});
	$("#q").blur( function() {
		if ($("#q").val()=="") {
			$("#search label").fadeIn("fast");
		}
	});
	
	// Create interactive footer navigation
	$("#footerNav li ul").parent("li").children("a").click(function(){
		if ($(this).parent("li").attr("class")=="active") {
			$(this).parent("li").removeClass("active");
			$(this).parent("li").children("ul").hide();
		} else {
			$("#footerNav li ul").hide();
			$("#footerNav li").removeClass("active");
			$(this).parent("li").addClass("active");
			$(this).parent("li").children("ul").show();
			$(this).parent("li").children("ul").css("min-height",(this.offsetTop+16)+"px");
			//alert(this.offsetTop+"px");
			
		}
		return false;
	});
	
	// If IE6 just display the first slide, and don't try to animate the homepage slideshow
	if(IE6) {
		$('#slideshow .slide:first-child').css("display","block");
	} else {
		$('#slideshow').cycle({
			fx:     'fade', 
			speed:  'slow', 
		    timeout: 7000, 
		    pager:  '#slideNav',
			pause:  1,
			cleartype: 0
		});
	}
	
	// create elements and set styles needed for 3-D ".extruded" class
	$(".extruded").each(function(){
		var x = $(this).width(); 
		var xpl = $(this).css("padding-left");
		var xpr = $(this).css("padding-right");
		xpl = xpl.substr(0,xpl.length-2);
		xpr = xpr.substr(0,xpr.length-2);
		x = parseInt(x) + parseInt(xpl) + parseInt(xpr);
		var y = $(this).height();
		var ypt = $(this).css("padding-top");
		var ypb = $(this).css("padding-bottom");
		ypt = ypt.substr(0,ypt.length-2);
		ypb = ypb.substr(0,ypb.length-2);
		y = parseInt(y) + parseInt(ypt) + parseInt(ypb);
		$(this).append('<div class="shadow1"></div><div class="shadow2"></div>');
		$(this).children(".shadow1").css("top",y+"px");
		$(this).children(".shadow2").css("left",x+"px");
	});
	
	// Sort category archives into two columns
	$("body.mt-category-archive #main h1").after('<div id="extras"><div class="column"></div><div class="column" style="width:300px;padding-right:0;"></div></div>');
	var entryCount = $("body.mt-category-archive #main .entry-asset").length;
	col1count = Math.round(entryCount/2);
	$("body.mt-category-archive #main .entry-asset").each( function(i) {
		if(i<col1count){
			$(this).appendTo($("div.column:eq(0)"));
		} else {
			$(this).appendTo($("div.column:eq(1)"));
		}
	});
	
});
