	/**
	* Prototype toolbar
	*
	* @version 1.61
	* @requires wps-namespace 
	* @param container DOMElement the container to append toolbar
	* @author Ivo Toby, Internet Voor Ondernemers (I-V-O), www.i-v-o.nl / blog.i-v-o.nl
	* @copyright I-V-O 2008
	* 
	* 
	*/
	

	wps.toolbar = function(container){
		this.instID = 'wps.toolbar.' + parseInt(Math.random()*1000000);
		this.container = container;
		this.items = new Array();
		this.iItemFuncs = ['init', 'draw'];
		this.drawn = false;
	}
	
	wps.toolbar = wps.toolbar.extendsFrom(wps.base);
	
	wps.toolbar.prototype.add= function(toolbarItem){
		if (this.checkObject(toolbarItem)){
			toolbarItem.pob = this; // set ME as parentObject
			this.items.push(toolbarItem);
		}else{
			alert('Object did not comply to interface!');
			
		}
	} 
	
	wps.toolbar.prototype.get = function(name){
		var res = this.items.find(
			function(item){
				if (item.name == name){
					return item;
				}
			}
		)
		return res;
	}
	
	wps.toolbar.prototype.draw = function(){
		//facade for UI library
		this.drawMenu();
	}
	
	wps.toolbar.prototype.drawMenu = function(){
		if (!this.container.style.display == 'none') {
			this.container.style.display = 'none';
		}
		this.items.each(
			(function(item){
				item.draw(this.container);
			}).bind(this)
		)
		this.drawn = true;
	}
	
	wps.toolbar.prototype.checkObject = function(obj){
		this.iItemFuncs.each(
			(function(func){
				if (!this.is_function(obj[func])){
					return false;
				}
			}).bind(this)
		)
		return true;
	}
	
	wps.toolbar.prototype.show = function(){
		if (!this.drawn) {
			this.draw();
		}
		new Effect.PhaseIn(this.container, {duration:'0.2'});
		Event.observe(document.getElementsByTagName('body').item(0), 'click', this.hide.bind(this));
	}

	wps.toolbar.prototype.hide = function(event){
		try{
			var clicked = Event.element(event);
			var desc = Element.descendants(clicked);
			if (desc.length > 0){
				new Effect.PhaseOut(this.container, {duration:'0.2'} );
				Event.stopObserving(document.getElementsByTagName('body').item(0),'click', this.hide.bind(this)); // add the close event to the custom node
			}
		}catch(e){
			new Effect.PhaseOut(this.container, {duration:'0.2'});
			Event.stopObserving(document.getElementsByTagName('body').item(0),'click', this.hide.bind(this)); // add the close event to the custom node
		}
	}
	
