window.$ = jQuery;

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

$(document).ready(function(){

	// add class to body to show we have javascript
	$("body").addClass("js");

	// first/last item fixes (for IE)
	$("#header .sys_left ul li:last-child, #homepage #spotlights .sys_spotlight ul li:last-child, #internal #internalNav ul li:last-child, #internal #main #pageTools ul li:last-child, #footer ul li:last-child").addClass("sys_last");
	$("#internal #internalNav ul li:first-child, #internal #content .sys_relatedRight h2:first-child, #internal #content .sys_relatedRight ul li:first-child").addClass("sys_first");

	// rollover fix (for IE6)
	$("#menu ul li:not(li li), #peopleLookUp tr").hoverClass("sys_active");

	// add 'rollover' class to links when a rollover box is open
	$("#menu ul li div.sys_rollover").each(function (i) {
		$(this).parent().mouseover(function (i) {
			$(this).attr("id","rollover")
			// check if next or prev LIs have 'on' state
			// remove left/right bar if so
			if($(this).prev().attr("id") == "mmOn") {
				$(this).addClass("sys_leftFix");
			};
			if($(this).next().attr("id") == "mmOn") {
				$(this).addClass("sys_rightFix");
			};
		}).mouseout(function (i) {
			$(this).removeAttr("id","rollover").removeClass("sys_leftFix").removeClass("sys_rightFix");
		});
	});

	// clear default text from search boxes
	$("#header .sys_right fieldset input, #internal #main #pageTools fieldset input").focus(function (i) {
		if($(this).attr("value") == "keyword(s)") {
			$(this).attr("value", "");
		};
	}).blur(function (i) {
		if($(this).attr("value") == "") {
			$(this).attr("value", "keyword(s)");
		};
	});

	// onfocus for general forms
	$(".sys_genForm :input[type=text], .sys_genForm textarea").focus(function() {
		$(this).addClass("sys_active");
		if(this.value == this.defaultValue) {
			this.value = "";
		};
	}).blur(function() {
		$(this).removeClass("sys_active");
		if(this.value == "") {
			this.value = this.defaultValue;
		};
	});

	// create image borders
	$(".imgBorder, .imgBorderLeft, .imgBorderRight, .sys_thumbnail:not(#SchoolHomeImageRotate_List .sys_thumbnail)").each(function (i) {
		// get width and height of the image
		widthOfImage = $(this).find("img").width();
		// take 10px off the height for the 5px border already placed top and bottom
		heightOfImage = $(this).find("img").height() - 10;
		// wrap the image in span tags for gradient
		$(this).wrapInner('<span class="sys_holder"><span class="sys_shadow1"><span class="sys_shadow2"><span class="sys_shadow3"><span class="sys_shadow4"></span></span></span></span></span>');
		// add the border spans in after the image
		$(this).find('.sys_holder').append('<span class="sys_fade1" style="width:' + widthOfImage + 'px;"><!-- //--></span><span class="sys_fade2" style="width:' + widthOfImage + 'px;"><!-- //--></span><span class="sys_fade3" style="height:' + heightOfImage + 'px;"><!-- //--></span><span class="sys_fade4" style="height:' + heightOfImage + 'px;"><!-- //--></span>');
		// fix IE problem where bottom or right borders are 1px when image is of uneven width or height
		if(heightOfImage != Math.round(heightOfImage / 2) * 2 ) {
			$(this).find('.sys_holder').addClass('sys_ieFixBtm');
		};
		if(widthOfImage != Math.round(widthOfImage / 2) * 2 ) {
			$(this).find('.sys_holder').addClass('sys_ieFixRight');
		};
	});



	// advanced search
	$(".sys_advancedSearchBox").css("display","none");							
		$("#advancedSearch").click(function(){	
			if($(".sys_advancedSearchBox").css("display") == "none") {
					$(".sys_advancedSearchBox").css("display", "block");
					$(".sys_searchBox").css("display", "none");
					$("#advancedSearch a").text("Simple Search");
					}
			else if($(".sys_advancedSearchBox").css("display") == "block") {
						$(".sys_advancedSearchBox").css("display", "none");
						$(".sys_searchBox").css("display", "block");
						$("#advancedSearch a").text("Advanced Search");
					};
	});

	// A to Z list of letters
	$(".sys_atoz-control ul").each(function (i) {
	$(this).find("a").wrapInner('<span><span></span></span>');
	$(this).find("li.sys_noresults span").wrap('<a href="#"><span></span></a>');

	
	// A to Z Current Letter
	$(".sys_atoz-control-currentletter big").wrapInner('<span><span><span><span></span></span></span></span>');
	});
});


