// JavaScript Document
  /*
    Copyright (c) 2009 Muneer Mohammad (http://www.encodez.com/)
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this code, to deal in the code without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the code, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:
     
    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the code.
    
    THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
  */
  
  
  var gTop=0;
  var gIncVal=0;
  // var timeOutValue can be used to adjust the speed of scroller.
  var timeOutValue=10;
    
    
  function scrollMe(arg)
  {    
    var objEncNav=document.getElementById('encNav');
    
    // var scrollAmount define the fast and
    // the amount of scrolling pane
    var scrollAmount=160;
    var objEncNavHeight=parseInt(objEncNav.offsetHeight);
    var objEncNavTop=objEncNav.style.top;
    
    // var barHeight defines the heigt of inner layer
    // it must set -10 from max height
    var barHeight=160;   
    
    if(!objEncNavTop)
      objEncNavTop=0;
    else
      objEncNavTop=objEncNavTop.substring(0,objEncNavTop.length-2);
      
    if(arg>0)
    {
      if(objEncNavTop>=0 || objEncNavTop>(-(objEncNavHeight-(barHeight+scrollAmount))))
      {
        incrementValue=scrollAmount;
      }
      else if(objEncNavTop<(-(objEncNavHeight-(barHeight+scrollAmount))))
      {
        incrementValue=(objEncNavHeight-barHeight)+parseInt(objEncNavTop);
      }
      else
      {
        incrementValue=0;
      }
      encSmoothScroll("minus", parseInt(objEncNavTop), parseInt(incrementValue));
    }
    else
    {
      if(objEncNavTop<0 && ((parseInt(objEncNavTop)+scrollAmount) < 0))
      {
        incrementValue=scrollAmount;
      }
      else
      {
        incrementValue=-objEncNavTop-0;     
      }
      encSmoothScroll("plus", parseInt(objEncNavTop), parseInt(incrementValue));
    }
  }
  function encSmoothScroll(dir, currentVal, incValue)
  {
    gTop=currentVal;
    gIncVal=incValue;
    encScrollBy(dir, 0)
  }
  function encScrollBy(dir, val)
  { 
    if(val<gIncVal)
    {
      var tmpInc;      
      if((gIncVal-val)>1)      
      {
        tmpInc=Math.ceil((gIncVal-val)/10);
        if(tmpInc <1)
          tmpInc=1;
      }
      else
      {
        tmpInc=gIncVal-val;
      }
      
      val+=tmpInc;
      
      var objEncNav=document.getElementById('encNav');
      if(dir=="plus")
      {
        objEncNav.style.top=gTop+val+"px";
      }
      else if(dir=="minus")
      {
        objEncNav.style.top=gTop-val+"px";
      }
      var t=setTimeout("encScrollBy('"+dir+"', "+val+");", timeOutValue);
    }
    else
    {
      clearTimeout(t);
    }
  }
