var Slide = Class.create();
Object.extend(
	Object.extend(Slide.prototype, Abstract.prototype),{
		initialize: function(target, options) {
			
			this.wrapper    = $('container');
			this.slide 		= $(target);
			this.options    = Object.extend( {transition: Effect.Transitions.linear, duration: 0.5, onlyUp:false}, options || {});
			
			this.link 		= $(this.options.link) || false;
			this.trigger	= this.options.trigger || false;
			this.checkEnter = this.options.checkEnter || false;
			this.close		= this.options.close || false;
			this.up 		= this.slide.visible() ? false : true;
			
			this.events = {
				click: this.click.bind(this),
				close: this.closeclick.bind(this)
			}
			
			this.addObservers();

		},
		addObservers: function() {
			var control = this.wrapper.getElementsBySelector(this.trigger);
		    control.invoke('observe', 'click', this.events.click);
			if(this.close){
				var close = this.wrapper.getElementsBySelector(this.close)
				close.invoke('observe', 'click', this.events.close);
			}
		},
		click: function(event) {

		    if (this.sliding) this.sliding.cancel();
		    
		    this.slideEffect(this.slide, this.options);
		    Event.stop(event);
		},
		change: function() {
		    if (this.sliding) this.sliding.cancel();
			this.options.onlyDown = true;
		    this.slideEffect(this.slide, this.options);
			this.options.onlyDown = false;
		    Event.stop(event);
		},
		closeclick: function(callback){
			if (this.sliding) this.sliding.cancel();
			this.options.onlyUp = true;
			this.slideEffect(this.slide, Object.extend({callback:callback},this.options));
			this.options.onlyUp = false;
		},
		slideEffect: function(container, options){
			if(this.up && !options.onlyUp){
				this.up = false;
				this.sliding = new Effect.SlideDown(container, {duration:options.duration,transition: options.transition});
			}else if(!this.up && !options.onlyDown){
				this.up = true;
				this.sliding = new Effect.SlideUp(container, {duration:options.duration,transition: options.transition, afterFinish:options.callback});
			}
			return false;
		}
	}
);

