
ImageRotator = function(config) {
	if(!config.id) {
		return null;
	}
	this.imgId = config.id;
	this.imgNames = config.images || [];
	this.imgs = [];
	this.imgDelay = config.delay || 4500;
	this.imgPath = config.path || '/';
	this.imgIndex = 0;
	this.addImages();
}
ImageRotator.prototype.rotate = function() {
	if(this.imgIndex == this.imgs.length - 1) {
		this.imgIndex = 0;
	}
	else {
		this.imgIndex++;
	}
	document.getElementById(this.imgId).src = this.imgs[this.imgIndex].src;
	startRotation(this);
}

ImageRotator.prototype.addImages = function() {
    var img;
    for (var i=0; this.imgNames[i]; i++) {
        img = new Image();
        img.src = this.imgPath + this.imgNames[i];
        this.imgs[i] = img;
    }
}

function startRotation(imgRotator) {
	setTimeout(function () { imgRotator.rotate(); }, imgRotator.imgDelay);
}
