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

randomQuotes.prototype = {
	initialize: function(qArray,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 = '5000';
		this.setupQuotes(qArray,transitionTime);
	},
	setupQuotes: function (qArray,transitionTime) {
		if(qArray.length>0)
		{
			quotesArray=qArray.sort(this.randSort);
			this.quotesReady = true;
		}
		else
		{
			this.quotesReady = false;
		}
		this.setupTimer();
		this.transTime=(transitionTime * 1000);
	},
	
	setupTimer: function() {
	    if(this.quotesReady)
		{
			var self = this;
			this.Timer = window.setTimeout(function() { self.randomQuote(); },self.transTime);
		}
	},
	
	randSort: function() {
		return (Math.round(Math.random())-0.5);
	},
	
	randomQuote: function() {
		if(quotesArray.length>0 && !this.firstTime)
		{
			// Assign our DOM nodes to be effected and image path
			this.quoteImage = document.getElementById('quoteImage');
			this.quoteText = document.getElementById('quoteText');
			this.imagePath = 'images/clientLogos/';
			
			// Shift the first element off the array and split's it's string value based off :|: delimeter
			var thisQuote = quotesArray.shift();
			
			// Attach it back to the end of the array .. now endless looping
			quotesArray.push(thisQuote);
			
			this.thisQuote = thisQuote.split(":|:");
			
			// preload this image.
			var preLoaded = new Image();
			preLoaded.src = this.imagePath + thisQuote[0];
			
			// Transist the quote with a fade out and in.
			this.transistQuote();
			
		}
		else
		{
			this.firstTime = false;
		}
		var self = this;
		if(!this.transisted) this.Timer = window.setTimeout(function() { self.randomQuote(); },self.transTime);
	
	},
	transistQuote: function(effect) {
		this.transisted = true;
		var self = this;
		var fadeOut = dojo.lfx.fadeOut('qmci-quoteData',null,null,function () {
				self.quoteImage.src = self.imagePath + self.thisQuote[0];
				self.quoteText.innerHTML = self.thisQuote[1];
		});
		var fadeIn = dojo.lfx.fadeIn('qmci-quoteData',null,null,function () {
				this.Timer = window.setTimeout(function() { self.randomQuote(); },self.transTime);
		});
		dojo.lfx.chain(fadeOut, fadeIn).play();
	}
};