function Toolbar(_controller,_domain,_hash)
{this.controller=_controller;this.domain=_domain;this.hash=_hash;this._resize_timer=null;this._widget_space=null;}
Toolbar.prototype.Initialize=function()
{this.Refactor();var self=this;var refactor=function(){self.RefactorWidgets();DropdownManager.refactor();};$(window).resize(function(){if(this._resize_timer)
clearTimeout(this._resize_timer);this._resize_timer=setTimeout(refactor,50);});}
Toolbar.prototype.getHash=function()
{var poq=this.hash.indexOf('?');if(poq<0)
return this.hash;return this.hash.substring(0,poq);}
Toolbar.prototype.getInternalHash=function(){return this.hash;}
Toolbar.prototype.getDomain=function(){return this.domain;}
Toolbar.prototype.getController=function(){return this.controller;}
Toolbar.prototype.getInternalController=function(){if(this.controller=='sharedlinks')
return'share';else
return this.controller;}
Toolbar.prototype.calcWidgetSpace=function()
{var ret=0;$("div.tbToolbar-view div.widget").each(function(){ret+=$(this).outerWidth(true);});ret+=35;return ret;}
Toolbar.prototype.getLowestPriorityVisibleWidget=function()
{var lowest=null;var lowest_priority=999999;$("div.tbToolbar-view div.widget:visible").each(function(){var this_priority=parseInt($(this).attr('data-priority'));if(!lowest||this_priority<lowest_priority){lowest=$(this);lowest_priority=this_priority;}});return lowest;}
Toolbar.prototype.Refactor=function()
{this._widget_space=this.calcWidgetSpace();this.RefactorWidgets();}
Toolbar.prototype.RefactorWidgets=function()
{$("div.tbToolbar-view div.widget:not(:visible)").show();var toolbar_width=$("div.tbToolbar-view").width();var widget_widths=this._widget_space;if(widget_widths>toolbar_width)
{var left=widget_widths-toolbar_width;while(left>0)
{var widget=this.getLowestPriorityVisibleWidget();if(!widget)break;var w_width=widget.outerWidth(true);widget.hide();left-=w_width;}
this._widget_space=this.calcWidgetSpace();}}
