$(function(){
	var rotationTimer = null;
	var currentImageIndex = 0;
	
	var imageContainer = $('#rotator-image');
	var controlContainer = $('#rotator-nav-ul');
	
	function showImageByIndex(i) {
		currentImageIndex = i;
		if (!imageContainer.find('li:eq('+currentImageIndex+')').size() > 0)
			currentImageIndex = i = 0;
			
		imageContainer.find('li').hide();
		imageContainer.find('li:eq('+i+')').fadeIn();
		
		controlContainer.find('.on').removeClass('on');
		controlContainer.find('a:eq('+i+')').addClass('on');
		
		controlContainer.find('li.onx').removeClass('onx');
		controlContainer.find('li:eq('+i+')').addClass('onx');
		
		//Cufon.replace('#rotator-nav-ul li a .cufon-futura', {color: 'black'});
		//Cufon.replace('#rotator-nav-ul li:eq('+i+') a.on .cufon-futura', {color: 'white'});
		
		
	}
	
	function showNextImage() {
		showImageByIndex(currentImageIndex);
		currentImageIndex++;
	}
	
	function startRotation() {
		rotationTimer = setInterval(showNextImage, 6000);
	}
	
	function endRotation() {
		clearInterval(rotationTimer);
	}
	
	controlContainer.find('a').hover(function(){
		endRotation();
		var currentImageIndex = $(this).parent().prevAll('li').size();
		showImageByIndex(currentImageIndex);
		
		//Cufon.replace('#rotator-nav-ul li:eq('+currentImageIndex+') a.on .cufon-futura', {color: 'white'});
	}, function() {
		currentImageIndex++;
		startRotation();
		
	});
	
	$('#rotator-image').find('li').css('opacity', 1);
	showNextImage();
	startRotation();
		
});

