//add table row for image so that caption does not move

////////////////////////////////////////////////////////
// slideshow
// example implementation
//
//var testShow = new Appa_Slideshow('images','testShow');
//testShow.addSlide('images/FMhero.jpg','166','165','FMhero');
//testShow.addSlide('images/FMleftangle.jpg','166','165','FMleftangle');
//testShow.addSlide('images/FMleftreflection.jpg','171','142','FMleftreflection');
//testShow.start();
//
///////////////////////////////////////////////////////

//create slideshow object
function Appa_Slideshow(imagePath,SlideshowName,height,width)
{
	this.name = SlideshowName;
	this.slides = new Array();
	this.index = 0;
	this.imagePath = imagePath;
	this.width = width;
	this.height = height;
	this.leftArrow = new Arrow('left',this.imagePath + '/' + 'leftarrow.gif',this.imagePath + '/' + 'leftarrow.gif','11','9');
	this.rightArrow = new Arrow('right',this.imagePath + '/' + 'rightarrow.gif',this.imagePath + '/' + 'rightarrow.gif','11','9');
	this.addSlide = addSlide;
	this.next = nextSlide;
	this.previous = previousSlide;
	this.start = writeSlides;
}

// write out layers
function writeSlides()
{
	slideCount = this.slides.length;
	for (var i = 0; i < slideCount; i++)
	{
		if (i == 0)
		{
			vis = 'visible';
		} else
		{
			vis = 'hidden';
		}
		document.write('<div id="' + i + '" style="position:absolute;   width:' + this.width + 'px; height:' + this.height + 'px; visibility: ' + vis + ';" align = "center">  ' + '\n'); 
		//document.write('<img src="' + this.slides[i].slide + '" width="' + this.slides[i].width + '" height="' + this.slides[i].height + '">  ' + '\n');
		//document.write('<br \/><br \/>'  + '\n');
		document.write('<table width="' + this.width + '" border="0" cellspacing="0" cellpadding="0">' + '\n');
		document.write('<tr>'  + '\n');
		document.write('<td colspan="3" height = "' + (this.height - 50) + '" align = "center" valign = "top"><img src="' + this.slides[i].slide + '" width="' + this.slides[i].width + '" height="' + this.slides[i].height + '"><\/td>'  + '\n');
		document.write('<\/tr>'  + '\n');
		document.write('<tr>'  + '\n');
		document.write('<td width="10" class = "layoutDataSS" height ="26" valign = "center"><img src="' + this.imagePath + '/' + 'leftarrow.gif" width="9" height="11" align="absmiddle" onClick = "' + this.name + '.previous()"><\/td>'  + '\n');
		document.write('<td width="190" align="center" class = "layoutDataSS" height ="18" valign = "center"><span class = "default">' + this.slides[i].captionTxt + '</span><\/td>'  + '\n');
		document.write('<td width="10" class = "layoutDataSS" height ="26" valign = "center"><img src="' + this.imagePath + '/' + 'rightarrow.gif" width="9" height="11" align="absmiddle" onClick = "' + this.name + '.next()"><\/td>'  + '\n');
		document.write('<\/tr>'  + '\n');
		document.write('<\/table>'  + '\n');
		document.write('<\/div>'  + '\n');
	}
}

// create arrow object
function Arrow(name,imageOutPath,imageOverPath,image_Height,image_Width)
{
	this.name = name;
	this.arrow = new Image(image_Height, image_Width);
	this.arrow.src = imageOutPath;
	this.arrowOver = new Image(image_Height, image_Width);
	this.arrowOver.src = imageOverPath;
	this.arrowSwapOver = arrowOver;
	this.arrowSwapOut = arrowOut;
	
}

// arrow object method
function arrowOver()
{
		this.arrow.src = this.arrowOver.src;
}

// arrow object method
function arrowOut()
{
		this.arrow.src = this.arrow.src;
}

// slideshow object method
function addSlide(imagePath,image_Height,image_Width,imageCaption)
{
	this.slides[this.slides.length] = new Slide(imagePath,image_Height,image_Width,imageCaption);
}

// create Slide object
function Slide(imagePath,image_Height,image_Width,imageCaption)
{
	this.height = image_Height;
	this.width = image_Width;
	this.slide = imagePath;
	this.captionTxt = imageCaption;
}

// slideshow object method
function nextSlide()
{
	//hide current
	toggleBox(this.index, 0);
	theCount = this.slides.length;
	if (this.index < (theCount - 1))
	{
		this.index++
	} else
	{
		this.index = 0;
	}
	toggleBox(this.index, 1);
}

// slideshow object method
function previousSlide()
{
	//hide current
	toggleBox(this.index, 0);
	theCount = this.slides.length;
	if (this.index == 0)
	{
		this.index = theCount - 1;
	} else
	{
		this.index--;
	}
	toggleBox(this.index, 1);
}

// show/hide layers
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
