var transitions = [];// only for IE
transitions.push("progid:DXImageTransform.Microsoft.Fade(duration=1)");
transitions.push("progid:DXImageTransform.Microsoft.Blinds(Duration=1,bands=20)");
transitions.push("progid:DXImageTransform.Microsoft.Checkerboard(Duration=1,squaresX=20,squaresY=20)");
transitions.push("progid:DXImageTransform.Microsoft.Strips(Duration=1,motion=rightdown)");
transitions.push("progid:DXImageTransform.Microsoft.Barn(Duration=1,orientation=vertical)");
transitions.push("progid:DXImageTransform.Microsoft.GradientWipe(duration=1)");
transitions.push("progid:DXImageTransform.Microsoft.Iris(Duration=1,motion=out)");
transitions.push("progid:DXImageTransform.Microsoft.Wheel(Duration=1,spokes=12)");
transitions.push("progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)");
transitions.push("progid:DXImageTransform.Microsoft.RadialWipe(Duration=1,wipeStyle=clock)");
transitions.push("progid:DXImageTransform.Microsoft.RandomBars(Duration=1,orientation=vertical)");
transitions.push("progid:DXImageTransform.Microsoft.Slide(Duration=1,slideStyle=push)");
transitions.push("progid:DXImageTransform.Microsoft.RandomDissolve(Duration=1,orientation=vertical)");
transitions.push("progid:DXImageTransform.Microsoft.Spiral(Duration=1,gridSizeX=40,gridSizeY=40)");
transitions.push("progid:DXImageTransform.Microsoft.Stretch(Duration=1,stretchStyle=push)");

var ImgRotator = Class.create();
ImgRotator.prototype = {
	container:		null,// param[0], img container, required
	imgUrls:		[],
	
	theTimer:		null,
	currImgIdx:		0,
	delayTime:		3500,
	
	initialize: function(con) {
		if(!con || !$(con) || !$(con).tagName || $(con).tagName.toUpperCase() != "IMG") {
			alert("ERROR:[ImgRotator.initialize]\nAn IMG element is required for initializing!");
			return;
		}
		this.container = $(con);
	},
	addImgUrl: function(imgUrl) {
		this.imgUrls.push(imgUrl);
	},
	/**
	 * @private
	 */
	playTransition: function() {
		if(this.currImgIdx < this.imgUrls.length - 1) {
			this.currImgIdx++;
		} else {
			this.currImgIdx = 0;
		}
		if (document.all) {// IE
			this.container.style.filter = transitions[Math.floor(Math.random() * transitions.length)];
			this.container.filters[0].apply();
			this.container.src = this.imgUrls[this.currImgIdx];
			this.container.filters[0].play();
		} else {// mozilla
			this.container.src = this.imgUrls[this.currImgIdx];
		}
		
		this.theTimer = setTimeout(this.playTransition.bind(this), this.delayTime);
	},
	start: function() {
		if(this.imgUrls.length === 0) {
			alert("ERROR:[ImgRotator.start]\nThe imgUrls array is empty, please add imgUrls use function - addImgUrl(imgUrl)");
			return;
		}
		if(!this.theTimer) {
			this.playTransition();
		}
	},
	pause: function() {
		if(this.theTimer) {
			clearTimeout(this.theTimer);
		}
		this.theTimer = null;
	}
};