// JavaScript Document

// CSS Drop down menu fix for IE
<!--//--><![CDATA[//><!--

sfHover = function() {
	var sfEls = document.getElementById("topMenu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//--><!]]>

// JQuery functions run when the DOM is ready
$(document).ready(function(){
	
	// Wrap <hr> tags in a div with class='hr'
	$("hr")
	.wrap("<div class='hr'>" +
	"</div>");
	
	// Paginate contentBoxes
		var paginatorString = '<ul class="pagintorLinks"><li><a href="#" class="paginator-toFirst"><< First</a></li><li><a href="#" class="paginator-back">< Back</a></li><li><a href="#" class="paginator-next">Next ></a></li><li><a href="#" class="paginator-toLast">Last >></a></li></ul>';
	
	$("div.contentBox").append(paginatorString);
	$("div.contentBox").prepend(paginatorString);
	
	$("div.contentBox").hide();
	$("div.contentBox:first").show();
	
	$("div.contentBox a.paginator-toFirst").click(function(){
		$(this).parent().parent().parent().fadeOut("fast",function(){ $("div.contentBox:first").fadeIn("slow"); });
	});
	$("div.contentBox a.paginator-toLast").click(function(){
		$(this).parent().parent().parent().fadeOut("fast",function(){	$("div.contentBox:last").fadeIn("slow"); });
	});
	
	$("div.contentBox:first a.paginator-back").addClass("notInUse");
	$("div.contentBox:last a.paginator-next").addClass("notInUse");
	
	$("a.paginator-back").click(function(){	
		var $$ = $(this).parent().parent().parent();
		var isContentBoxBefore = $$.prev().is("div.contentBox");

		if(isContentBoxBefore) {
			$$.fadeOut("fast",function(){
				$$.prev().fadeIn("slow");
			});
		}
	});
	
	$("a.paginator-next").click(function(){	
		var $$ = $(this).parent().parent().parent();
		var isContentBoxAfter = $$.next().is("div.contentBox");

		if(isContentBoxAfter) {
			$$.fadeOut("fast",function(){
				$$.next().fadeIn("slow");
			});
		}
	});// Eof Paginate contentBoxes
	
	//$("#footer ul li:first-child").addClass("hideThis"); // Hides the sitemap link
	//$("#searchBox").addClass("hideThis");
	
	/*
	// Fontsizer init
	
	var options = { min: -4, max: 4};

	//Initialize the font sizer for the site.
	$.FontSizer.Init(options);
	
	// Eof Fontsizer init
	*/
	
	
	// Nested list accordion
	/*
	if (getElementById(courseList)) {

	jQuery('#courseList').Accordion({ 
		active: false, 
		header: '.head', 
		alwaysOpen: false,
		navigation: false, 
		event: 'mouseup', 
		autoheight: true, 
		animated: 'easeslide' 
	}); // Eof nested list accordion
	
	$.fn.search = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
	$("#searchTerm").search();
	
	}
	*/
	$.fn.search = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
	$("#searchTerm").search();
	$("#searchCourse").search();
	
	$("#associations li:first").addClass("first");
	$("#associations li:last").addClass("last");
//	$("#associations li:nth-child(4n+3)").addClass("first");
//	$("#associations li:nth-child(4n)").addClass("last");
	
	// Add classes for divider styling
	$('#higherEd_2 .row:first').addClass('divide');
	$('#higherEd_3 .row:first').addClass('divide');
	$('#post16_2 .row:first').addClass('divide');
	$('#panel_employer_2 .row:first').addClass('divide');
	$('#panel_employer_3 .row:first').addClass('divide');
	$('#panel_employer_4 .row:first').addClass('divide');
	$('#panel_employer_5 .row:first').addClass('divide');
	
	
	$('.panelHide').hide(); // Hide all Job app form panels
	
	$("#showHigherEd_2").click(function() {   
		$("#higherEd_2").show();
		$("#showHigherEd_2").hide()
	});
	$("#showHigherEd_3").click(function() {   
		$("#higherEd_3").show();
		$("#showHigherEd_3").hide()
	});
	$("#showPost16_2").click(function() {   
		$("#post16_2").show();
		$("#showPost16_2").hide()
	});
	$("#aAddAnotherEmployer1").click(function() {   
		$("#panel_employer_2").show();
		$("#aAddAnotherEmployer1").hide()
	});
	$("#aAddAnotherEmployer2").click(function() {   
		$("#panel_employer_3").show();
		$("#aAddAnotherEmployer2").hide()
	});
	$("#aAddAnotherEmployer3").click(function() {   
		$("#panel_employer_4").show();
		$("#aAddAnotherEmployer3").hide()
	});
	$("#aAddAnotherEmployer4").click(function() {   
		$("#panel_employer_5").show();
		$("#aAddAnotherEmployer4").hide()
	});
	

});
