// JavaScript Document
$(document).ready(function() {
	
	var subItemsLaunch = true;
	
	if($.browser.msie){
		$('#jobsButton li.arrow').prepend('<span></span>');
	}

	
	//hack to match height - not used when subItemsLaunch == true hacky :(
	//$('#jobsButton li.arrow').height($('#jobsButton>li:first-child').height()+0.5);
	//$('#jobsButton li ul').css('margin-top', $('#jobsButton>li:first-child').height()+5);
	
	$('#jobsButton li.arrow').hover(
	  	function () {
			$(this).addClass('over');
			$(this).find('ul').css('visibility', 'visible');
	  	},
	  	function () {
			$(this).removeClass('over');
	  	}
	);	
	
	$('#jobsButton>li:first-child').click(function(){
		$('#jobsButton li.arrow').removeClass('open');		
		
		window.location = $(this).find('a').attr("href");	
			
		return false;
		
	});
	
	$('#jobsButton li.arrow li a').click(function(event){
		event.preventDefault();
	});
	
	$('#jobsButton li.arrow li').click(function(event){
		
		event.stopPropagation();	
		
		if(subItemsLaunch){
			window.location = $(this).find('a').attr("href");	
			return false;
		}
		
		if(!$(this).hasClass('selected')){
			
			$('#jobsButton li.arrow li.selected').removeClass('selected');
			
			$(this).addClass('selected');
			
			if($(this).index() == 0){
				$('#jobsButton>li:first-child a').text('View '+$(this).find('a').text());
			}else{
				$('#jobsButton>li:first-child a').text('View '+$(this).find('a').text()+' Postings');
			}
			
			$('#jobsButton>li:first-child a').attr('href', $(this).find('a').attr('href'));

			
			//hack to match height - not used when subItemsLaunch == true hacky :(
			if($(this).index() == 0){
				$('#jobsButton li.arrow').height($('#jobsButton>li:first-child').height()+0.5);
			}else{			
				$('#jobsButton li.arrow').height($('#jobsButton>li:first-child').height());
			}
			
			$('#jobsButton li ul').css('margin-top', $('#jobsButton>li:first-child').height()+5);
			
		}		
		
	});	
	
	$('#jobsButton li.arrow').click(function(){			
		if($(this).hasClass('open')){			
			$(this).find('ul').css('visibility', 'hidden');
			$(this).removeClass('open');
		}else{
			$(this).find('ul').css('visibility', 'visible');
			$(this).addClass('open');
		}
	});	
	
	
});
