/*  rotatingbears_reloadnew.js

Creates an array of objects that contains the ID of an image and an array of images
to be rotated. This script supports an unlimited number of images per object and each
object does NOT need to have the same number of images. On each page reload,the array
will change to a new set of images

Reference this script in the "Close HTML" of the page you wish to use it on.
*/

// declare image sets 
  ar1 = ["BC001.JPG","BC010.JPG","BC016.JPG"];
  ar2 = ["BC031.JPG","BC039.JPG","BC037.JPG"];
  ar3 = ["BC017.JPG","BC023.JPG","BC057.JPG"];
  
  ar4 = ["BC035.JPG","BC022.JPG","BC066.JPG"];
  ar5 = ["BC043.JPG","BC057.JPG","BC045.JPG"];
  ar6 = ["BC042.JPG","BC058.JPG","BC061.JPG"];

var Brown = [ar1,ar2,ar3]; 
var Blonde = [ar4,ar5,ar6]; 
 
// call for randINT  
var tmp = Math.round(Math.random()*(Brown.length - 1));  
var tmp2 = Math.round(Math.random()*(Blonde.length - 1)); 








//time interval for swapping images (in sec.)
var timer = 2;		

//full path to directory with the images in them. Full path /DSN... 
var basedir = "DSN/wwwcapemayteddybearcom/Content/Images/rotatingbears/";


//'true' will randomize the display order of the images, 'false' will display them in order
var randomize = true; 

//'true' will rotate every image at the same time, 'false' does them 1 at a time
var groupswap = false;


//rotator = object array,  Algorithm: new objIMG("imgID",["img1","img2","imgN"]) 

var rotator = new Array(new objIMG("img1",Blonde[tmp]), new objIMG("img2",Brown[tmp2]));
					


			
//Be sure to seperate each item in the object array with a comma (,).



//no need to edit anything below this point
var imgNum = rotator.length
var i = 0;

function rotateIMGs()
{
	try {

		if(groupswap) {
			for(i=0; i<imgNum; i++)
				rotator[i].rotate();
		} else {
			rotator[i].rotate();
			
			if(i == (imgNum - 1)) 
				i = 0;
			else 
				i++;
		}


	} catch(e) { }
}
		

	




function objIMG(id, aryIMG)
{
	this.ID = id;
	this.aryIMG = aryIMG;
	this.curImg = 0;
	this.reset = false;
	this.nextImg = new Image();
	this.showImg = document.getElementById(id);
}

objIMG.prototype.rotate = function()
{
	if(randomize) {
		this.curImg = getRandInt(this.curImg,this.aryIMG);
	} else {
		this.curImg++;
		if(this.reset) this.curImg = 0;
	}
	
	if(document.all) {
		this.showImg.style.filter="blendTrans(duration=1)";
		this.showImg.filters.blendTrans.Apply();
		this.showImg.filters.blendTrans.Play();
	}
	
	if(this.curImg == (this.aryIMG.length - 1)) {  
		this.showImg.src = basedir + this.aryIMG[this.curImg]; 
		this.reset = true;
	} else {
		this.loadNext();
		this.showImg.src = basedir + this.aryIMG[this.curImg];
		this.reset = false;
	}

}

objIMG.prototype.loadNext = function()
{
	if(this.aryIMG.length > 1 && this.curImg > (this.aryIMG.length - 1)) {
		this.nextImg.src = this.aryIMG[this.curImg + 1];
	}
}

function getRandInt(curINT,curARY)
{
	var tmp = Math.round(Math.random()*(curARY.length - 1));
	
	if(tmp != curINT) {
		return tmp;
	} else {
		return getRandInt(curINT,curARY);
	}
}

setInterval("rotateIMGs()",timer*1200);


