var xOffset = 10;
var yOffset = 200;
var timeOut = 1000;
var rotateTime = 4000;
var _rotate;
var readMoreMenu;

jQuery(document).ready(function(){
	//create readmore menu and nav boxes
	init();

	/*jQuery("#nr_content").click(
   		function (e) {
   			self.location = newsArray[rotateIndex][1];
   		});
	*/
	jQuery("div#news_rotator_body").hover(
   		function (e) { //onmouse over
			//only create once
			clearTimeout(_rotate);
  		},
  		function (e) { //on mouse out
			clearTimeout(_rotate);
			_rotate= setTimeout(rotate, rotateTime);
  		}
	);
});
	
var rotateIndex;	
// function to rotate item
function rotate(){
	//increment rotate item
	rotateIndex++;
	if(newsArray.length <= rotateIndex)
		rotateIndex = 0;
	// set item
	setPrms();
}	


function init(){
	newsArray = jQuery("div.news_item");
	//add click to each navigation box
	jQuery("#news_rotator_nav > ul >li").click(function(){
		var $nextLi = jQuery(this).html();
		rotateIndex = ($nextLi - 1);
		setPrms();
	})
	rotateIndex = 0;
	setPrms();
}	
// function to set each parameter of an item
function setPrms(){
	newsArray = jQuery("div.news_item");
	if(newsArray.length > rotateIndex){
		jQuery("li.selected").removeClass("selected");
		
		jQuery("#news_rotator_title").html(jQuery(newsArray[rotateIndex]).find("div.news_ttl").html());
		jQuery("#news_rotator_body").html(jQuery(newsArray[rotateIndex]).find("div.news_body").html());
		
		jQuery(jQuery("#news_rotator_nav > ul > li")[rotateIndex]).addClass("selected");
		clearTimeout(_rotate);
		_rotate= setTimeout(rotate, rotateTime);
	}
}
