/* 
jQuery defines a $ function, but so do we.
Ours takes precendence however due to its prevelance in the system.
I'd rather not change their code so I am going to make a pointer to their definition of $ before our scripts redefine it.
*/
window.sh$ = $;


// For IE hover flicker bug
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}


// Hello jQuery!

sh$(document).ready(function(){
// homepage Featured Community on/off

	sh$(".layertoggle").mouseover(function() {
		sh$(this).addClass("over")
		sh$("#community dd p").addClass("over")
	});
	sh$(".layertoggle").mouseout(function() {
		sh$(this).removeClass("over")
		sh$("#community dd p").removeClass("over")
	});
	sh$(".layertoggle").click(function() {
		sh$("div#community_over").toggle()
		sh$("#giving p").toggleClass("hide")
	});


// News & Events element group hovers
	sh$("#news_events ul a").mouseover(function() {
		sh$(this).parent(this).parent("#news_events ul").addClass("over");
	});
	sh$("#news_events ul a").mouseout(function() {
		sh$(this).parent(this).parent("#news_events ul").removeClass("over");
	});


	sh$("#news_events dl a").mouseover(function() {
		sh$(this).parent(this).parent("#news_events dl").addClass("over");
	});
	sh$("#news_events dl a").mouseout(function() {
		sh$(this).parent(this).parent("#news_events dl").removeClass("over");
	});

	sh$("#inline_news dl a").mouseover(function() {
		sh$(this).parent(this).parent("#inline_news dl").addClass("over");
	});
	sh$("#inline_news dl a").mouseout(function() {
		sh$(this).parent(this).parent("#inline_news dl").removeClass("over");
	});

// News & Events Hovers
	sh$("#news_events li[a]").mouseover(function() {
		sh$(this).addClass("over");
	});
	sh$("#news_events li[a]").mouseout(function() {
		sh$(this).removeClass("over");
	});


// See Also Document Link Icons
    sh$(".see_also a[@hrefsh$='.pdf']").append("<span class=\"file type_pdf\">&nbsp;</span>");
    sh$(".see_also a[@hrefsh$='.doc']").append("<span class=\"file type_doc\">&nbsp;</span>");

// Add arrows to the See Also links - this code must be below
// Link Icon javascript so the arrows display after the icons
	sh$(".see_also a").append("<span>&nbsp;&gt;</span>");

// Contact link arrow
	sh$(".contact_us a").append("<span>&nbsp;&gt;</span>");

// 2Col link arrows
	sh$(".cols_2 .col ul li a").append("<span>&nbsp;&gt;</span>");

// Upcoming Events
	sh$(".upcoming li a").append("<span>&nbsp;&gt;</span>");
	sh$(".upcoming dd:last").addClass("last");

// Module Hovers
	sh$(".box dl").mouseover(function() {
		sh$(this).addClass("over");
	});
	sh$(".box dl").mouseout(function() {
		sh$(this).removeClass("over");
	});

	sh$(".timely h2 a").mouseover(function() {
		sh$(this).parent(this).parent(".timely").addClass("over");
	});
	sh$(".timely h2 a").mouseout(function() {
		sh$(this).parent(this).parent(".timely").removeClass("over");
	});

	sh$(".timely p a").mouseover(function() {
		sh$(this).parent(this).parent(".timely").addClass("over");
	});
	sh$(".timely p a").mouseout(function() {
		sh$(this).parent(this).parent(".timely").removeClass("over")
	});

// Share show/hide
	sh$("li.option_share .share").click(function() {
		sh$("li.option_share").toggleClass("active");
		sh$("li.option_share a").toggleClass("active");
		sh$("li.option_share ul").toggle();
		return false;
	});

// Campus Life landing nav
	sh$("#landing_campus-life .button").mouseover(function() {
		sh$(this).next(".blurb").addClass("shown")
	});
	sh$("#landing_campus-life .button").mouseout(function() {
		sh$(this).next(".blurb").removeClass("shown")
	});

//Communities document icon hover
// News & Events element group hovers
		sh$(".media dt a").mouseover(function() {
		sh$(this).parent(this).parent("dl.media").addClass("media_over");
	});
	sh$(".media dt a").mouseout(function() {
		sh$(this).parent(this).parent("dl.media").removeClass("media_over");
	});

// Wide page margin fix
	sh$(".page_wide #content .col:eq(2)").addClass("col_last");

// zebra tables
sh$(function() {
	sh$("table").each(function(){
		sh$("tr:nth-child(odd)").addClass("odd");
	});
});

// 2-col margin fix
	sh$(".cols_2 .col:eq(1)").addClass("last");

// Accordion plugin
jQuery.fn.accordion = function(options) {
	// options
	var SLIDE_DOWN_SPEED = 500;
	var SLIDE_UP_SPEED = 250;
	var startClosed = options && options.start && options.start == 'closed';
	var on = options && options.on && (typeof options.on == 'number' && options.on > 0) ? options.on - 1 : 0;
	return this.each(function() {
		jQuery(this).find('dd').hide();
		jQuery(this).find('dt').click(function() {
			var current = jQuery(this.parentNode).find('dd:visible');
			var next = jQuery(this).find('+dd');
			if (current[0] != next[0]) {
				current.slideUp(SLIDE_UP_SPEED);
				sh$("#mmop_content dt").removeClass("active");
				sh$(this).addClass("active");
			}
			if (next.is(':visible')) {
				sh$("#mmop_content dt").removeClass("active");
				next.slideUp(SLIDE_UP_SPEED);
			} else {
				sh$("#mmop_content dt").removeClass("active");
				sh$(this).addClass("active");
				next.slideDown(SLIDE_DOWN_SPEED);
			}
		});
		if (!startClosed) {
			var active = jQuery(this).find('dd:eq(' + on + ')');
			active.slideDown(SLIDE_DOWN_SPEED);
			active.prev("dt").addClass("active");
		}
	});
};

// Accordion Hovers
	sh$("#mmop_content dt").mouseover(function() {
		sh$(this).addClass("over")
	});
	sh$("#mmop_content dt").mouseout(function() {
		sh$(this).removeClass("over")
	});

// Initiate MMOP Accordion defaults
	//sh$('#mmop_content').accordion();
	//sh$('#faq').accordion({on: 3});

}); // Bye-bye jQuery!

