<?xml version="1.0"?>

<bindings id="scrollbarBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:html="http://www.w3.org/1999/xhtml"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  
  <binding id="scrollbar">
    <implementation>
      <method name="initScrollbar">
        <body>
          <![CDATA[
            try {
              var scrollbarStyle = this.boxObject.getLookAndFeelMetric("scrollbarStyle");
              var thumbStyle = this.boxObject.getLookAndFeelMetric("thumbStyle");
              var downTop;
              var upBottom;
              if ( scrollbarStyle == "double" ) {
                downTop = this.findNodeByAttribute("sbattr", "scrollbar-down-top");
                upBottom = this.findNodeByAttribute("sbattr", "scrollbar-up-bottom");
                downTop.removeAttribute("collapsed");
                upBottom.removeAttribute("collapsed");
              }
              else if ( scrollbarStyle == "doubletop" ) {
                downTop = this.findNodeByAttribute("sbattr", "scrollbar-down-top");
                var downBottom = this.findNodeByAttribute("sbattr", "scrollbar-down-bottom");
                downTop.removeAttribute("collapsed");
                downBottom.setAttribute("collapsed","true");
              }
              else if ( scrollbarStyle == "doublebottom" ) {
                var upTop = this.findNodeByAttribute("sbattr", "scrollbar-up-top");
                upBottom = this.findNodeByAttribute("sbattr", "scrollbar-up-bottom");
                upTop.setAttribute("collapsed","true");
                upBottom.removeAttribute("collapsed");
              }
              if ( thumbStyle == "fixed" ) {
                var thumb = this.findNodeByAttribute("sbattr","scrollbar-thumb");
                if ( thumb )
                  thumb.removeAttribute("flex");
              }
            }
            catch ( x ) {
              throw "Scrollbars in this skin are not properly supporting mac smart-scrolling prefs!";
            }
          ]]>
        </body>
      </method>
      <method name="findNodeByAttribute">
        <parameter name="aAttribute"/>
        <parameter name="aValue"/>
        <body>
        <![CDATA[
          var nodes = document.getAnonymousNodes(this);
          for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].getAttribute(aAttribute) == aValue)
              return nodes[i];
            else {
              var subnodes = nodes[i].getElementsByAttribute(aAttribute, aValue);
              if (!subnodes.length) continue;
              return subnodes[0];
            }
          }
          return null;
        ]]>
        </body>
      </method>
	  <constructor>
	    this.initScrollbar();
	  </constructor>
    </implementation>
  </binding>


</bindings>

