$(function(){
	
	Cufon.replace('.btn-link');

	//The default only turns :hover on for links, use hoverables for other elements!
	Cufon.replace('#home-promo ul a', {hover: true});
		
	// 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;
	});

	
	$('.follow-link').live('click', function() {
		var $link = $(this); 
		var href = $link.attr('href');
		var memberName = $link.attr('data-name');
		var strState = 'follow';
		
		MemberOnlyPopup(URL_addparam(href,'_noheader'), 94, 400, GB_RefreshFollowLink($link, memberName, strState));
		
		return false;
	}); 
	
	
	$('.unfollow-link').live('click', function() {
		var $link = $(this); 
		var href = $link.attr('href');
		var memberName = $link.attr('data-name');
		var strState = 'unfollow';
		
		MemberOnlyPopup(URL_addparam(href,'_noheader'), 94, 400, GB_RefreshFollowLink($link, memberName, strState));
		
		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);
	}
}

