  /*
    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.
    
  */
  
  
  var gTop=0;
  var gIncVal=0;
  // var timeOutValue can be used to adjust the speed of scroller.
  var timeOutValue=150;
    
    
  function scrollMe(arg)
  {    
    var objEncNav=document.getElementById('encNav');
    
    // var scrollAmount define the fast and
    // the amount of scrolling pane
    var scrollAmount=265;
    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=290;   
    
    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);
    }
  }