var w = {
	_init: function (options) {
		$.extend(this.options, options);
		this.id = this.element.attr('id');
		this.element
			.addClass('ui-widget-header')
//			.addClass('ui-corner-all')
			.addClass('button_div')
			;
		this.element.html('<div class="button_div_icon_outer"><div class="button_div_icon_inner ui-icon '+this.options['icon']+'"></div></div>');
		this.pane = $('<div> </div>').appendTo(this.element);
	},
	id: null,
	pane: null,
	options: {
		'icon': 'ui-icon-triangle-1-s'
	},
	add: function(button_id, params) {
		//alert('Добавляем '+button_id);
		var button = this.pane.find('input[button_id='+button_id+']');
		var hint;
		var title;
		var icon = '';
		
		if (button.length == 0) {
			if (params['hint'] == null) {
				hint = '';
			} else {
				hint = params['hint'];
			}
			if (params['title'] == null) {
				title = '';
			} else {
				title = params['title'];
			}
			if (params['icon_class'] != null) {
				icon = '<div class="button_div_icon_inner ui-icon '+params['icon_class']+'"></div>';
			}
			button = $('<div class="doc_button ui-button ui-state-default ui-corner-all" button_id="'+button_id+'" title="'+hint+'">'+icon+' '+title+'</div>').appendTo(this.pane);
			button.hover(function(){ 
				$(this).addClass('ui-state-hover'); 
			}, function(){ 
				$(this).removeClass('ui-state-hover'); 
			});
			if(params['action'] != null) {
				button.click(params['action']);
			}
		} else {
			// Конфликтная ситуация, когда кнопка с таким button_id уже есть на панели
			alert('Кнопка с id '+button_id+' уже есть на панели '+id);
			return;
		}
	}	
}
$.widget('ui.toolbar', w);

