$(document).ready(function(){
	$('#header > ul > li > a').hover(
		function(evt) { 
			var el = $('ul', this.parentNode)
			if(!el[0])
				return
				
			if(el[0].isDown) {
				el[0].needsToGoBackUp = true
				return
			}
			
			el[0].isDown = true
			el.slideDown('800'); 
		},
		
		function() {
			var el = $('ul', this.parentNode)
			if(!el[0])
				return
				
			el[0].needsToGoBackUp = false
		}
	),

	$('#header > ul > li').hover(
		function() {},
		function() { 
			var el = $('ul', this)

			if(!el[0] || !el[0].isDown)
				return
				
			el.slideUp('600', function() {
				this.isDown = false
				if(!this.needsToGoBackUp)
					return
				this.isDown = true
				$('ul', this.parentNode).slideDown('800')
			}); 
		}
	)
	
  $('.news_link').click(
      function() { 
          $(this).next('div.news').slideToggle(); 
          $(this).toggleClass('closed'); 
          $(this).toggleClass('open'); 
      });

	leftNavLoad();
    $.swapImage(".swapImage");
})
		
function getNews(url, clicked_link) {
    if (clicked_link) { 
        $('div.news p').css('font-weight','normal');
    }
    $('.big_banner h1').fadeOut();
    $('#newsContent').fadeOut( function() {
        $.get(url, function(xml) {
          $('#newsContent').load(url).fadeIn(function() { $('.big_banner h1').html($('#newsContent').find('#newsHeadline').text()).fadeIn();	});
        }); 
    });
    if (clicked_link) { 
        $(clicked_link).parent().css('font-weight', 'bold');
    }
}


function pickHomeContent() {
        // pick main content
		var content_choice = Math.floor(Math.random()*3) + 1
		$("#homepage_content_" + content_choice).show();

        // pick independent contractor image
		var image_choice = Math.floor(Math.random()*2) + 1
		$("#independent_" + image_choice).show();

        // pick flash content
		var flash_choice = Math.floor(Math.random()*3) + 1
		$("#flash_wrapper_" + flash_choice).show();
}

function leftNavLoad() {
    $(".left_nav .left_subnav a").each( function() { 
        if (this.href == document.location || $(this).parent().parent().prev("a")[0].href == document.location) {
					if(this.href == document.location)
           	$(this).parent("li").addClass("current"); 
           $(this).parent().parent().show(); 
           $(this).parent().parent().prev("a").addClass("open"); 
           return;
        } else {
					// $(this).parent().parent().hide(); 
				}

    });
}

