var TransitionTester = Class.create();
TransitionTester.prototype = {
	initialize: function(element,options) {
		this.el = $(element);
		var chldn = $A($(element).getElementsByTagName('div'));
		this.elHeader = chldn[0];
		this.elBody = chldn[1];
		this.resetNow();
		this.options = Object.extend({
			Appear:{duration: 1, beforeStart: this.hideBox.bind(this)},
			Fade:{},
			Puff:{duration:1.5},
			BlindDown:{duration: 2, beforeStart: this.hideBox.bind(this)},
			BlindUp:{duration: 1},
			SwitchOff:{duration:4},
			SlideDown:{},
			SlideUp:{},
			DropOut:{duration:2},
			Shake:{duration:4},
			Pulsate:{},
			Squish:{},
			Fold:{},
			Highlight:{startcolor: '#f1f1f1', endcolor: '#9999ff'}		
		},options);
		this.savedCombos = [];
		this.transition = 'Elastic';
		this.effect = 'BlindDown';
	},
	showBox: function() {
		Element.show(this.el);
		this.running = false;
	},
	hideBox: function() {
		Element.hide(this.el);
		this.running = false;
	},
	resetDelayed: function() {
		this.timeout = setTimeout(this.resetNow.bind(this),3000);
	},
	resetNow: function() {
		//Element.setStyle(this.elHeader,{'background-color': '#4E4EFF', color:'#f1f1f1', padding:'4px', 'font-size':'1.3em', 'text-align': 'center'});
		//Element.setStyle(this.elBody,{'font-weight': 'normal', 'font-size': '1.2em', padding: '4px 8px', color: '#333333'});
		try { this.effectHandle.cancel(); } catch(e) {}
		try { clearTimeout(this.timeout); } catch(e) {}
		this.running = false;
	},
	beginEffect: function() {
		if( this.running ) {
			this.effectHandle.cancel();
			this.resetNow();
		}
		switch( this.effect ) {
			case 'Scale200':	
				this.effectHandle = new Effect.Scale(this.el,200,{
					transition:Effect.Transitions[this.transition],
					duration: 1,
					fps: 25,
					scaleContent: true,
					scaleFromCenter: true,
					afterFinish: this.resetDelayed.bind(this)
				});
				break;
			case 'Scale50':
				this.effectHandle = new Effect.Scale(this.el,50,{
					transition:Effect.Transitions[this.transition],
					duration: 1,
					fps: 25,
					scaleContent: true,
					scaleFromCenter: true,
					afterFinish: this.resetDelayed.bind(this)
				});			
				break;
			default:
				this.effectHandle = new Effect[this.effect](this.el,Object.extend(
					{
						transition:Effect.Transitions[this.transition],
						duration: 3,
						fps: 25,
						afterFinish: this.resetDelayed.bind(this)
					},
					this.options[this.effect])
				);
				break;
		}
		this.running = true;
	},
	beginCombo: function(trans,eff) {
		//this.transition	= Effect.Transitions[trans] ? trans : this.transition;
		//this.effect = Effect[eff] ? eff : this.effect;
		this.transition = trans;
		this.effect = eff;
		this.beginEffect();
	},
	saveCombo: function(transitionSpaceEffect,cookieName) {
		this.savedCombos.push(transitionSpaceEffect);
		Cookie.set(cookieName,this.savedCombos.inspect(),90);
	},
	createCombo: function(startAt,parentNode,varName) {
		var parentNode = $(parentNode);
		var i = startAt;
		var tmp, trans, effect;
		while( i < this.savedCombos.length )
		{
			tmp = this.savedCombos[i].split(' ');
			trans = tmp[0];
			effect = tmp[1];
			parentNode.appendChild(Builder.node('input',{type:'button',className:'btn-custom',onclick:varName+".beginCombo('"+trans+"','"+effect+"')",value:trans+' '+effect}));
			parentNode.appendChild(Builder.node('br'));
			i++;
		}		
	}
	
}