var SliderSwap = Class.create();
Object.extend(Object.extend(SliderSwap.prototype, AC.ContentSwap.prototype), {
	width: null,
	isAnimating: false,

	initialize: function(selectorClass, contentClass, eventStr, width) {
	
		this.eventStr = eventStr;
		this.width = width;
		
		// get lists of selectors and content in order
		this.selectorList = document.getElementsByClassName(selectorClass);
		this.contentList = document.getElementsByClassName(contentClass);
		
		this.setMouseover();
	},

	setMouseover: function() {
		for(var i=0; i<this.selectorList.length; i++) {
			var selector = this.selectorList[i];
			var direction = (Element.hasClassName(selector, 'left')) ? 1 : -1; // 1 is left, -1 is right
			Event.observe(selector, this.eventStr, this.swapContent.bind(this, selector, direction), false);
		}
	},
	
	swapContent: function(selector, direction) {
		if (this.isAnimating == false) {
			// set the flag
			this.isAnimating = true;
			
			// swap the 'on' class from the selectors
			for (var i=0; i<this.selectorList.length; i++) {
				if (this.selectorList[i]==selector) {
					if (Element.hasClassName(this.selectorList[i], 'active')) Element.removeClassName(this.selectorList[i], 'active');
				} else {
					if (!Element.hasClassName(this.selectorList[i], 'active')) Element.addClassName(this.selectorList[i], 'active');
				}
			}
		
			// do the swap
			var moveBy = direction*this.width;

			var mondoEffect = [];
			for (var i=0; i<this.contentList.length; i++) {
				var content = this.contentList[i];
				var effect = new Effect.MoveBy(content, 0, moveBy, { sync:true });
				mondoEffect.push(effect);
			}
			
			new Effect.Parallel(mondoEffect, {
				duration:.5,
				queue:{ position:'end', scope:'cs1' },
				afterFinish:this.resetFlag.bind(this,'isAnimating')
			});
		}
		
		return false;
	},

	resetFlag: function(flagName) {
		if (flagName == 'isAnimating') this.isAnimating = false;
	}
});
