var slidecycles="continous" //(ie: "2" / "continous")
var randomorder="no" //"yes" / "no"
var preloadimages="no" //"yes" / "no"
var slidedelay=3000

var ie=document.all
var dom=document.getElementById
var curcycle=0

var ultimateshow=new Array()
var ruta=dom? document.getElementById("ruta").value : document.all.ruta.value
var n=dom? document.getElementById("nimages") : document.all.nimages
var paths=n.value.split(",")
var i=0

//ultimateshow[x]=["path to image", "OPTIONAL link for image", "OPTIONAL link target"]
for (i=0; i <paths.length; i++)
{
	ultimateshow[i]=[ruta+paths[i],'','']
}

if (preloadimages=="yes")
{
	for (i=0;i<ultimateshow.length;i++)
	{
		var cacheimage=new Image()
		cacheimage.src=ultimateshow[i][0]
	}
}

var currentslide=0
var ultimateshowCopy

function randomize(targetarray)
{
	ultimateshowCopy=new Array()
	var the_one
	var z=0
	while (z<targetarray.length)
	{
		the_one=Math.floor(Math.random()*targetarray.length)
		if (targetarray[the_one]!="_selected!")
		{
			ultimateshowCopy[z]=targetarray[the_one]
			targetarray[the_one]="_selected!"
			z++
		}
	}
}

if (randomorder=="yes")
	randomize(ultimateshow)
else
	ultimateshowCopy=ultimateshow

function rotateimages()
{
	curcycle=(currentslide==0)? curcycle+1 : curcycle
	ultcontainer='<center>'
	if (ultimateshowCopy[currentslide][1]!="")
		ultcontainer+='<a href="'+ultimateshowCopy[currentslide][1]+'" target="'+ultimateshowCopy[currentslide][2]+'">'
	ultcontainer+='<img alt="product image" class="product" src="'+ultimateshowCopy[currentslide][0]+'" >'
	if (ultimateshowCopy[currentslide][1]!="")
		ultcontainer+='</a>'
	ultcontainer+='</center>'
	if (ie||dom)
		crossrotateobj.innerHTML=ultcontainer
	if (currentslide==ultimateshow.length-1) 
		currentslide=0
	else 
		currentslide++
	if (curcycle==parseInt(slidecycles) && currentslide==0)
		return
	setTimeout("rotateimages()",slidedelay)
}

if (ie||dom)
	document.write('<div id="product" ></div>')

function start_slider()
{
	crossrotateobj=dom? document.getElementById("product") : document.all.product
	rotateimages()
}

if (ie||dom)
{
	var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = start_slider
  } else {
    window.onload = function() {
      oldonload()
      start_slider()
    }
  }
}
