
var cur=1;					//Point out the current slide.
var max=0; 					// This is used to tell the script that it's reached the last item and needs to roll back to the first.
var rs_slidenumber = 5; 	//This is the counter,should be number of slide items plus 1
$(document).ready(function() {
	$(".listm").click(function(){
		$(".listm").css("background","url('images/white_dot.png')");
		$(this).css("background","url('images/red_dot.png')");
		var place = $(this).attr('place');
		var offset = cur-place;
		$(".listli").animate({ // It moves all the slides at once, i know this can be optimized, just haven't gotten around to it. Also the reason each item has to have a "left" position set.
			'left':"+="+(offset*960)+"px"
		},(Math.abs(offset)*1200));
		cur=place;
		clearTimeout(slidetime); //Stops the automatic scrolling once you've clicked on a control number.
	});
});

slidetime = setTimeout("autolistm()",5000); //This starts it all, currently defaulted to 10 seconds.

function autolistm(){
	//alert(cur);
	var v=cur+1;
	if(v==rs_slidenumber){ 
		v=1; 
		max=1;
		$(".listli").fadeOut('1500'); //At the end, so it does not scroll all the way back to slide 1, we hide them, then make em reappear once the sliding is complete.
	}

	$(".listm").css("background","url('images/white_dot.png')");
	$(".listm[place="+v+"]").css("background","url('images/red_dot.png')");
	var offset = cur-v;
	//alert(offset);
	$(".listli").animate({ //Move the items to the left as needed.
		'left':"+="+(offset*960)+"px"
	},(max==1?'10':(Math.abs(offset)*1200)));
	if(max==1) $(".listli").fadeIn('1500');
	max=0;
	cur=v;
	slidetime = setTimeout("autolistm()",5000); //This tells it to wait 10 seconds, then call the next slide.
}
