var clock = new Clock();
var index = 0;
var maxSeconds = 5;
var hls = new Array();

function initHlRotate(){
	hls = $('#hl-rotate div.hl-first-item');
	$.each(hls,function(i, it){
		$(it).click(function(){
			changeHighlight(i);
		});
	});
	
	changeHighlight(0);
	timer();
}

function changeHighlight(i){
	index = i==hls.length ? 0 : i;

	$(hls).stop().animate({opacity: 0},1000,function(){$(this).css('z-index','1');});
	$(hls).eq(index).stop().animate({opacity: 1},1000,function(){$(this).css('z-index','5');});
	
	clock.reset();
}

function Clock(){
	this.clock = 0;
	this.add = function(){
		this.clock++;
		if (this.clock == maxSeconds){
			changeHighlight(index+1);
		}
	};
	this.reset = function(){
		this.clock = 0;
	};
}

function timer(){
	clock.add();
	setTimeout("timer()",1000);
} 
