/*
Eastern University
General JavaScript file
27 June 2007
Created by: Pat Collins <pat@walltowall.com>
*/

$(document).ready(function(){
	// $("#top_nav li").children("a").fadeTo(1, 0.35);
	// $("#top_home").children("a").fadeTo(1, 0.2);
	// $("#top_home").children("a").hover(function(){
	// 	$(this).fadeTo(1, 0.8);
	// },function(){
	// 	$(this).fadeTo(1, 1);
	// });
	
	// Handle the Quick Links.
	// $("#top_quicklinks div").fadeTo(1, 0.9, function(){
	// 	$(this).hide();
	// });
	$("#top_quicklinks").children("a").click(function(){
		this.blur();
		$("#top_quicklinks div").toggle();
	});
	
	// Add 'top' class to the first header tag in each of the left, content, and right columns.
	$("#left-content").children("h1, h2, h3, h4, h5, h6").filter(":first").add(
		$("#content").children("h1, h2, h3, h4, h5, h6").filter(":first").get()
	).add(
		$("#right-content").children("h1, h2, h3, h4, h5, h6").filter(":first").get()
	).addClass("top");
	
	// Append a self-clearing div after each feature
	$("div.feature").append("<div class='clear'></div>");
	
	// Change the opacity hover effect on all links that have images inside them,
	// except those with a 'nofade' class, in addition to all
	// links with a "fadelink" class.
	// $("a").filter(function(){
	// 	return this.className.indexOf("nofade") < 0;
	// }).children("img").parent().add(
	// 	$("a.fadelink")
	// ).hover(function(){
	// 	$(this).children("img").fadeTo(1, 0.7);
	// },function(){
	// 	$(this).children("img").fadeTo(1, 1);
	// });
	$("a.fadelink").hover(function(){
		$(this).children("img").fadeTo(1, 0.75);
	},function(){
		$(this).children("img").fadeTo(1, 1);
	});
	
	// Flyout navigation
	$("#menu").children("li").children("a").hover(function(){
		// link mouseover
		var id = $(this).parent().get(0).id.split("_link")[0];
		if($("#"+id+"_link").get(0).className.indexOf('current') < 0){
			$(this).parent().addClass("hover");
			$('#'+id).show();
		}
	},function(){
		// link mouseout
		var id = $(this).parent().get(0).id.split("_link")[0];
		if($("#"+id+"_link").get(0).className.indexOf('current') < 0){
			$(this).parent().removeClass("hover");
			$('#'+id).hide();
		}
	}).end().each(function(){
		var id = this.id.split("_link")[0];
		// taking the id of the links, finding the divs, and attaching behavior.
		if($("#"+id+"_link").get(0).className.indexOf('current') < 0){
			$('#'+id).hover(function(){
				$(this).show();
			},function(){
				$('#'+id+'_link').removeClass("hover");
				$(this).hide();
			}).mousemove(function(){
				$('#'+id+'_link').addClass("hover");
				$(this).show();
			});
		}
	});
	
	// Position the top of each flyout element to the top of where its corresponding link in the main menu is.
	$("#menu-container .submenu").each(function(){
		var pos = $('#'+this.id+'_link').position();
		$(this).css("top", pos.top+"px");
	});
	
	// Replace all horizontal rules with a custom HR div, maintaining the classes set on them.
	$("hr").wrap('<div class="hr"></div>').each(function(){
		var tmpCls = this.className.split(' ');
		var theDiv = $(this).parent();
		$(tmpCls).each(function(index){
			theDiv.addClass(tmpCls[index]);
		});
	}).remove();
	
	// Add the menu-bottom element before the main menu UL.
	// Provides the maroon bar at the bottom of the nav.
	// $("#menu").before('');
	
	
});