<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE bindings SYSTEM "/entities.dtd"><?xml-stylesheet type="text/css" href="/styles/style.css"?>

<bindings xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <binding extends="chrome://global/content/bindings/button.xml#button-base" id="button">
        <content>
            <xul:toolbarbutton anonid="button" class="ybar-button-text-counter" id="ybar-button-odnoklassniki-notifications" oncommand="OnCommand(event)" orient="horizontal" tooltiptext="&widget.tooltip.notifications;" type="menu-button">
                <xul:menupopup anonid="menu">
                    <xul:menuitem anonid="update" label="&widget.menuitem.update;"/>
                    <xul:menuseparator/>
                    <xul:menuitem anonid="menu-notifications" class="menuitem-iconic" label="&widget.menuitem.notifications-follow;"/>
                    <xul:menuseparator anonid="sep" hidden="true"/>
                </xul:menupopup>
            </xul:toolbarbutton>
        </content>
        <implementation implements="nsISupports, nsIDOMEventListener">
            <field name="odnoklassniki">this.parentNode.app.odnoklassniki</field>
            <field name="settings">this.parentNode.app.settings</field>
            <field name="button">document.getAnonymousElementByAttribute(this, "anonid", "button")</field>
            <field name="sep">document.getAnonymousElementByAttribute(this, "anonid", "sep")</field>
            <field name="menu">document.getAnonymousElementByAttribute(this, "anonid", "menu")</field>
            <field name="observerService">Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);</field>
            
            <constructor><![CDATA[var $ = this;
if (this.settings.counters)
{
this.SetCounter(this.settings.counters.notifications);
}

this.UpdateMenu();]]></constructor>
                        
            <method name="OnCommand">
                <parameter name="event"/>
                <body><![CDATA[var anonid = event.target.getAttribute("anonid","");
switch (anonid) {
case "button":

case "menuitem":

case "menu-notifications":
this.odnoklassniki.Navigate("notifications");
break;
case "update":
this.odnoklassniki.ShowThrobber("notifications");
this.odnoklassniki.Update();
break;
}
]]></body>
            </method>
            
            <method name="SetCounter">
                <parameter name="counter"/>
                <body><![CDATA[this.button.label = counter ? counter : "";
this.button.setAttribute("throbber",false);]]></body>
            </method>
            
            <method name="UpdateMenu">
                <body><![CDATA[var msgs = this.settings.notifications;
if (! msgs)
{
return;
}

var show = msgs.length > 0;
this.sep.setAttribute("hidden",! show);]]></body>
            </method>
            
        </implementation>
    </binding>
</bindings>