var ToolbarButton = Class.create();
ToolbarButton.prototype =
{
  initialize: function(clientID, textElementId, onClickFunc, url)
  {
    this.ClientID = clientID;
    this.ButtonElement = $(this.ClientID);
    this.TextElement = $(textElementId);
    this.OnClickFunc = onClickFunc;
    this.Url = url;
  },
  
  Click: function()
  {
    eval(this.OnClickFunc + "(this)");
  }
}

var Toolbar = Class.create();

Toolbar.prototype = 
{
  initialize: function(clientID, buttonArray)
  {
    this.ClientID = clientID;
    this.ButtonArray = buttonArray;
  },
  
  ButtonChange: function(button, imageSrc)
  {
    button = $(button);
    
    button.style.backgroundImage = 'url(' + imageSrc + ')';
  },
  
  FireButton: function(clickedButton)
  {
    $A(this.ButtonArray).each(function(buttonObj)
    {
      if(buttonObj.ButtonElement == clickedButton)
      {
        buttonObj.Click();
        if(buttonObj.Url)
          window.location.replace(buttonObj.Url);
      }
      
    }.bind(this));
  },
	
	GetButtonByCommandName: function(commandName)
	{
		
		var buttonObj;
		$A(this.ButtonArray).each(function(button)
		{
			if(button.ClientID.match(new RegExp(commandName)) != null)
				buttonObj = button;
		}.bind(this));
		
		return buttonObj;
	}
}
