$(document).ready(function (){
	// set JS class for CSS
	$('HTML').addClass('JS');
	
	// Setup link to open and close the contact panel
	
	$("#main-nav li.contact-us a, p#close-contact a").click(function () {
		if ($("#contact-us").css("display")=="none") {
			$("#contact-us").slideDown();
			$("#main-nav li.contact-us a").addClass("selected");
			return false;
		} else {
			$("#contact-us").slideUp();
			$("#main-nav li.contact-us a").removeClass("selected");
			return false;
		}
	});
		
	// If on home page, hide and show relevant text for field links on hover
	
	$("body#home ul#home-field-selector li").hover(
		function () {
			$("#home-field-descriptions dd").hide();
			$("#home-field-descriptions dd."+$(this).attr("class")).show();
		},
		function () {
			$("#home-field-descriptions dd").hide();
			$("#home-field-descriptions dd.welcome").show();			
		}
	);
	
	// If there's a job list about, make whole rows clickable
	$('table.job-list tr.job-listing').click(function() {
        var href = $(this).find("a").attr("href");
        if(href) {
            window.location = href;
        }
    });
    
    // rotating quotes...
	function next_quote() {
		// fade out current quote
		$(".rotating-quotes").eq(current_quote - 1).fadeOut(500, function() {
			// advance to next quote
			current_quote++; if (current_quote > $(".rotating-quotes").length) current_quote = 1;
			// save current quote to cookie
			if ($("body#home").length) {$.cookie('saved_home_quote', current_quote);
			} else if ($("body#search").length || $("body#about-us").length) {$.cookie('saved_search_quote', current_quote);}
			// fade in new quote
			$(".rotating-quotes").eq(current_quote -1).fadeIn(500);
		})
	}
    if ($(".rotating-quotes").length) {
    	var current_quote = 1;
    	if ($("body#home").length) {
    		if ($.cookie('saved_home_quote')) { // if we've saved a cookie...
	    		current_quote = $.cookie('saved_home_quote'); // load in saved quote
				current_quote++; if (current_quote > $(".rotating-quotes").length) current_quote = 1; // advance to the next one
	    	}
			$.cookie('saved_home_quote', current_quote); // resave quote
	    	$(".rotating-quotes").hide().eq(current_quote - 1).show(); // display quote
    	} else if ($("body#search").length || $("body#about-us").length) {
    		if ($.cookie('saved_search_quote')) { // if we've saved a cookie...
	    		current_quote = $.cookie('saved_search_quote'); // load in saved quote
				current_quote++; if (current_quote > $(".rotating-quotes").length) current_quote = 1; // advance to the next one
			}
    		$.cookie('saved_search_quote', current_quote); // resave quote
    		$(".rotating-quotes").hide().eq(current_quote - 1).show(); // display quote
    	}
    	var quote_timer = setInterval(next_quote, 12000);
    }

});
