var switchBox = new Class({
	Implements: [Events, Options],
	options: {
		switchBoxContentsId : "#box",
		switchBoxContentsElement : "div",
		switchBoxElementInnerId : "switchBoxElementInnerId",
		switchDelay: 6000,//Delay in changing items	
		switchDelaya: 7000,//Delay in changing items	
		moveLeft: -350,
		out: 5000, //delay to move out
		tweenDuration: 1000
	},
	initialize: function(element, options) {
		this.setOptions(options);
		this.fireEvent('onInit');
		this.boxData;
		this.boxIter = 0;
		this.switchBoxElement = element;		
		this.constructBox();
		this.constructElements();
		this.startSwitcher();
	},
	constructBox: function() {
		var switchBoxElementInner = new Element('div', {id: this.options.switchBoxElementInnerId});
		$(switchBoxElementInner).inject(this.switchBoxElement);
		//$(this.options.switchBoxElementInnerId).set('opacity', '0');
	},
	clearBox: function() {
		$(this.options.switchBoxElementInnerId).empty();
		//$(this.options.switchBoxElementInnerId).set('opacity', '0');
	},
	constructElements: function() {
		$$(this.options.switchBoxContentsId).hide();
		var boxArray = $$(this.options.switchBoxContentsId+' '+this.options.switchBoxContentsElement);
		this.boxData = boxArray;
	},	
	startSwitcher: function() {
		this.fireEvent('onStart');
		this.populateBox();
		this.mover();
		//this.fader();
		this.prepareTimer();
	},
	moveNext: function() {
		this.fireEvent('onNextCalled');
		this.boxIter += 1;
		if(this.boxIter >= this.boxData.length) {
			this.boxIter = 0;
		}
		this.goTo();
	},
	goTo: function() {
		this.clearTimer();
		this.populateBox();
		this.mover();
		//this.fader();
		this.prepareTimer();
	},
	clearTimer: function() {
		$clear(this.timer);
	},
	prepareTimer: function() {
		this.timer = this.moveNext.delay(this.options.switchDelay, this);
	},
	populateBox: function() {
		this.clearBox();
		this.boxData[this.boxIter].clone().inject(this.options.switchBoxElementInnerId);
	},
	mover: function() {
		var boxMove = new Fx.Tween(this.options.switchBoxElementInnerId, {
			property: 'left',
			duration: this.options.tweenDuration,
			transition: Fx.Transitions.Quart.easeInOut
		});
		boxMove.start(this.options.moveLeft,0);
		boxMove.start.pass([0,this.options.moveLeft], boxMove).delay(this.options.out);
	},	
	fader: function() {
		var boxFade = new Fx.Tween(this.options.switchBoxElementInnerId, {
			property: 'opacity',
			duration: this.options.tweenDuration,
			transition: Fx.Transitions.Quart.easeInOut
		});	
		boxFade.start(0,1);
		boxFade.start.pass([1,0], boxFade).delay(this.options.out);
	}
});