var randomSwapper = function() {
	this.initialize.apply(this,arguments);
	
}

randomSwapper.prototype = {
	initialize: function(sArray,transitionTime) {
		// Include required effects from Dojo Toolkit
		dojo.require("dojo.lfx.*");
		// Setup Quotes -- Randomize the array keys and set the timer in seconds for the timeOut.
		this.firstTime = true;
		this.transisted = false;
		this.transTime = '3000';
		this.setupSwapper(sArray,transitionTime);
	},
	setupSwapper: function (sArray,transitionTime) {
		if(sArray.length>0)
		{
			swapArray=sArray.sort(this.randSort);
			this.swapperReady = true;
		}
		else
		{
			this.swapperReady = false;
		}
		this.setupTimer();
		this.transTime=(transitionTime * 1000);
	},
	
	setupTimer: function() {
	    if(this.swapperReady)
		{
			var self = this;
			this.Timer = window.setTimeout(function() { self.randomItem(); },self.transTime);
		}
	},
	
	randSort: function() {
		return (Math.round(Math.random())-0.5);
	},
	
	randomItem: function() {
		if(swapArray.length>0)
		{
			// Assign our DOM nodes to be effected and image path
			this.swapImage = document.getElementById('swapper');
			this.imagePath = 'images/';
			
			// Shift the first element off the array and split's it's string value based off :|: delimeter
			var thisItem = swapArray.shift();
			
			// Attach it back to the end of the array .. now endless looping
			swapArray.push(thisItem);
			
			this.thisItem = thisItem;
			
			// preload this image.
			var preLoaded = new Image();
			preLoaded.src = this.imagePath + this.thisItem;
			
			// Transist the quote with a fade out and in.
			this.transistSwap();
			
		}
		var self = this;
		if(!this.transisted) this.Timer = window.setTimeout(function() { self.randomItem(); },self.transTime);
	
	},
	transistSwap: function() {
		this.transisted = true;
		var self = this;
		var fadeOut = dojo.lfx.fadeOut('swapperWrapper',null,null,function () {
				self.swapImage.src = self.imagePath + self.thisItem;
		});
		var fadeIn = dojo.lfx.fadeIn('swapperWrapper',null,null,function () {
				this.Timer = window.setTimeout(function() { self.randomItem(); },self.transTime);
		});
		dojo.lfx.chain(fadeOut, fadeIn).play();
	}
};