$(document).ready(function() {
	$('#masthead .nav li').has('ul').hover(function() {
		$(this).children('a').addClass('on');
		$(this).children('ul').show().stop().animate({ opacity: 1 })
	}, function() {
		$(this).children('a').removeClass('on');				
		$(this).children('ul').stop().animate({ opacity: 0 }, function() { 
			$(this).hide();
		});
	});
							
	if(!$.browser.msie) {
		applyNavSelector = function() {
			var activeObject = $('#masthead .nav ul a.on').parent();
			$(activeObject).prepend('<span class="selector" />');				
			var activeWidth = Math.round(parseInt($(activeObject).css('width')));
			var selectorWidth = Math.round(parseInt($('#masthead .nav .selector').css('width')));								
			$(activeObject).children('.selector').css({ left: ((activeWidth - selectorWidth) / 2) });
		}

		applyNavSelector();
	}	
});
