function PanelGroup( name ) {
	this.name = name;
	this.panels = new Array();
	this.selected = new Array();
	
	this.selected.exists = function( item ) {
		var l = this.length;
		
		for( var i = 0; i < l; i++ ) {
			if( this[i] == item ) {
				return i;
			}
		}
		
		return false;
	}
	
	this.dispatcherEvent = 'onclick';
	
	this.maximumVisiblePanels = 1;
	
	return this;
}

/**
	Agrega un dispatcher con su respectivo panel.
	@param dispatcherID ID del dispatcher, que puede ser virtualmente cualquier control que pueda disparar eventos.
	@param panelID ID del panel, que tambi�n puede ser cualquier control, preferentemente un DIV. Si no se especifica, se busca el primer DIV siguiente al dispatcher en el DOM.
	@return �xito de la operaci�n.
*/
PanelGroup.prototype.add = function( dispatcherID, panelID ) {
	var dispatcher = document.getElementById( dispatcherID );
	
	if( panelID ) {
		var panel = document.getElementById( panelID );
	}
	else {
		var panel = this._getNextSiblingByNodeName( dispatcher, 'div' );
	}
	
	if( panel ) {
		this.panels[dispatcherID] = panel;
		
		if( dispatcher.attachEvent ) {
			dispatcher.attachEvent( this.dispatcherEvent, this.eventHandler );
		}
		else {
			dispatcher[this.dispatcherEvent] = this.eventHandler;
		}
		
		dispatcher._panelGroup = this;
		dispatcher._panel = panel;
		
		panel.style.display = 'none';
		
		return true;
	}
	
	return false;
}

PanelGroup.prototype.eventHandler = function( e ) {
	if( !e ) e = window.event;
	
	if( e.srcElement ) target = e.srcElement;
	else if( e.target ) target = e.target;
	
	var o = target._panelGroup;
	var selected = o.selected;

	pos = selected.exists( target );
	
	if( pos !== false ) {
		/* Ya est� seleccionado */
		if( o.dispatcherEvent != 'onmouseover' ) {
			o.alternateStatus( selected.splice( pos, 1 )[0], false );
		}
	}
	else {
		/* No est� seleccionado */
		if( selected.length == o.maximumVisiblePanels ) {
			o.alternateStatus( selected.shift(), false );
		}
		
		selected.push( target );
		
		o.alternateStatus( target, true );
	}
}

PanelGroup.prototype.alternateStatus = function( dispatcher, show ) {
	if( dispatcher ) {
		var panel = dispatcher._panel;
		
		if( this.selectedClassName ) {
			if( show ) {
				dispatcher._className = dispatcher.className;
				
				dispatcher.className = this.selectedClassName;
			}
			else {
				if( dispatcher._className ) {
					dispatcher.className = dispatcher._className;
				}
				else {
					dispatcher.className = '';
				}
			}
		}
	}
	
	if( panel ) {
		if( show ) {
			panel.style.display = '';
		}
		else {
			panel.style.display = 'none';
		}
	}
}

PanelGroup.prototype._getNextSiblingByNodeName = function( node, nodeName ) {
	nodeName = nodeName.toUpperCase();

	while( node ) {
		if( node.nodeName == nodeName ) {
			return node;
		}
		
		node = node.nextSibling;
	}
	
	return null;
}