$(document).ready(function() {

	justifyMenu();
	
	// bind menu highlighting
	var loc = window.location.toString().split("/");
	//alert(loc.length);
	//alert(loc);
	loc = loc[3];
	if(loc == '') {
	 	loc = '/'; //home
	}
	else {
		loc = "/" + loc + "/"; 
	};
	match = '#nav li a[href^="' + loc + '"]:eq(0)';
 	//alert(match); 
	$(match).addClass("selected").first;
	
	

});

/* distributes main menu evenly across header */
function justifyMenu() {
	var menuItems  = $("#nav > ul > li");
	var lastItem = menuItems.length - 1
	var menuWidth  = $("#nav > ul").width();
	var totalWidth = 0;

   //alert(menuItems.length);
   //alert(menuWidth);
       
   menuItems.each(function(index) {
       totalWidth += $(this).width();
   });
    
   var margin = (menuWidth - totalWidth) / lastItem;
   margin = parseInt(margin);

	menuItems.css("margin-right", margin + 'px');

 	//remove the right margin on last 2 menu items
 	//to handle zooming
 	//last item is floated right
 	$("#nav > ul > li:eq(" + (lastItem - 1) + ")").css("margin-right", '0px');
 	$("#nav > ul > li:eq(" + lastItem + ")").css("margin-right", '0px'); 
   
   //alert(margin);
   //alert($("#nav > ul > li:eq(" + lastItem + ")").width());

}

/* ie compatibility for suckerfish style menu */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


/* test */
function newFunc() {
	alert("in newFunc");
}


