var width //image width
var height //image height
var seconds = 5 //number of seconds before next image
var pause = seconds * 1000
var fadeDuration = 50 //time for image to fade in

var fadeimages = new Array()

// ------------------ //
// Do not change anything below this line!
// ------------------ //

var ie4=document.all
var dom=document.getElementById
var curpos = 4

var curcanvasB = "canvasA"
var curimageindex
var nextimageindex
var isRandom

function ImageRotation(paths, isRandom, width, height)
{	
	fadeimages = paths.split(',')
	
	this.isRandom = isRandom
	this.width= width + 'px'
	this.height= height + 'px'
	
	if(isRandom)
	{
		curimageindex = Math.floor(Math.random()*fadeimages.length)
		nextimageindex = Math.floor(Math.random()*fadeimages.length)
	}
	else
	{
		curimageindex = 0
		nextimageindex = 1
	}
	Init()
}

function Init()
{
	var preloadedimages = new Array()
	
	for (c=0; c<fadeimages.length; c++)
	{
		preloadedimages[c] = new Image()
		preloadedimages[c].src = fadeimages[c]
	}
	
	if (ie4||dom)
	{
		document.write('<div style="position:relative;width:' + width + '; height:' + height + '; overflow:hidden;background-color:white;"><div id="canvasA" style="position:absolute; width:' + width + '; height:' + height + '; top:0; left:0; filter:alpha(opacity=10); -moz-opacity:10"></div><div id="canvasB" style="position:absolute; width:' + width + '; height:' + height + '; top:0; left:0; filter:alpha(opacity=10); -moz-opacity:10; visibility:hidden"></div></div>')
	}
	else
	{
		document.write('<img name="defaultslide" src="'  + fadeimages[Math.floor(Math.random()*fadeimages.length-1)] + '">')
	}
	
	if (ie4||dom)
		window.onload=startit
	else
		setInterval("rotateimage()",pause)
}

/*
this method produces the fading effect of the image.
the curpos variable is set to the opacity level of the fading.
*/
function fadepic()
{
	if (curpos < 100)
	{
		curpos += 4
		if (temp1obj1.filters)
			temp1obj1.filters.alpha.opacity = curpos
		else if (temp1obj1.style.MozOpacity)
			temp1obj1.style.MozOpacity = curpos/101
	}
	else
	{
		clearInterval(dropslide)
		nextcanvas1 = (curcanvasB == "canvasA")? "canvasA" : "canvasB"
		temp1obj1=ie4? eval("document.all." + nextcanvas1) : document.getElementById(nextcanvas1)
		temp1obj1.innerHTML = insertimage(nextimageindex)

		curimageindex = nextimageindex
		
		if(isRandom)
		{
			while(nextimageindex==curimageindex)
				nextimageindex = (curimageindex<fadeimages.length-1) ? Math.floor(Math.random()*fadeimages.length) : 0
		}
		else
			nextimageindex = (curimageindex<fadeimages.length-1) ? curimageindex+1 : 0
		
		var temp1obj12=ie4? eval("document.all." + nextcanvas1) : document.getElementById(nextcanvas1)
		temp1obj12.style.visibility = "hidden"
		
		setTimeout("rotateimage()",pause)
	}
}

function insertimage(i)
{
	var temp1container1 = fadeimages[i] != ""? '<img src="'+fadeimages[i]+'" border="0">' : ""
	return temp1container1
}

function rotateimage()
{
	if (ie4||dom)
	{
		resetit(curcanvasB)
		var crossobj1 = temp1obj1=ie4? eval("document.all." + curcanvasB) : document.getElementById(curcanvasB)
		crossobj1.style.zIndex++
		temp1obj1.style.visibility = "visible"
		var temp1 = 'setInterval("fadepic()",' + fadeDuration + ')'
		dropslide = eval(temp1)
		curcanvasB = (curcanvasB == "canvasA")? "canvasB" : "canvasA"
	}
	else
	{
		document.images.defaultslide.src = fadeimages[curimageindex]
	}
}

function resetit(what)
{
	curpos = 4
	var crossobj1=ie4? eval("document.all." + what) : document.getElementById(what)
		if (crossobj1.filters)
			crossobj1.filters.alpha.opacity = curpos
		else if (crossobj1.style.MozOpacity)
			crossobj1.style.MozOpacity = curpos/101
}

function startit()
{
	var crossobj=ie4? eval("document.all." + curcanvasB) : document.getElementById(curcanvasB)
	crossobj.innerHTML = insertimage(curimageindex)
	rotateimage()
}