var itemCount;
var oldItemNum = 0;
var currentItemNum=0;

function startRotate(){
	//alert("test");
	itemCount = jQuery("#rotatorImg img").size(); 
	interval = setInterval(rotate,4500);
	jQuery('#rotator','#rotator_content').hover(function() {
		clearInterval(interval);
	}, function() {
		interval = setInterval(rotate,4500);
		rotate();
	});
}
function rotate() {
	currentItemNum = (oldItemNum + 1) % itemCount;
	nextItemNum = currentItemNum + 1;
	if(oldItemNum == 0){
		prevItem = 5;
	} else {
		prevItem = oldItemNum - 1;
	}
	jQuery("#rotatorImg img:eq(" + oldItemNum + ")").fadeOut("fast",function(){
		jQuery("#rotatorImg img:eq(" + currentItemNum + ")").fadeIn("slow");
		jQuery("#rotatorTxt div:eq(" + prevItem + ")").fadeOut("fast");
		jQuery("#rotatorTxt div:eq(" + currentItemNum + ")").fadeIn("slow");
		jQuery(".rotatorNavItem a").removeClass("hover");
		jQuery(".rotatorNavItem a:eq(" + currentItemNum + ")").addClass("hover");
	})
	oldItemNum = currentItemNum;
}

jQuery(document).ready(function() {

	startRotate();

	jQuery(".rotatorNavItem a").click(function(){
		jQuery(".rotatorNavItem a").removeClass("hover");
		jQuery(this).addClass("hover");
		return false;
	});
	
	jQuery(".rotatorNavItem a").eq(0).click(function(){
		jQuery("#rotatorImg img").hide();
		jQuery("#rotatorImg img").eq(0).show();
		jQuery("#rotatorTxt div").hide();
		jQuery("#rotatorTxt div").eq(0).show();
		oldItemNum = 0;
		return false;
	});	
	
	jQuery(".rotatorNavItem a").eq(1).click(function(){
		jQuery("#rotatorImg img").hide();
		jQuery("#rotatorImg img").eq(1).show();
		jQuery("#rotatorTxt div").hide();
		jQuery("#rotatorTxt div").eq(1).show();
		oldItemNum = 1;
		return false;
	});	
	
	jQuery(".rotatorNavItem a").eq(2).click(function(){
		jQuery("#rotatorImg img").hide();
		jQuery("#rotatorImg img").eq(2).show();
		jQuery("#rotatorTxt div").hide();
		jQuery("#rotatorTxt div").eq(2).show();
		oldItemNum = 2;
		return false;
	});		
	
	jQuery(".rotatorNavItem a").eq(3).click(function(){
		jQuery("#rotatorImg img").hide();
		jQuery("#rotatorImg img").eq(3).show();
		jQuery("#rotatorTxt div").hide();
		jQuery("#rotatorTxt div").eq(3).show();
		oldItemNum = 3;
		return false;
	});			

	jQuery(".rotatorNavItem a").eq(4).click(function(){
		jQuery("#rotatorImg img").hide();
		jQuery("#rotatorImg img").eq(4).show();
		jQuery("#rotatorTxt div").hide();
		jQuery("#rotatorTxt div").eq(4).show();
		oldItemNum = 4;
		return false;
	});			

	jQuery(".rotatorNavItem a").eq(5).click(function(){
		jQuery("#rotatorImg img").hide();
		jQuery("#rotatorImg img").eq(5).show();
		jQuery("#rotatorTxt div").hide();
		jQuery("#rotatorTxt div").eq(5).show();
		oldItemNum = 5;
		return false;
	});			


	jQuery("#rotatorImg img").hide();
	jQuery("#rotatorImg img").eq(0).show();
	jQuery("#rotatorTxt div").hide();
	jQuery("#rotatorTxt div").eq(0).show();
	return false;

});
