var myRotateCount;
var myRotateSpeed = 6000;

$(document).ready(function(){ 

	myRotateCount = $('#rotateControl > div').size();
	rotateMyImg(0,0);	

	$('#rotateControl > div').click(function(){
		myIndex = $("#rotateControl > div").index(this);
		resetMyImg(myIndex,0);
	});
	
	
	$('#rotateContent > div').hover(
		function(){
			clearTimeout(timer);
			clearTimeout(timer1);
		}
		,
		function(){
			myIndex = $("#rotateContent > div").index(this)+1
			if(myIndex >= myRotateCount) { myIndex = 0; }
			resetMyImg(myIndex,myRotateSpeed);
		}
	);
	
	

});


function rotateMyImg(myIndex,mySpeed) {

  
  timer1 = setTimeout(
	  function(){
	  $("#rotateControl > div").removeClass('rotateControlItemSelected');
	  $("#rotateContent > div").hide();
	  
	  $("#rotateControl > div:eq("+myIndex+")").addClass('rotateControlItemSelected');
	  $("#rotateContent > div:eq("+myIndex+")").fadeIn(1000);
	
	  myIndex++;  
		
	  if(myIndex >= myRotateCount) { myIndex = 0; } 
			timer = setTimeout("rotateMyImg("+myIndex+",0)", myRotateSpeed); 
	  }	
	  ,mySpeed
  );	        
}
  
function resetMyImg(myIndex,mySpeed) {
   clearTimeout(timer);
   clearTimeout(timer1);
   rotateMyImg(myIndex,mySpeed);
}
	
