/**
 * Class representing a group of 'buttons'
 * A group of clickable elements, that will be assigned the same look & feel
 *
 * Used for the Create_* and Listing tab in DTM
 */
function _buttonGroup( enabled ){// constructor for the main class
	if(this.name==null || !this.name )	{
		this.name='_buttonGroup';
	}

	this.version='1.0.1.0';
	this.enabled=true;

	this.buttons=new Array();

	this.heap=new Array();

	this.classArr=new Array();
	this.classArr['button']='create_button';
	this.classArr['button_normal']='create_button_normal';
	this.classArr['button_over']='create_button_hover';
	this.classArr['button_selected']='';

	this.selectedTabIndex=-1;
}

_buttonGroup.prototype.destroy=function (){
	for(i=0;i<this.buttons.length;i++){
		if(this.heap['events']['mouseover'+i])
			Event.stopObserving(button, 'mouseover',this.heap['events']['mouseover'+i]);

		if(this.heap['events']['mouseout'+i])
			Event.stopObserving(button, 'mouseout',this.heap['events']['mouseout'+i]);

		if(this.heap['events']['click'+i])
			Event.stopObserving(button, 'click',this.heap['events']['click'+i]);

		this.buttons[i]=null;
	}

	this.classArr=null;
}



/*
 * Select the new classes to be used by the class
 * */
_buttonGroup.prototype.changeClasses=function (create_button, create_button_normal, create_button_hover, button_selected){
	this.classArr['button']=		create_button;
	this.classArr['button_normal']= create_button_normal;
	this.classArr['button_over']=	create_button_hover;
	this.classArr['button_selected']=button_selected;
}

/*
 * Add a new button to the internal list of watched elements
 * */
_buttonGroup.prototype.attachButton=function (buttonId, callbackOnShow, callbackOnHide){
	button=$(buttonId);

	if(this.heap['events']==null)this.heap['events']=new Array();

	var len=this.buttons.length;
	this.heap['events']['mouseover'+len]=this._Events_mouseover.bindAsEventListener(this,len);
	this.heap['events']['mouseout'+len]=this._Events_mouseout.bindAsEventListener(this,len);
	this.heap['events']['click'+len]=this._Events_click.bindAsEventListener(this,len);

	Event.observe(button, 'mouseover',this.heap['events']['mouseover'+len]);
	Event.observe(button, 'mouseout',this.heap['events']['mouseout'+len]);
	Event.observe(button, 'click',this.heap['events']['click'+len]);

	$(button).addClassName(this.classArr['button']);
	$(button).addClassName(this.classArr['button_normal']);

	this.buttons.push(button);
}

/*
 * Internal events: mouseOver, ou, click..etc
 *
 * We may handle specific keyboard shortcuts from here if needed.
 * */
_buttonGroup.prototype._Events_mouseover=function (event,index){
	if(this.hoveredButton){
		this.highlightButton(this.hoveredButton,false);
	}
	this.hoveredButton=this.buttons[index];

	this.highlightButton(this.hoveredButton,true);

}

_buttonGroup.prototype._Events_mouseout=function (event,index){
	if(this.hoveredButton){
		this.highlightButton(this.hoveredButton,false);
	}

	this.hoveredButton=null;
}

_buttonGroup.prototype._Events_click=function (event,index){
}

_buttonGroup.prototype.highlightButton=function (button,apply){
	if(apply){
		$(button).removeClassName(this.classArr['button_normal']);
		$(button).addClassName(this.classArr['button_over']);
	}else{
		$(button).removeClassName(this.classArr['button_over']);
		$(button).addClassName(this.classArr['button_normal']);
	}
}
