/******************************************************************************************************************/
// NEWS CAROUSEL FUNCTIONS
/******************************************************************************************************************/

function CarouselHoverHandle(){
	$('.carousel .index-list LI').hover(function(){
		clearTimeout(CarouselTimerId);
		$(this).addClass('current');
		index = $('.carousel .index-list LI').index(this);
		ItemShow(index);
	}, function(){
		CarouselRun(index);
	});
	
	$('.carousel .items-list LI').hover(function(){
		clearTimeout(CarouselTimerId);
		index = $('.carousel .items-list LI').index(this);
	}, function(){
		CarouselRun(index);
	});
}

function ItemShow(i){
	$('.carousel .items-list LI').hide();
	$('.carousel .index-list LI').removeClass('current');
		
	$('.carousel .items-list LI:eq('+ i +')').show();
	$('.carousel .index-list LI:eq('+ i +')').addClass('current');
}

function CarouselRun(i){
	num = $('.carousel .items-list LI').size();
	if (num > 1) {
		ItemShow(i)
		i++;
		if (i == num) i = 0;
		CarouselTimerId = window.setTimeout('CarouselRun('+ i +')', 5000);
	}
}

/******************************************************************************************************************/
// NEWS TICKER FUNCTIONS
/******************************************************************************************************************/

function TickerHoverHandle(){
	$('.ticker LI').hover(function(){
		clearTimeout(TickerTimerId);
		index = $('.ticker LI').index(this);
	}, function(){
		TickerRun(index);
	});
}

function TickerShow(i){
	$('.ticker LI').hide();
	$('.ticker LI:eq('+ i +')').fadeIn('slow');
}

function TickerRun(i){
	num = $('.ticker LI').size();
	if (num > 1) {
		TickerShow(i)
		i++;
		if (i == num) i = 0;
		TickerTimerId = window.setTimeout('TickerRun('+ i +')', 5000);
	}
}

/******************************************************************************************************************/
// ON DOCUMENT LOAD...
/******************************************************************************************************************/

$(function(){
	// Iinitializations
	$('#live-news .date, #live-news H1 A').fadeTo(10, 0.4);
	$('#login').height('5px');
	$('#menu LI UL').fadeTo(10, 0.9);
	
	// Some Fx handle
	$('#login-button').toggle(function(){
		h = $('#login .wrap').height() + 20;
		$('#login').animate({height: h}, 500);
	}, function(){
		$('#login').animate({height:'5px'}, 300);
	});
	
	$('#live-news UL').hover(function(){
		$('#live-news .date, #live-news H1 A').fadeTo(300, 1);
	}, function(){
		$('#live-news .date, #live-news H1 A').fadeTo(500, 0.4);
	});
	
	$('#search .textbox').focus(function(){
		$(this).attr('value','');
	});
	
	$('#links .cont').height('170px');
	$('#links H1').toggle(function(){
		$(this).toggleClass('minus');
		$('#links .cont').height('auto');
	}, function(){
		$(this).toggleClass('minus');
		$('#links .cont').height('170px');
	});
	
	// Adjust blocks height
	max = $('#archive .block:eq(0)').height();	
	$('.block').each(function(){
		if (max < $(this).height()) max = $(this).height();
	});
	$('.block').height(max);
});