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, or the Wrath of Keenan will come down upon you!
// ------------------ //

var ie4=document.all
var dom=document.getElementById
var ie7 = false
var curpos = 4

var curcanvasB = "canvasA"
var curimageindex
var nextimageindex
var isRandom


function ImageRotation(paths, isRandom, width, height)
{	

	var nav = navigator.appVersion;
	if( nav.indexOf("MSIE 7") != -1 )
	{
		ie7=true;
		fadeDuration = 10;
	}
	
	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 setOpacity(obj, opacity) 
{
  opacity = (opacity == 100) ? 99 : opacity;

  // IE/Win
  obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+ opacity + ");";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function Init()
{
	var preloadedimages = new Array()
		
	for (c=0; c<fadeimages.length; c++)
	{
		preloadedimages[c] = new Image()
		preloadedimages[c].src = fadeimages[c]
	}
	
	if (ie7)
	{
		document.write('<div style="position:absolute;width:' + width + '; height:' + height + '; overflow:hidden; z-index:0"><div id="canvasA" style="z-index:0;position:absolute; width:' + width + '; height:' + height + '; top:0; left:0;"></div><div id="canvasB" style="z-index:0; position:absolute; width:' + width + '; height:' + height + '; top:0; left:0; visibility:hidden"></div></div>')
	}
	else if (ie4||dom)
	{
		document.write('<div style="position:absolute;width:' + width + '; height:' + height + '; overflow:hidden; z-index:0"><div id="canvasA" style="z-index:0;position:absolute; width:' + width + '; height:' + height + '; top:0; left:0; filter:alpha(opacity=10); -moz-opacity:10"></div><div id="canvasB" style="z-index:0; 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)
		{
			if(ie7)
			{
				//temp1obj1.style.opacity = curpos
			}
			else
				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" class="icon_png" style="z-index: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)
	
	//setOpacity(crossobj1, 75)
		if (crossobj1.filters)
		{
			if(ie7)
			{
				//crossobj1.style.opacity = curpos
			}
			else
				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()
	
}