var animatedtab = true;

function topstories() {
	$('#frontpage-promo-images ul > li').css("display","none");
	topstories_current = 0;
	topstories_switch(1);
}

var topstories_rotateTimeout;
function topstories_switch(num) {
	if (num == undefined) {
		if ((++topstories_current) > topstories_number) { topstories_current = 1; }
	} else {
		topstories_current = num;
	}
	num = topstories_current;
	$('#topstories-title-link').html(topstories_data[num-1]['title']);
	$('#topstories-summary').html(topstories_data[num-1]['description']);
	$('#topstories-type-label').html(topstories_data[num-1]['label']);
	$('#topstories-images ul > li').css("display","none");
	$('#topstories-img-'+num).fadeIn("def");
	$('#topstories-menu ul > li').removeClass();
	$('#topstories-menu-'+num).addClass('selected');
	document.getElementById('topstories-title-link').href = topstories_data[num-1]['url'];
	if (topstories_rotateTimeout != undefined) clearTimeout(topstories_rotateTimeout);
	topstories_rotateTimeout = setTimeout('topstories_switch()',5000);
}

var headernav_drop_delay;
var headernav_drop_close_delay;

function headernav_drop_init() {
	$('.site-header-button-exp').each(function(){
		$(this).bind("mouseenter", function(){
			//var thisli = $(this).parent();
			var thisli = $(this);
			var dropdown = '#'+$(thisli).attr('id')+'-dropdown';
			var button = '#'+$(thisli).attr('id');
			var pos = $(thisli).offset();    
			var eWidth = $(thisli).outerWidth();
			var mWidth = $(dropdown).outerWidth();
			var left = 0;
			var top = $('#site-header-buttons').position().top + $('#site-header-buttons').outerHeight();
			if ($('#site-header-navbar-inner').length > 0) {
				var left = $('#site-header-navbar-inner').position().left + thisli.position().left + (eWidth/2) - (mWidth/2);
			} else {
				var left = thisli.position().left + (eWidth/2) - (mWidth/2);
			}
			clearTimeout(headernav_drop_close_delay);
			clearTimeout(headernav_drop_delay);
			headernav_drop_delay = setTimeout(function() {
				if ($(dropdown).css('display') != 'block') {
					//$('.site-header-button-exp a').css({visibility: 'hidden'}); 
					$('#topfullbanner_inner').css({display: 'none'});
					$('.site-header-dropdown').css({ display: 'none' });
					$('#site-header-buttons li').removeClass('site-header-button-hover');
					$(button).addClass('site-header-button-hover');
					$(dropdown).css( { 
						position: 'absolute',
						zIndex: 5000,
						left: left, 
						top: top
					} );
					$(dropdown).hide().fadeIn('fast');
					//$(button + ' a').css({visibility: 'visible'}).hide().fadeIn('fast'); 
					//$(dropdown).slideDown('fast');
				}
			}, 300 );
		}).bind("mouseleave",function(){
			clearTimeout(headernav_drop_close_delay);
			clearTimeout(headernav_drop_delay);
			headernav_drop_close_delay = setTimeout(function() {
				$('#site-header-buttons li').removeClass('site-header-button-hover');
				$('.site-header-dropdown').css({ display: 'none' });
				//$('.site-header-button-exp a').css({visibility: 'hidden'}); 
				$('#topfullbanner_inner').css({display: 'block'});
			}, 300); 
		});

		//var thisli = $(this).parent();
		var thisli = $(this);
		var dropdown = '#'+$(thisli).attr('id')+'-dropdown';
		$(dropdown).bind("mouseenter", function(){
			clearTimeout(headernav_drop_close_delay);
		}).bind("mouseleave",function(){
			clearTimeout(headernav_drop_close_delay);
			clearTimeout(headernav_drop_delay);
			headernav_drop_close_delay = setTimeout(function() {
				$('#site-header-buttons li').removeClass('site-header-button-hover');
				$('.site-header-dropdown').css({ display: 'none' });
				//$('.site-header-button-exp a').css({visibility: 'hidden'}); 
				$('#topfullbanner_inner').css({display: 'block'});
			}, 300); 
		});
	});
}

