// JavaScript Document

rotateidx = 0;
	
handle = window.setInterval(rotate, 7000);
	
function rotate() {
		
		$max = $('.rotate').length - 1;
		
		if ($max > 0) {
			// only rotate if there's more than one item
			$('.rotate-' + rotateidx).fadeOut('slow');
			$('#rotateBtn-' + rotateidx).removeClass('active');
			if (rotateidx==$max) {
				rotateidx=0
			} else {
				rotateidx++;	
			}
			$('#rotateBtn-' + rotateidx).addClass('active');
			$('.rotate-' + rotateidx).fadeIn('slow');
			
		}
}


function rotateTo(idx)  {
	window.clearInterval(handle);
	$('.rotate-' + rotateidx).fadeOut('slow');
	$('#rotateBtn-' + rotateidx).removeClass('active');
	rotateidx = idx;
	$('.rotate-' + rotateidx).fadeIn('slow');	
	$('#rotateBtn-' + rotateidx).addClass('active');
	handle = window.setInterval(reinitInterval, 15000);
}

function reinitInterval() {
	window.clearInterval(handle);
	handle = window.setInterval(rotate, 7000);
}


$(document).ready(function() {
	$('#rotateBtn-' + rotateidx).addClass('active');	
});

function relink(idx, id) {
	//alert('ok');
	oldhref = $('.rotate-' + idx + ' A').attr('href');
	$('.rotate-' + idx + ' A').mouseout(function() {
												 $('.rotate-' + idx + ' A').attr('href', oldhref);
												 });
	$('.rotate-' + idx + ' A').attr('href', '/banner/click/' + id);
//	top.location.href = "/banner/click/" + id;	
}
