var iSum;
if(!iSum) iSum = {};

iSum.imageRotator = function(imgArr,srcImg)
{
	this.interval = 1000;
	this.random_display = 1;
	this.image_index=0;
	if(imgArr)
		this.image_list = imgArr;
	else
		this.image_list = new Array();
	this.number_of_image = this.image_list.length;
	if(typeof srcImg == 'string')
		this.image  = document.getElementById(srcImg);
	else
		this.image=srcImg;
};

iSum.imageRotator.generate = function(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
};
iSum.imageRotator.prototype.getNextImage = function() {
	if (this.random_display) {
		this.image_index = iSum.imageRotator.generate(0, this.number_of_image-1);
	}
	else {
		this.image_index = (this.image_index+1) % this.number_of_image;
	}
	var new_image = this.image_list[this.image_index];
	return(new_image);
};
iSum.imageRotator.prototype.rotateImage = function() {
	var _self = this;
	var new_image = this.getNextImage();
	this.image.src = this.getImageAttributes(new_image,'SRC');
	this.image.alt = this.getImageAttributes(new_image,'URL');
	setTimeout(function(){_self.rotateImage()}, this.interval);
};
iSum.imageRotator.prototype.getImageAttributes = function(arg,retType){
	var myStrArr,myURL;	
	myStrArr = arg.split('&^&');
	myURL = "";
	if(myStrArr.length >= 1){		
		 myURL = myStrArr[1];		 
	}
	if(myURL == "undefined") myURL = "";
	
	if(retType == 'URL')
		return myURL;
	else
		return myStrArr[0];
};
