/**
 * @author Sonic
 */

var _numstories = 4;
var _currentstory = 1;
var _slidespeed = 2500;
var _loop = "";

function changeSlide(){
	
	_currentstory++;
	
	if(_currentstory==5){
		_currentstory = 1;
	}
	
	img = $('#tbpromo_'+_currentstory).attr("data");
	
	$('#lrg_promo')
			.hide()
			.attr('src',img)
			.fadeIn('250');
	
	$('.news').hide();
	$('.tb_promo').css('borderColor','#cccccc');
	$('.menu_promo').css('textDecoration','none');
	
	$('.newsheading'+_currentstory).show();
	$('.newsdesc'+_currentstory).show();
	
	//hilight thumb
	$('#tbpromo_'+_currentstory).css('borderColor','#1f1d1d');
	
	//hilight menu
	$('#menupromo_'+_currentstory).css('textDecoration','underline');
}

function startLoop(){
	_loop = setInterval(function(){changeSlide()}, _slidespeed)
}

$(document).ready(function() {
    
	//hilight thumb
	$('#tbpromo_1').css('borderColor','#1f1d1d');
	//hilight menu
	$('#menupromo_1').css('textDecoration','underline');
	
	//pause 2 secs before kicking in news promo slideshow
	_pauseLoop = setTimeout(startLoop,2000);
	
	$('.hovernews').hover(
		function(){
			
			clearTimeout(_pauseLoop);
			clearInterval(_loop);
			
			$('.news').hide();
			$('.tb_promo').css('borderColor','#cccccc');
			$('.menu_promo').css('textDecoration','none');	
			
			
			
			$(this).css('borderColor','#cccccc');		
					
			el = $(this).attr('id').split('_');
			
			
			img = $('#tbpromo_'+el[1]).attr("data");
			
			$('#lrg_promo')
			.hide()
			.attr('src',img)
			.fadeIn('250');
			
			$('.newsheading'+el[1]).show();
			$('.newsdesc'+el[1]).show();
			
			//hilight thumb
			$('#tbpromo_'+el[1]).css('borderColor','#1f1d1d');
			
			//hilight menu
			$('#menupromo_'+el[1]).css('textDecoration','underline');

		},
		function(){
			
			_currentstory = el[1];
			clearTimeout(_pauseLoop);
			clearInterval(_loop);
			startLoop();
		}
	);
	

	
});

