function setupslides() {

	var imageSum	= $("#slideshow li").size();
	var imageWidth = $("#slides").width();
	
	for(i=1; i <= imageSum; i++) {
		var $lib = $("#slideshow li:nth-child("+ i+")")
		//var $bg = $lib.find("div").css("background-image");
		add2SlideMenu(i,$lib.find("h2").html());
	}
	
	$("#slides ol").css({'width' : imageWidth * imageSum});
	$("#slidemenu a:first-child").addClass('active');
	
	
	rotate = function(){
		var triggerID = parseInt($active.attr("rel"));
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$("#slidemenu a").removeClass('active');
		$active.addClass('active');
		$("#slides ol").animate({left: -image_reelPosition}, 500 );
	}; 
	
	rotateSwitch = function(){
		play = setInterval(function(){ 
			$active = $('#slidemenu a.active').next(); //Move to the next paging
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('#slidemenu a:first'); //go back to first
			}
			rotate(); 
		}, 10000);
	};
	
	$("#slides li").hover(function() {
		clearInterval(play); 
		}, function() {
			rotateSwitch(); 
		}
	);	
	
	
	//On Click
	$("#slidemenu a").click(function() {
		$active = $(this); //Activate the clicked paging
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation timer
		return false; //Prevent browser jump to link anchor
	});
	
	rotateSwitch();
}

function add2SlideMenu(id,textstring) {
	id = id-1;
	var $div = $('<a rel="'+id+'"><div>'+textstring+'</div></a>');
	//$div.css("background-image",bg);
	var $menu = $("#slidemenu").append($div);
}

