dsgn = {};
dsgn.Filter = null;


/**
 * The DSNG.Filter is used to create search and filters for Article retrievement
 */
dsgn.FilterObject = new Class({
	
	/**
	 * Options Object
	 *
	 * @type {Object}
	 */
	options: {
		openOnStartup:	false,
		openString:		'Open Filter',
		closeString:	'Close Filter',
		openDuration:	900,
		closeDuration:	300,
		minimalHeight:	10
	},
	
	/**
	 * The filters controller knob
	 *
	 * @type {Object}
	 */
	filterKnob: null,

	/**
	 * The filters container
	 *
	 * @type {Object}
	 */
	filterContainer: null,
	
	/**
	 * The current FX if a FX is currently used
	 *
	 * @type {FX.Style}
	 */
	currentAcion: null,

	/**
	 * Array containing the Filters keys
	 * 
	 * @type {Array}
	 */
	keys: null,

	/**
	 * @constructor
	 * @param {Array} keys
	 * @param {Object} options
	 */
	initialize: function(knob, container, options) {
		
		//Options
		this.setOptions(options);
		
		//Filter objects
		this.filterKnob = knob;
		this.filterContainer = container;

		//Appearance
		this.initAppearance();
		
	},
	
	/**
	 * Setup the appearance of the filter
	 */
	initAppearance: function() {
		
		//Set css properties
		$(this.filterContainer).setStyle('overflow', 'hidden');
		$(this.filterKnob).setStyle('cursor', 'pointer');
		
		//Set initial state
		if(this.options.openOnStartup === true) {
		
			this.setKnobText(this.options.closeString);
		
		} else {
					
			this.setKnobText(this.options.openString);
			this.collapse();
			$(this.filterKnob).onclick = this.open.bindAsEventListener(this);
			
		}
		
	},
	
	/**
	 * Set the knob text
	 *
	 * @param {String} text
	 */
	setKnobText: function(text) {
		
		this.filterKnob.setText(text);
		
	},
	
	/**
	 * Collapse the filter to its closed state without animation 
	 */
	collapse: function() {

		$(this.filterContainer).setStyle('height', 1);
	
	},

	/**
	 * Expand the filter to its open state without animation 
	 */	
	expand: function() {
	
	},

	/**
	 * Opens the filter
	 */
	open: function() {

		if(this.currentAcion !== null) {
			
			this.currentAcion.stop();
			this.currentAcion = null;
			
		}
	
		//Create action
		var dimension = $(this.filterContainer).getSize();
		
		this.currentAcion = new Fx.Style($(this.filterContainer), 'height', {duration: this.options.openDuration});
		
		
		//Set new behaviour
		$(this.filterKnob).onclick = this.close.bindAsEventListener(this);
		
		//Preform action
		this.setKnobText(this.options.closeString);
		this.currentAcion.start(dimension.size.y, dimension.scrollSize.y);
		
	},
	
	
	/**
	 * Closes the filter
	 */
	close: function() {
	
	
		if(this.currentAcion !== null) {
			
			this.currentAcion.stop();
			this.currentAcion = null;
			
		}
	
		//Create action
		var dimension = $(this.filterContainer).getSize();
		
		this.currentAcion = new Fx.Style($(this.filterContainer), 'height', {duration: this.options.closeDuration});
		
		
		//Set new behaviour
		$(this.filterKnob).onclick = this.open.bindAsEventListener(this);
		
		//Preform action
		this.setKnobText(this.options.openString);
		this.currentAcion.start(dimension.size.y, 1);
	
	},
	
	/**
	 * Toggles the open/close state of the filter
	 */
	toggle: function() {
	
	},
	
	/**
	 * Indicates if the filer is currenly open
	 * 
	 * @return {boolean}
	 */
	isOpen: function() {
	
	},

	/**
	 * Setter method for the keys array
	 *
	 * @param {Array} keys
	 */
	setKeys: function(keys) {
		 this.keys = keys;
	},

	/**
	 * Getter method for the keys array
	 *
	 * @return {Array}
	 */
	getKeys: function() {

	},

	/**
	 * Adds a key to the keys array
	 *
	 * @param {String} key
	 */
	addKey: function(key) {
		 this.keys.push(key);
	},

	/**
	 * Removes key from the keys array
	 *
	 * @param {String} key
	 */
	removeKey: function(key) {
	
	},

	/**
	 * Removes the at givin index
	 *
	 * @param {Number} index
	 */
	removeKeyAtIndex: function(index) {

	}
	
});
dsgn.FilterObject.implement(new Options);


dsgn.initFilter = function(knob, container) {
	
	dsgn.Filter = new dsgn.FilterObject(knob, container);
	
}


//EOS.addToInitStack(dsgn.initFilter);

/*
var FILTER_OPEN_STRING		= 'Open Filer';
var FILTER_CLOSE_STRING		= 'Close Filter';
var FILTER_SLIDER_DURATION	= 600;
var FILTER_SLIDER			= null;


function sliderInit(knob, container) {
	knob = $(knob);
	container = $(container);
	
	if ($chk(knob)) {
		FILTER_SLIDER = new Fx.Slide(container, {FILTER_SLIDER_DURATION: 600}).hide();
		knob.removeProperty("href");
		knob.setStyle('cursor', 'pointer');
		knob.addEvent("click", function(event) {
			 if (container.getStyle('margin-top') == '0px') {
				 knob.setText(FILTER_OPEN_STRING);
			 }
			 else {
				 knob.setText(FILTER_CLOSE_STRING);
			 };
			 FILTER_SLIDER.toggle();
		});
	};
};

Window.onDomReady(function() {sliderInit('sliderknob', 'slidercontainer')});
*/