// Initials:
var featuresInterval = null;
var currentItem = 0;

// CUSTOM FUNCTIONS:

// Position arrow over active item:
function positionItemArrow() {
	var currentOffset = $(".rotate .selected").offset();
	
	$("img#current_item").css("top", currentOffset.top + 12);
	$("img#current_item").css("left", currentOffset.left - 80); }

// Rotate to next item:
function rotateItems() {
		
	// Deselect the current item:
	$(".rotate .selected").removeClass("selected");

	// Empty the about div:
	$("div#about").empty();
	
	// Iterate the current item count:
	currentItem++;
	
	// The current item is too high, reset currentItem:
	if(currentItem > ($(".rotate .rotate_item").length - 1)) { 
		currentItem = 0; }

 // Select the new current item:
	$(".rotate .rotate_item").eq(currentItem).addClass("selected");
	
	// Position the selected indicator:
	positionItemArrow();
	
	// Change the contents of the about div:
	$("div#about").html( $(".rotate .selected").next("div.about").html() ); }



// Listener functions:
$(document).ready(function() {
	
	// Create the current item arrow:
	$("body").prepend('<img id="current_item" src="images/elements/large_arrow.png" alt="Mouse over the items on the right to view more information." />');
	
	// Position the item arrow:
	positionItemArrow();

	// Run the rotate items function at intervals:
	featuresInterval = setInterval("rotateItems()", 7000);


 // User has scrolled over a tidbit item:
	$(".rotate_item").hover(function() {
	
	 // Make this the previous item the current item:
		currentItem = $(".rotate_item").index(this) - 1;
		
		// Rotate to this item:
		rotateItems();
	
	 // Stop the interval:
		clearInterval(featuresInterval);

		
	}, function() {
	
	 // Run the rotate items function at intervals:
 	featuresInterval = setInterval("rotateItems()", 7000);
	
	});
	
	
	// User has paused over the about div:
	$("div#about").hover(function() {
	
	 // Stop the interval:
		clearInterval(featuresInterval);
		
		// Make selected:
		$(this).addClass("selected");

		
	}, function() {
	
	 // Run the rotate items function at intervals:
 	featuresInterval = setInterval("rotateItems()", 7000);
		
		// Deselect:
		$(this).removeClass("selected");
	
	});
	
	
	// Window listeners:
 $(window).resize(function() {

  // Keep the services list item arrow positioned:
		positionItemArrow(); });	
	
});
