/** Generated by js.php */
/**
 * Toolbar version 2 (générique). 
 */
 
 var ToolbarEx = Class.create()
 
ToolbarEx.toolbarTemplate = new Template(
 		'<div class="toolbar">'+
 		'<span class="content"></span><span class="help"></span>' +
 		'</div>'
 	);
 
 ToolbarEx.toolbarItemTemplate =  new Template(
 		'<img src="#{SRC}"/>'
 	);
 
 ToolbarEx.prototype = { 
 	initialize: function(id, items) {
 		this._id = id;
 		this._items = items;
 	},
 	
 	createElement: function() {
 		if(!$(this._id)) this._toolbar = undefined;
 		if(this._toolbar) {
 			this._toolbar.remove();
 			return;
 		}
 		
 		if(!this._toolbar) {
 			this._toolbar = document.createElement('DIV');
 			this._toolbar.setAttribute('id', this._id);
 			new Insertion.Top(this._toolbar, ToolbarEx.toolbarTemplate.evaluate());
 		}
 		this._toolbar.hide();
 		
 		var toolbarContent = this._toolbar.getElementsBySelector('.content')[0];
 		var toolbarHelp = this._toolbar.getElementsBySelector('.help')[0];
 		
 		this._items.each(function(el) {
 			new Insertion.Bottom(toolbarContent, 
 				ToolbarEx.toolbarItemTemplate.evaluate({SRC: el.image}));
 				
 			var item = toolbarContent.immediateDescendants().last();
 			
 			item.addClassName('greyed');
 			
 			// Gestion générique de l'ombrage des images
 			Event.observe(item, 'mouseover', function() {
 				item.removeClassName('greyed');
 				toolbarHelp.innerHTML = el.helpText;
 			});
 			
 			Event.observe(item, 'mouseout', function() {
 				item.addClassName('greyed');
 				toolbarHelp.innerHTML = '';
 			});
 			
 			Event.observe(item, 'click', function() {
 				item.addClassName('greyed');
 				toolbarHelp.innerHTML = '';
 			});
 			
 			$H(el.events).each(function(ev) {
 				Event.observe(item, ev.key, ev.value);
 			});
 		});
 	},
 	
 	closePrevious: function() {
 		if(this._toolbar) {
 		try {
 			this._toolbar.remove();
 		} catch(e) {}
 		}
 	},
 	
 	displayIn: function(element) {
 		this.createElement();
 		$(element).appendChild(this._toolbar);
 		this._container = element;
 		this._toolbar.show();
 	},
 	
 	toggleIn: function(element) {
 		if(this._container == element) {
 			this.hide();
 		} else {
 			this.displayIn(element);
 		}
 	},
 	
 	hide: function() {
 		if(this._toolbar) {
 			this._toolbar.hide();
 			this._container = null;
 		}
 	},
 	
 	/**
 	 * Renvoie l'élément dans lequel on
 	 * a demandé l'affichage de la toolbar.
 	 */
 	getContainer: function() {
 		return this._container;
 	},
 	
 	getId: function() {
 		return this._id;
 	}
 };


 

