var thethisholder = new Array();
thethisholder[0] = null;
thethisholder[1] = null;
thethisholder[2] = null;

// The shift() and unshift() methods.

if(!Array.prototype.shift) { // if this method does not exist..

	Array.prototype.shift = function(){
		firstElement = this[0];
		this.reverse();
		this.length = Math.max(this.length-1,0);
		this.reverse();
		return firstElement;
	}
	
}

if(!Array.prototype.unshift) { // if this method does not exist..
	
	Array.prototype.unshift = function(){
		this.reverse();
		
			for(var i=arguments.length-1;i>=0;i--){
				this[this.length]=arguments[i]
			}
			
		this.reverse();
		return this.length
	}
}


function Rotimg(ids)
{
	var handle = ids;
	this.grabhandle = document.getElementById(handle);
	var thsinterval;
	this.op = 0;
	this.speed = 36;
	this.mental = 3;
	this.waitime = 11500;
	this.ind = 0;
	var imgs = new Array;
	var caps = new Array;
	var aSeed = 2 * Math.random() - 1;
	
	
	this.addimg = function(sorce) {imgs.push(sorce)};
	this.addcap = function(sorce) {caps.push(sorce)};
	this.getimg = function() {return imgs.shift()};
	this.getcap = function() {return caps.shift()};
	this.randomtail = function() {var thisonething = fisherYates(imgs,caps);imgs = thisonething[0];caps = thisonething[1]};
}

	Rotimg.prototype.fadeout = function(){ this.thsinterval = setInterval("thethisholder[" + this.ind + "].fadedown()",this.speed)};
	Rotimg.prototype.fadein = function(){  this.thsinterval = setInterval("thethisholder[" + this.ind + "].fadeup()",this.speed)};
	Rotimg.prototype.stoprot = function(){ clearInterval(this.thsinterval)};
	Rotimg.prototype.startin = function(delay,i)
	{
		thethisholder[i] = this;
		this.ind = i;
		setTimeout("thethisholder[" + this.ind + "].rotateit()",delay);
	}
	
	Rotimg.prototype.rotateit = function()
	{
		var spdd = (this.waitime * 2) + 3500;
		setTimeout("thethisholder[" + this.ind + "].fadein()",3500)
		setInterval("thethisholder[" + this.ind + "].fadein()",spdd);
	}
	
	Rotimg.prototype.fadedown = function()
	{
		if(this.op > 0)
		{
			this.op -= this.mental;
			assignop(this.grabhandle.childNodes[2], this.op);
			return;
		}
		else
		{
			clearInterval(this.thsinterval);
			this.addimg(this.grabhandle.childNodes[2].childNodes[0].src);
			this.grabhandle.childNodes[2].childNodes[0].src = this.getimg();
			this.addcap(this.grabhandle.childNodes[2].childNodes[1].firstChild.nodeValue);
			this.grabhandle.childNodes[2].childNodes[1].firstChild.nodeValue = this.getcap();
			return;
		}
	}
	Rotimg.prototype.fadeup = function()
	{
		if(this.op < 99)
		{
			this.op += this.mental;
			assignop(this.grabhandle.childNodes[2], this.op);
			return;
		}
		else
		{
			clearInterval(this.thsinterval);
			this.addimg(this.grabhandle.childNodes[0].src);
			this.grabhandle.childNodes[0].src = this.getimg();
			this.addcap(this.grabhandle.childNodes[1].firstChild.nodeValue);
			this.grabhandle.childNodes[1].firstChild.nodeValue = this.getcap();
			setTimeout("thethisholder[" + this.ind + "].fadeout()",this.waitime)
			return;
		}
	}
	Rotimg.prototype.insert = function(nam)
	{
		var theimg = document.createElement("img");
		var thespan = document.createElement("span");
		var thediv = document.createElement("div");
		
		thediv.className =  "bzi up nomarpad rothold fdimg";
		thespan.className = "imgloc fr";
		thespan.appendChild(document.createTextNode(this.getcap()))
		theimg.setAttribute('alt',"Images from our "+nam+" Plants");
		theimg.setAttribute('src',this.getimg());
		theimg.className = "bzi";
		thediv.appendChild(theimg);
		thediv.appendChild(thespan);
		if(document.all)
		{
			thediv.style.marginBottom = "-195px";
		}
		
		if(this.grabhandle.childNodes[2])
		{
			this.grabhandle.insertBefore(thediv,this.grabhandle.childNodes[2]);
		}
		else
		{
			this.grabhandle.appendChild(thediv);
		}
	}
	

	function assignop(grab,op)
	{
		if("filters" in grab && typeof grab.filters.alpha.opacity == "number")
		{
		    	grab.filters[0].opacity = op;
		}
		else
		{
    		    	grab.style.opacity = op/100;
    		    	grab.style.MozOpacity = op/100;
			grab.style.KhtmlOpacity = op/100;
		}
	}

function fisherYates ( myArray,myArraytwo) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
     var ttempi = myArraytwo[i];
     var ttempj = myArraytwo[j];
     myArraytwo[i] = ttempj;
     myArraytwo[j] = ttempi;
   }
   arrlisters = new Array();
   arrlisters[0] = myArray;
   arrlisters[1] = myArraytwo;
   return arrlisters;
}