  YAHOO.namespace("YAHOO.dealerweb.panel.teaserbar");


  /*****************************************************************************
  * DealerwebBackend_Panel_TeaserBar
  *  - YAHOO.dealerweb.panel.teaserbar.Util
  *****************************************************************************/
  if(!YAHOO.dealerweb.panel.teaserbar.Util)
    YAHOO.dealerweb.panel.teaserbar.Util=new function()
  {
    // predefined properties
    this.SCROLL_NEXT=0;
    this.SCROLL_PREV=1;

    this.TEASER_COUNT=4;
    this.TEASER_WIDTH=176;
    //--------------------------------------------------------------------------

    // static accessors
    this.init=function(id_)
    {
      this.m_id=id_;

      this.m_bar=document.getElementById(this.m_id+"-bar");
      if(!this.m_bar)
        return;

      var items=YAHOO.util.Dom.getElementsByClassName("item", "li", this.m_bar);

      this.m_count=items.length;
      this.m_bar.style.width=((this.m_count*this.TEASER_WIDTH)-9)+"px";

      this.updateNavigation();
    }

    this.next=function()                                                        {this.scroll(this.SCROLL_NEXT);}
    this.prev=function()                                                        {this.scroll(this.SCROLL_PREV);}
    //--------------------------------------------------------------------------

    // IMPLEMENTATION
    this.m_id=null;
    this.m_bar=null;
    this.m_wrapper=null;

    this.m_count=0;
    this.m_current=0;
    //-----

    this.updateNavigation=function()
    {
      var prev=document.getElementById(this.m_id+"-prev");
      if(0<this.m_current)
        prev.style.display="block";
      else
        prev.style.display="none";

      var next=document.getElementById(this.m_id+"-next");
      if(this.m_count>(this.m_current+this.TEASER_COUNT))
        next.style.display="block";
      else
        next.style.display="none";
    }
    this.scroll=function(direction_)
    {
      if(this.SCROLL_NEXT==direction_ && this.m_count>(this.m_current+this.TEASER_COUNT))
      {
        this.m_current++;
        this.scrollTo(-(this.TEASER_WIDTH), 0);
      }
      else if(this.SCROLL_PREV==direction_ && 0<(this.m_current))
      {
        this.m_current--;
        this.scrollTo((this.TEASER_WIDTH), 0);
      }
      this.updateNavigation();
    }

    this.scrollTo=function(px)
    {
      var step = this.getStep(px);
      if(px < 0)
      {
        step = -step;
        if(px < step)
        {
          this.m_bar.style.left = (this.m_bar.offsetLeft + step).toString() + "px";
          px -= step;
          window.setTimeout('YAHOO.dealerweb.panel.teaserbar.Util.scrollTo(' + px.toString() + ')', 10);
        }
        else
        {
          this.m_bar.style.left = (this.m_bar.offsetLeft + px).toString() + "px";
        }
      }
      else
      {
        if(px > step)
        {
          this.m_bar.style.left = (this.m_bar.offsetLeft + step).toString() + "px";
          px -= step;
          window.setTimeout('YAHOO.dealerweb.panel.teaserbar.Util.scrollTo(' + px.toString() + ')', 10);
        }
        else
        {
          this.m_bar.style.left = (this.m_bar.offsetLeft + px).toString() + "px";
        }
      }
    }
    this.getStep=function(px)
    {
      if(px < 0)
        px = -px;
      if(px >= 300)
        return 50;
      if(px >= 50)
        return 20;
      if(px >= 15)
        return 5;

      return 2;
    }
  };
  /****************************************************************************/
