$(document).ready(function(){
	$(".subnav").hide();

	// navigation rollovers and sub-menu popup
	$(".navitem").hover(function() {
		
		$(this).children("div.tab").addClass("tab-focus");
		
		if ($.browser.msie && $.browser.version == "6.0") {
			$(this).children(".tab").children(".tab-text").css("background-image","url(/images/tabs/tab_focus_bg.png)");
			$(this).children(".tab").children(".tab-lhs").css("background-image","url(/images/tabs/tab_focus_lhs.png)");
			$(this).children(".tab").children(".tab-rhs").css("background-image","url(/images/tabs/tab_focus_rhs.png)");
		}
		
		if ($.browser.msie && $.browser.version == "6.0") {
		} else {
			$(".subnav").hide(); // hide any open sub menus
			
			if ($("#sub-"+$(this).attr("id")).length) { // check if a sub menu exists
				var pos = $(this).position(); // get position of navigation item
				
				var offset = 49;
				var loffset = 3;
				if ($.browser.safari) { offset = 29; }
				if ($.browser.msie) { loffset = 2}
				
				$("#sub-"+$(this).attr("id")).css("top",(pos.top + offset)+"px").css("left",(pos.left+loffset)+"px"); // position sub menu
				$("#sub-"+$(this).attr("id")).show(); // show sub menu
			}
		}
    }, function() {   
    	
    	$(this).children("div.tab-focus").removeClass().addClass("tab");
    	
    	if ($.browser.msie && $.browser.version == "6.0") {
			$(this).children(".tab").children(".tab-text").css("background-image","url(/images/tabs/tab_off_bg.png)");
			$(this).children(".tab").children(".tab-lhs").css("background-image","url(/images/tabs/tab_off_lhs.png)");
			$(this).children(".tab").children(".tab-rhs").css("background-image","url(/images/tabs/tab_off_rhs.png)");
		}
		if ($.browser.msie && $.browser.version == "6.0") {
		} else {
    		$("#sub-"+$(this).attr("id")).hide(); // hide sub menu
    	}
    });
	
	$(".panel.links").hide();
    
	// ensure the sidebar and page are the same height
    var pheight = $("#page").height();
    var sheight = $("#sidebar").height();
	if (pheight > sheight) {
		$("#sidebar").css("height", pheight+"px");
	} else {
		$("#page").css("height", sheight+"px");
	}
	
	// ensure that the university logos are at the bottom (irrespective of the amount of content)
	var btn = $("#btm").position();
	$("#unilogos").css("top", (btn.top-75)+"px").css("position", "absolute");

	$("a.toggle").bind("click", function() {
		var id = $(this).attr("id");
		$(".panel").hide();
		$(".toggletabs li.on").removeClass("on");
		$("#"+id+"_panel").show();
		$(this).parent().addClass("on");
		return false;	
	});
	
	
});	
