
function SlideShow() { 
// uses array number of slide <li> attribute
var nextSlide = 1;
var showStopped = false;
var interval=0;
	
	imageArray=$('.ebook-video-list').find('li');
	imageArray.css({"position":"absolute","top":"0px"});
	$imgWidth=imageArray.width();
	$imgHeight=imageArray.height();
	$('.ebook-video-list').width($imgWidth);

	// Set up buttons - one for each slide
	$i=0;var c=["eb8c00","dc6900","e0301e","db536a","a32020","602320","968c6d","6d6e71"];
	$appendString='<div class="buttons"><ul>';
	$.each(imageArray,function(a,b){$appendString+='<li style="display:block; list-style:none;float:left;width:10px;margin:0;margin-right:3px;padding:8px;background-color:#'+ c[a%8] +';color:white;font-weight:bold;font-family:Georgia;opacity:0.5;filter:alpha(opacity=50)" rel="'+a+'"><em>'+(a+1)+'</em></li>'});
	$appendString+='<li id="stopgo" style="display:block;list-style:none;float:left;margin:0;margin-left:3px;padding:8px;background-color:#FF0000;color:white;font-weight:bold;font-family:Georgia;font-size:1em;"><em>||</em></li>';
	$appendString+='</ul></div>';
	$('.ebook-video-list').parent().append($appendString);

	// render 1st slide
	$('.buttons li').eq(0).animate({'opacity':1},"fast").addClass('actbut');
	$(imageArray).eq(0).find('div').animate({'opacity':1},"slow"); //fade in text on 1st slide
	$(imageArray).eq(0).css({'left':'0px'}); // set att for IE

	// mouseover
	$('.buttons > ul > li').mouseover(function(){
		$(this).css({'cursor':'pointer'}); //set border in stylesheet
	});
	// mouseout
	$('.buttons > ul > li').mouseout(function(){
		$(this).css({'cursor':'auto'}); //set border in stylesheet
	});

	// activate the buttons
	$('.buttons ul li').not('#stopgo').click(function(){
	//move to relevant slide, test is to prevent error when user clicking button before slide fully loaded
		if(($(imageArray).eq(0).css("left").substring(0,$(imageArray).eq(0).css("left").length-2)% -$imgWidth)==0){
			if($(this).css('opacity')!=1){	
			stopShow();			
			slideLeft($(this).attr('rel'), "stop");
		}}
	});

	//activate the pause/resume button
	$("#stopgo").click(function(){
	// if show stopped, then start rotating again, else stop rotation.
	if(($(imageArray).eq(0).css("left").substring(0,$(imageArray).eq(0).css("left").length-2)% -$imgWidth)==0){
		if (showStopped) {
			$("#stopgo").text("||");
			$("#stopgo").css({'background-color':'#FF0000'});
			$("#stopgo").removeClass('actbut');
			showStopped = false;	
			slideLeft(nextSlide, "go");
		}
			else {stopShow();}
		}
	});

	//start the slideshow
	interval = setTimeout(function(){slideLeft('1')},24000); //first time go to 2nd slide in array

	// ** the main functionality ** //
	function slideLeft(a,cont){
		var continueLoop = (cont==null) ? "" : cont;			
		$('.buttons li').not('#stopgo').animate({'opacity':0.5},"fast").removeClass('actbut').filter(':eq('+a+')').animate({'opacity':1},"fast").addClass('actbut'); //hightlight active button & fade others
		$(imageArray).find('div').animate({'opacity':0},"fast");  //fade out text on slides - prevents wobble problem in IE
		$(imageArray).eq(a).css({"left":$imgWidth}); //position selected slide ready to display
		$(imageArray).eq(a).css({"display":"block"}); //unhide selected slide for 1st rotate
		$(imageArray).animate({"left":'-='+$imgWidth},1000); //move all sides to the left, selected will now appear
		$(imageArray).eq(a).find('div').delay(1000).animate({'opacity':1},"slow"); //fade in top text  
  
		if(a==imageArray.length-1){a=0}else{a++}clearTimeout(interval);
		nextSlide = a; //save in case of resume
		if (continueLoop != "stop"){
			interval=window.setTimeout(function(){slideLeft(a)},24000) //loop again
		}	
	}
	
	function stopShow(){
		// stop the rotation - called from various button events
		$("#stopgo").css({'background-color':'#B5CC7A'});
		$("#stopgo").animate({'opacity':1},"fast").addClass('actbut');	
		$("#stopgo").text(">");		
		clearTimeout(interval);
		showStopped = true;	
	}
	
} // end SlideShow

$(document).ready(function(){
//	setTimeout(SlideShow,500);
	SlideShow();
});
