var thisid = '#home-first';
var t;
var timer_is_on=0;

(function($){
	$('#active-home-buttons li').mouseover(function(){
		$(this).addClass('hover');
	});
	$('#active-home-buttons li').mouseout(function(){
		$(this).removeClass('hover');
	});
	
	doTimer();
	$('#active-home-buttons li').click(function(){
		stopCount();
		thisid = '#'+$(this).attr('id');
		doTimer();
	});
})(window.jQuery);

function change_banner(thisid)
{
	var position = 0;
	//var next = 'home-first';
	if($(thisid).attr('id') == 'home-first')
	{
		position = 40;
		next = 'home-second';
	}
	else if($(thisid).attr('id') == 'home-second')
	{
		position = 1020;
		next = 'home-third';
	}
	else if($(thisid).attr('id') == 'home-third')
	{
		position = 2000;
		next = 'home-fourth';
	}
	else if($(thisid).attr('id') == 'home-fourth')
	{
		position = 2980;
		next = 'home-first';
	}
	$('#active-home-buttons li').removeClass('active');
	$('#active-home-content li').removeClass('active');
	$(thisid).addClass('active');
	var content = $(thisid).attr('id')+'-content';
	$('#'+content).addClass('active');
	$('#active-home-banner ul').animate({left: '-'+position}, 800);
	return '#'+next;
}

function timedCount()
{
	thisid = change_banner(thisid);
	t=setTimeout("timedCount()",10000);
}

function doTimer()
{
	if (!timer_is_on)
  	{
  		timer_is_on=1;
  		timedCount();
  	}
}

function stopCount()
{
	clearTimeout(t);
	timer_is_on=0;
}
