//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
$(document).ready(function() {
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".list-nav li").hover(function () {
			$(this).addClass("hover");
		},function () {
			$(this).removeClass("hover");
		});
	} else {
		// this is need for safari when nav covers flash
		$(".list-nav li ul").hover(function () {
			$(this).addClass("redraw");
		},function () {
			$(this).removeClass("redraw");
		});
	}

	// Place pipes | between links
	//$(".list-nav > li:not(:last-child)").after("<li class=\"pipe\">|</li>");

	// Add first and last classes to UL's
	$(".list-nav li:first-child, #sub_nav li:first-child").addClass("first");
	$(".list-nav li:last-child, #sub_nav li:last-child").addClass("last");
	$(".list-nav li a").each(function(){
		var bob = this.href;
		var billy = window.location.href;
		if(this.href == window.location.href)
			$(this).parent().addClass('selected');
			
	});

	//$("#sub_nav li a").each(function(){
	//	var bob = this.href;
	//	var billy = window.location.href;
	//	if(this.href == window.location.href)
	//		$(this).parent().addClass('selected');
	//		
	//});

	// Remove default search text on focus
	$("#search .text").focus( function(){
		if ( $(this).val() == $(this)[0].defaultValue ) {
			$(this).val("");
		}
	});
	// Replace default search text on blur if input is empty
	$("#search .text").blur( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this)[0].defaultValue );
		}
	});

	// divide dropdown nav into columns
	var maxRows = 10;
	var rowHeight = 25;
	var colWidth = 181;
	$("#headernav ul > li > ul").each(function() {
		var $kids = $(this).children();
		if ($kids.length > maxRows) {
			$(this).addClass("multi-col");
			var row = 1;
			var col = 1;
			$kids.each(function() {
				if (row > maxRows) {
					row = 1;
					col++;
				}
				$(this).addClass("row_" + row + " col_" + col);
				row++;
			});
			$(this).height(maxRows * rowHeight + 1);
			$(this).width(col * colWidth);
		}
	});
});
