// Need to come back and rewrite this to use a chain when I learn how

function crossFader(imageArray,imageID,containerID)
{
	this.imageArray = imageArray;
	this.imageIndex = 0;
	this.image = $(imageID);
	this.container = $(containerID);
	this.effect = new Fx.Style(imageID,'opacity' ,{duration:1000});
	this.fadeOut = function(){this.effect.start(1,0);};
	this.switchOn = function(){this.effect.set(1);};
	this.updateImageSrc = function(){ this.image.setAttribute('src', this.imageArray[this.imageIndex]);};
	this.updateImageIndex = function(){this.imageIndex++; this.imageIndex %= this.imageArray.length;};
	this.updateBackground = function(){this.container.style.backgroundImage = 'url(' + this.imageArray[this.imageIndex] + ')';};
	this.locked = 0;
	this.lock = function(){this.locked=1;};
	this.unlock = function(){this.locked=0};
	this.next = function(){
		if (!this.locked)
			{
			this.lock();
			this.updateImageIndex();
			this.updateBackground();
			this.fadeOut();
			this.updateImageSrc.delay(1501,this);
			this.switchOn.delay(1600,this);
			this.unlock.delay(1601,this);
			}
		else {}
		};
	this.start = function (x){this.next.periodical(x,this);};
	};
