	/* CONFIGURATION: Auto-Rotation and Delays */
	var willAutorotate = true; //set this to false if you do not want the script to rotate through items automatically
	var delay = 6000; //the default delay - this is used when the script is auto-rotating.
	var clickdelay = 10000; //delay between when a user clicks a nav button and the rotation kicks in again.
	/* END CONFIGURATION */
	
$(document).ready(function(){
		
	//add a simple wait function to the jQuery object
	$.fn.wait = function(time, type) { time = time || 1000; type = type || "fx"; return this.queue(type, function() {var self = this; setTimeout(function() {$(self).dequeue();}, time);});};
	
	//Nav-button animation logic
	$(".newsnavbutton").mouseover (function(){ $(this).queue(function(){ $(this).addClass("navbuttonhover"); $(this).dequeue(); });
					 }).mouseout  (function(){ $(this).queue(function(){ $(this).removeClass("navbuttonhover"); $(this).dequeue(); });
					 }).click     (function(){ $(this).queue(function(){ $(this).removeClass("navbuttonhover").addClass("navbuttonclick").wait(100).removeClass("navbuttonclick", 300); $(this).dequeue(); });
					 });
	
	//Item rotation logic
	var items = $(".newsitem").get(); // items is an array of all the newsitem elements
	var maxitem = $(".newsitem").length - 1; // find out what the index of the last item is
	var safeToClick = false; if( $(".newsitem").length > 0) { safeToClick = true; }
	var current = -1; // initialize the current index.
	function pullItem(i) {
		if( i === undefined ){ i = 0; } //defaults to pull the first item.
		//next two lines do the rotation animation.
		$(items).hide();
		$("#news-cursor").css({'width':''}).queue(function(){ $(items[i]).show(); $(this).wait(500).animate({ width: "0px" }, 1500); $(this).dequeue(); });
		current = i;
	}
	function pullNext() {
		var next = current + 1;
		if (next > maxitem) { next = 0; }
		pullItem(next);
	}
	function pullPrev() {
		var prev = current - 1;
		if (prev < 0) { prev = maxitem; }
		pullItem(prev);
	}
	
	//Auto-rotation logic
	var queuedRotation = null;
	function autoRotate(thisdelay){ queuedRotation = setTimeout('$("#newsnav-next").click();', thisdelay); delay = 6000; }
	
	//Attach all the above logic to the navigation buttons.
	$(".newsnavbutton").mouseup(function(){ if(willAutorotate){clearTimeout(queuedRotation); delay = clickdelay;} });
	$("#newsnav-prev").click(function(){ if(safeToClick) { pullPrev(); if(willAutorotate){autoRotate(delay);} } });
	$("#newsnav-next").click(function(){ if(safeToClick) { pullNext(); if(willAutorotate){autoRotate(delay);} } });
	
	//do the initial item pull now
	if(safeToClick) {$("#newsnav-next").click();}
	
	
});
