
var rotate_delay = 3000; // delay in milliseconds (5000 = 5 secs)
var current = 0;
var mainImage; 
var imageList; 
var slidebutton;
var init = true; 
function initSlideShow()
{

 	mainImage = document.getElementById("mainpic");
 	imageList = document.getElementsByName("img");
	slidebutton = document.getElementById("slidebutton");
	init = false;
}
function next() 
{
	if (init == true)
		initSlideShow();
	if (imageList[current+1]) 
	{
		mainImage.src = imageList[current+1].src;
		imageList.selectedIndex = ++current;
   	}
	else first();
}
function previous() 
{
	if (init == true)
		initSlideShow();
	if (current-1 >= 0) 
	{
		mainImage.src  = imageList[current-1].src;
		imageList.selectedIndex = --current;
   	}
	else last();
}

function first() 
{
	if (init == true)
		initSlideShow();
	current = 0;
	mainImage.src  = imageList[0].src;
	imageList.selectedIndex = 0;
}
function last() 
{
	if (init == true)
		initSlideShow();
	current = imageList.length-1;
	mainImage.src  = imageList[current].src;
	imageList.selectedIndex = current;
}
function ap(text) 
{

	if (init == true)
		initSlideShow();	
	debugger;	
	if (text == "STOP")
	
		slidebutton.value = "PLAY"; 
	else
	{
		slidebutton.value = "STOP";
		rotate();
	}

}

function rotate() 
{
	if (slidebutton.value == "PLAY") 
	{
		return;
	}
	mainImage.src = imageList[current].src;
	current = (current == imageList.length-1) ? 0 : current+1;
	imageList.selectedIndex = current;
	window.setTimeout("rotate()", rotate_delay);
   
}