$(document).ready(function() {

	// Set Default State
	$("#hmeSlideShowSelect").show();
	$("#hmeSlideShowSelect a:first").addClass("active");

	// Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $("#hmeSlideShow").width();
	var imageSum = $("#hmeSlideShowImg img").size();
	var imageReelWidth = imageWidth * imageSum;

	// Adjust the image reel to its new size
	$("#hmeSlideShowImg").css({'width' : imageReelWidth});

	// Paging + Slider Function
	function rotate(){
		var triggerID = $active.attr("rel") - 1; // Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; // Determines the distance the image reel needs to slide

		$("#hmeSlideShowSelect a").removeClass('active'); // Remove all active class
		$active.addClass('active'); // Add active class (the $active is declared in the rotateSwitch function)

		// Slider Animation
		$("#hmeSlideShowImg").animate({
			left: -image_reelPosition
		}, 500 );
	};

	// Rotation + Timing Event
	function rotateSwitch(){
		play = setInterval(function(){ // Set timer - this will repeat itself every 3 seconds
			$active = $('#hmeSlideShowSelect a.active').next();
			if ( $active.length === 0) { // If paging reaches the end...
				$active = $('#hmeSlideShowSelect a:first'); // Go back to first
			}
			rotate(); // Trigger the paging and slider function
		}, 7000); // Timer speed in milliseconds (3 seconds)
	};

	rotateSwitch(); // Run function on launch

	// On Hover
	$("#hmeSlideShowSelect a").hover(function() {
		clearInterval(play); // Stop the rotation
	}, function() {
		rotateSwitch(); // Resume rotation
	});

	// On Click
	$("#hmeSlideShowSelect a").click(function() {
		$active = $(this); // Activate the clicked paging
		// Reset Timer
		clearInterval(play); // Stop the rotation
		rotate(); // Trigger rotation immediately
		return false; // Prevent browser jump to link anchor
	});
});

/*
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open(){
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
} // jsddm_open

function jsddm_close(){
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
} // jsddm_close

function jsddm_timer(){
	closetimer = window.setTimeout(jsddm_close, timeout);
} // jsddm_timer

function jsddm_canceltimer(){
	if (closetimer){
		window.clearTimeout(closetimer);
	  closetimer = null;
	} //if
} // jsddm_canceltimer

$(document).ready(function(){
   $('#navTop > li').bind('mouseover', jsddm_open)
   $('#navTop > li').bind('mouseout',  jsddm_timer)
});

document.onclick = jsddm_close;

*/

