var SliderCollection = Class.create();

SliderCollection.prototype = {

    initialize: function(sliderCollectionName, sliderClassName, controlClassName, slidingDuration) {
    
        this.sliderCollectionName = sliderCollectionName;
        this.sliderCollectionElement = $(sliderCollectionName);
        
        this.sliderClassName = sliderClassName;
        this.controlClassName = controlClassName;
        
        this.slidingDuration = slidingDuration;
        
        this.sliderList = new Array();
        
        var sliderElementList = this.sliderCollectionElement.getElementsByClassName(sliderClassName);
        for (var i = 0; i < sliderElementList.length; i++) {
			var sliderElement = sliderElementList[i];
			var controlElement = sliderElement.parentNode.getElementsByClassName(controlClassName)[0];
			this.sliderList[i] = new Slider(sliderElement, controlElement, this.slidingDuration);
			controlElement.onclick = this.changeSliderState.bindAsEventListener(this);	
				
        }
    },
    
    changeSliderState: function(event) {
		
		var handlingControl = Event.element(event);
		if (handlingControl.className.indexOf(this.controlClassName) < 0) {
			handlingControl = handlingControl.up('.' + this.controlClassName);
		}

        if (handlingControl != null && !Object.isUndefined(handlingControl)) {
			handlingControl.slider.changeState();
		}
	}
}

var Slider = Class.create();
Slider.prototype = {
    
    initialize: function(sliderElement, controlElement, slidingDuration) {
		this.slidingDuration = slidingDuration;
		
        this.sliderElement = sliderElement;
        if (sliderElement != null) {
            sliderElement.slider = this;
        }
        this.controlElement = controlElement;
        if (controlElement != null) {
            controlElement.slider = this;
        }
        this.isOpened =  true;
    },
    
    changeState: function(){
        if (this.isOpened)
        {
            this.Close();
        }
        else
        {
            this.Open();
        }
    },
    
    Open: function() {
        Effect.BlindDown(this.sliderElement, {duration: this.slidingDuration, scaleContent: false, queue: 'end'});
        this.isOpened = true;
    },
    
    Close: function() {
        Effect.BlindUp(this.sliderElement, {duration: this.slidingDuration, scaleContent: false, queue: 'end'});
        this.isOpened = false;
    }
    
}

