/*
 * Javascript Functions for conair.com
 * Mootools functions. Requires the Mootools Javascript Framework (www.mootools.net)
 * @Author Tony Collings
 * @Copyright Conair Corporation
 * @Date July 2009
 * @Version 1.0
 *
 */

// Simple Javascript object based class to switch images
var Twinkle = {
	init: function(arrImages,options){
		this.arrFadeElements = arrImages; 
		this.iInterval = options.interval;
		this.iIntervalID = null;
		this.oFadeFX = null;
		this.iCurrent = 0;
		this.iNext = null;
		// Call anonymous function (changeImg) to pass 'this'. See "The 'this' Binding Problem" : https://developer.mozilla.org/en/DOM/window.setInterval
		this.intervalID = setInterval(function(){Twinkle.changeImg()},this.iInterval);
	},
	changeImg: function(){
		this.iCurrent = (this.iCurrent > (this.arrFadeElements.length)-1)?0:this.iCurrent;
		this.iNext = (this.iCurrent+1 > (this.arrFadeElements.length)-1)?0:this.iCurrent+1;
		Twinkle.fadeOut(this.arrFadeElements[this.iCurrent]);
		Twinkle.fadeIn(this.arrFadeElements[this.iNext]);
		this.iCurrent++;
	},
	fadeOut: function (oElement)
	{
		this.oFadeFX = new Fx.Tween(oElement, {property: 'opacity', duration: 0}).start(1,0);
	},
	fadeIn: function (oElement)
	{
		this.oFadeFX = new Fx.Tween(oElement,  {property: 'opacity', duration: 0}).start(0,1);
	}

	
};
			

