$(function(){
	
	// initialise home promo gallery
	$('#home-promo ul').show().find('li a:first').addClass('current');
	$('#home-promo>div').eq(0).show();
	$('#home-promo>div').eq(1).removeClass('loading').hide();
	$('#home-promo>div').eq(2).removeClass('loading').hide();	

	t = setTimeout('cyclePromos()',interval);
	
	$("#home-promo>div").hover(
		function () {
			freezeCycling=true;
		}, 
		function () {
			freezeCycling=false;
		}
	);
		
	// set up slideshow click events
	$('#home-promo ul a').bind('activate mouseover',function(){
		freezeCycling=true;
		if(!$(this).hasClass('current')){
			var targetDiv = $(this).attr('href');
			var prevLink = $('#home-promo .current');
			prevLink.removeClass('current');
			$(this).addClass('current');			
			Cufon.replace(prevLink);
			Cufon.replace($(this));
			$('#home-promo>div:visible').fadeOut('fast',function(){
				if(!activeAnimation){
				activeAnimation = true;
				$(targetDiv).fadeIn('fast',function(){
					activeAnimation = false;
				});
				}
			});
		}		
		return false;
	}).bind('deactivate mouseout',function(){
		freezeCycling=false;
		return false;
	}).click(function(){
		return false;
	});
		
});
// function to cycle homepage promos
var freezeCycling = false, activeAnimation = false, t, interval = 5000;
function cyclePromos(){
	clearTimeout(t);
	if(!freezeCycling){
		if($('#home-promo a.current').parent().next().children('a').length){
			$('#home-promo a.current').parent().next().children('a').trigger('activate').trigger('deactivate');
		}else{
			$('#home-promo ul li a').eq(0).trigger('activate').trigger('deactivate');
		}
		t = setTimeout('cyclePromos()',interval);
	}else{
		t = setTimeout('cyclePromos()',interval);
	}
}
