// For IE hover flicker bug
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

// Hello jQuery!
$(document).ready(function(){
// Add class to body to tell the stylesheet that JavaScript is turned on
	$("body").removeClass("jsOff").addClass("jsOn");
	inputClear(".clearInput");

// Move go ahead/share module
 $(".home #flashAlternate").empty();

// Move go ahead/share module
$("#content .mygoAhead").insertBefore("h1#pageHeading");

	 
// News & Events Tabs

    $("#newsEventsMod h2").click(function () {
		$("#newsEventsMod div").removeClass("active");
		$(this).parent("div").addClass("active");
	});
// News & Events L2 subnavigation
	$("#newsNav li:first").addClass("first");
	$("#newsNav li:gt(4)").addClass("last");

// Other Stories (Brand Experience)
	$("#otherStories li:first").addClass("first");

// Go Ahead tool tip
	$("#goAhead li a").hover(
      function () { $(this).parent("li").addClass("over").css("z-index", "999"); },
      function () { $(this).parent("li").removeClass("over").css("z-index", "1"); }
    );
//	Share Molloy
    $("#shareMolloy").hover(
      function () { $(this).addClass("over"); }, 
      function () { $(this).removeClass("over"); }
    );
    $("#shareMolloy h2").click(
		function() { $("#shareMolloy").toggleClass("open"); }
    );
	$("#shareMolloy .close").click(
		function() { $("#shareMolloy").removeClass("open"); }
    );
	// Share Post & Email Tabs
    $("#shareLinks h3").click(function () {
		$("#shareLinks div").removeClass("active");
		$(this).parent("div").addClass("active");
	});
    $("#shareLinks h3").hover(
      function () { $(this).addClass("over"); }, 
      function () { $(this).removeClass("over"); }
    );
	// Share Post & Email Tabs of NEW
    $("#shareLinksNew h3").click(function () {
		$("#shareLinksNew div").removeClass("active");
		$(this).parent("div").addClass("active");
	});
    $("#shareLinksNew h3").hover(
      function () { $(this).addClass("over"); }, 
      function () { $(this).removeClass("over"); }
    );
// Academic Expanding Navigation ------------------------------
//	First, set the height of each hidden section so IE can show/hide it properly.
//C. Target IE6 and below
if ($.browser.msie && $.browser.version <= 7 ) $(".expandingNav ul").each(function() {
		var myHeight = $(this).height()
		$(this).css({ height:myHeight+6 });
	});
//	Hide nested ul with js (so users with js turned off can see everything)
	$(".expandingNav ul").hide();
//	Show the DIVs marked active on load
	$(".expandingNav ul.open").show();
	$(".expandingNav ul ul").show();
//	Hover state for headlines
    $(".expandingNav h3").hover(
      function () { $(this).addClass("over"); }, 
      function () { $(this).removeClass("over"); }
    );
//  Actions
	$(".expandingNav h3").click(function() {
	//	If clicking on an active section, close it and remove active state
		if($(this).hasClass("active")) {
			$(this).next("ul").removeClass("open").slideUp(300);
			$(this).removeClass("active")
		}
	//	Otherwise, the click marks the section active and opens it
		else if($(this)) {
			$(this).addClass("active");
			$(this).next("ul").addClass("open").slideDown(300)
		}
	});
// Drawer Modules ------------------------------
//	First, set the height of each hidden section so IE can show/hide it properly.
	$(".drawers li div.drawerContent").each(function() {
		var myHeight = $(this).height()
		$(this).css({ height:myHeight+12 });
	});
//	Identify the first li (for styling)
	$(".drawers li:first").addClass("first");
//	Hide nested DIVs with js (so users with js turned off can see everything)
	$(".drawers div.drawerContent").hide();
//	Show the DIVs marked active on load
	$(".drawers .active div.drawerContent").show();
//	Hover state for headlines
    $(".drawers h2").hover(
      function () { $(this).addClass("over"); }, 
      function () { $(this).removeClass("over"); }
    );
//  Actions
	$(".drawers h2").click(function() {
	//	If clicking on an active section, close it and remove active state
		if($(this).parent().hasClass("active")) {
			$(this).parent("li").removeClass("active");
			$(this).siblings("div.drawerContent").slideUp("300")
		}
	//	Otherwise, the click marks the section active and opens it
		else if($(this)) {
			$(this).parent().addClass("active")
			$(".active div.drawerContent").slideDown("300")
		}
	});

// Drawers Left Modules ------------------------------
//	First, set the height of each hidden section so IE can show/hide it properly.
	$("#drawersleft div div.drawerContent").each(function() {
		var myHeight = $(this).height()
		$(this).css({ height:myHeight+12 });
	});
//	Identify the first li (for styling)
	$("#drawersleft div:first").addClass("first");
//	Hide nested DIVs with js (so users with js turned off can see everything)
	$("#drawersleft div.drawerContent").hide();
//	Show the DIVs marked active on load
	$("#drawersleft .active div.drawerContent").show();
//	Hover state for headlines
    $("#drawersleft h3").hover(
      function () { $(this).addClass("over"); }, 
      function () { $(this).removeClass("over"); }
    );
//  Actions
	$("#drawersleft h3").click(function() {
	//	If clicking on an active section, close it and remove active state
		if($(this).parent().hasClass("active")) {
			$(this).parent("div").removeClass("active");
			$(this).siblings("div.drawerContent").slideUp("300")
		}
	//	Otherwise, the click marks the section active and opens it
		else if($(this)) {
			$(this).parent().addClass("active")
			$(".active div.drawerContent").slideDown("300")
		}
	});
/*
 * Clear out the default text in a specified input when it gains focus
 * If focus is lost and field is empty replace with default text
 *
 * Takes an optional parameter which is a jQuery string selector "#search-form input", "form .focusInput", etc
 * By default it targets ALL text inputs on a page
 */
function inputClear(target) {
	var target = target || "input";
	
	$(target).each(function() {
		if($(this).attr("type") == "text") {
			var value = $(this).val();

			$(this).focus(function() {
				if($(this).val() == value) {
					$(this).val("");
				}
			});

			$(this).blur(function() {
				if($(this).val() == "") {
					$(this).val(value);
				}
			});
		}
	});
}

// zebra tables
	$("#content table").each(function(){
		$("tr:nth-child(odd)").addClass("odd");
	});
});
