//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
// return value from key in URL query string
function getQueryKey(searchKey) {
    var url = location.href;
    var query = url.split("?");
    if(query.length < 2)
        return "";
    var pairs = query[1].split("&");
    
    var split, key, val, found = false;
    
    for ( var i = 0; i < pairs.length; i++ ) {
        split = pairs[i].split("=");
        key = split[0];
        val = split[1];
        
        if ( key == searchKey ) {
            found = val;
            return found;
        }
    }
    
    if ( found == false ) {
        return "";
    }
}


$(window).load(function() {
	$('#close_button a').click(function()
	{
		$('#modal').hide();
		$('#modal_top #m_header').html('');
		$('#modal_middle').html('');
		return false;
	});
	
	$('#joblist a, a.modal_link').click(function(){
		$('#modal_top #m_header').load(this.href  + ' #m_header h1');
		$('#modal_middle').load(this.href + ' #m_content', function(){
			$('#modal #m_content a').click(function(){
				var job = $('#modal_top #m_header h1')[0].innerHTML;
				this.href = this.href + '?job=' + escape(jQuery.trim(job.replace(/<br\/>|<br>/g, " ")));
			});
		});
		$('#modal').show();
		return false;
			
	});

	if( $('#applicationForm').length > 0 )
	{
		var job = unescape(getQueryKey('job'));
		$('#applicationForm').prepend('<input type="hidden" name="job_title_and_number" value="' + job + '" />');
	}
	
	
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop > li").hover(function() {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		
		$(".navtop > li li ").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
			
		});
		
		
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").mouseover(function () {
			$(this).addClass("redraw");
		});
		$(".navtop li ul").mouseout(function () {
			$(this).removeClass("redraw");
		});
	}

	if (window.location.hostname.indexOf("cms") > 0) {
		$("#headerImage").css("margin-top", 0);
	}
});

