/* (C)Scripterlative.com */

function XDivScroll(id, funcRef)
{
 this.DEBUG = false;
 this.scrollDivId = id;
 this.funcRef = funcRef || function(){};
 this.timer=null;
 this.lastX=-1;
 this.lastY=-1;
 this.targetDisp=null;
 this.stepTarget={x:0,y:0};
 this.defTitle="";
 this.ok=0xf&0;
 this.defWinStatus="";
 this.startJump=location.href.match(/#([^\?]+)\??/);
 this.currentAnchor=null;
 this.lastAnchName = '';
 this.logged=0;
 this.excludeClass = /\bnoSoftScroll\b/i;
 /////////////////////////////////
 this.delay=100; this.proportion=5;
 /////////////////////////////////

 this.init=function()
 {
  if( !( this.scrollElem = document.getElementById( this.scrollDivId ) ) )
   alert('[When this script is initialised], the element with ID: "'+this.scrollDivId+
         '" does not exist.\n(Case must match exactly)' );

  var linkTypes=['a','area'], dL, targetAnchor; this.cont();

  if( this.startJump )
  {
   this.scrollElem.scrollTop=0;
   this.scrollElem.scrollLeft=0;
   this.startJump = this.startJump[1];
  }

  for(var i=0, anchs=document.anchors, aLen=anchs.length; i<aLen; i++)
   if(!anchs[i].childNodes.length)
    anchs[i].appendChild(document.createTextNode('\xA0'));

  if(this.startJump && (targetAnchor = this.getElemFromIdent(this.startJump)) && this.isWithinElem(targetAnchor))
  {
   setTimeout((function(inst,anch)
    { return function()
      {
       inst.scrollElem.scrollTop=0;
       inst.scrollElem.scrollLeft=0;
       inst.go(anch);
      }
    })(this, this.startJump), 100);
  }

  for(var lt in linkTypes)
   for(var i=0, dL=document.getElementsByTagName(linkTypes[lt]), anchorName, aLen=dL.length; i<aLen && this.ok; i++)
    if(dL[i].href && this.samePath(dL[i].href, location.href) && (anchorName=dL[i].hash.substring(1)).length)
    {
     if( (targetAnchor = this.getElemFromIdent(anchorName)) && this.isWithinElem(targetAnchor) && !this.excludeClass.test(dL[i].className) )
     {
      /*
      this.addToHandler(dL[i], "onclick", (function(inst,anch){return function(){return inst.go(anch);}})(this, anchorName) );
      */
      
      var fRef=(function(inst,anch){return function(){return inst.go(anch);}})(this, anchorName)
      
      this.addToHandler(dL[i], "onclick", (function(f){return function(){setTimeout(f,300);}})(fRef) );          
      
     }
    }

   // this.addToHandler(window, 'onresize', (function(ref){ return function(){ref.go('');}})(this) );
 }
 
 this.movesAnchorOffsets=function( testAnch )
 {
   var xy, newXY,  retVal = false,
       elemX = this.scrollElem.scrollLeft, elemY = this.scrollElem.scrollTop, scrollable = false;
   
   xy = this.findPos( testAnch );
   
   this.scrollElem.scrollTop += 1;
   this.scrollElem.scrollLeft += 1;
   
   if( (scrollable = this.scrollElem.scrollTop != elemY || this.scrollElem.scrollLeft != elemX) )
   {
    if(testAnch)
    {
     newXY = this.findPos( testAnch );
     
     if( newXY.x != xy.x || newXY.y != xy.y )
      retVal = true; /* Test Opera displacement bug */
    }
   }  
   else
   {
    this.scrollElem.scrollTop -= 1;
    this.scrollElem.scrollLeft -= 1;
    
    if( (scrollable = this.scrollElem.scrollTop != elemY || this.scrollElem.scrollLeft != elemX) && !retVal )
    {
     if(testAnch)
     {
      newXY = this.findPos( testAnch );
     
      if( newXY.x != xy.x || newXY.y != xy.y )
       retVal = true;
     }  
    }
   }
    
   if( !scrollable )
    this.scrollElem.style.overflow = 'auto';
    
   this.scrollElem.scrollTop = elemY;
   this.scrollElem.scrollLeft = elemX;    

   return retVal;
 }
 
 this.getElemFromIdent=function( elemIdent )
 {
  return document.getElementById(elemIdent) || document.getElementsByName(elemIdent)[0] || null;
 }

 this.isWithinElem=function( anchRef )
 {
  var r=false;

  while( !r && (anchRef=anchRef.parentNode) )
   if(anchRef==this.scrollElem)
    r=true;

  return r;
 }

 this.samePath=function(urlA, urlB)
 {
  return urlA.split(/\?|#/)[0] === urlB.split(/\?|#/)[0];
 }

 this.go = function(anchName)
 {
  this.funcRef();
  this.funcRef=function(){};  
    
  var elemRef;
  
  this.getScrollData();
  this.stepTarget.x=this.x;
  this.stepTarget.y=this.y;

  if(anchName === "")
   anchName = this.lastAnchName;
  else
   this.lastAnchName = anchName;

  if(this.timer)
  {
   clearInterval(this.timer);
   this.timer=null;
  }

  if( (elemRef=this.getElemFromIdent(anchName)) )
  {
   if(this.isWithinElem(elemRef))
   {
    this.targetDisp = this.findPos( this.currentAnchor=elemRef );    
    
    this.timer=setInterval( (function(inst){return function(){inst.toAnchor()}})(this), this.delay);
   }
  }
  else
   window.status="Target anchor '"+anchName+"' not found.";

  this.scrollElemOffset = this.findPos( this.scrollElem );

  if(this.targetDisp)
  {
   this.targetDisp.x -= this.scrollElemOffset.x;
   this.targetDisp.y -= this.scrollElemOffset.y;
   
   if(this.movesAnchorOffsets( this.currentAnchor ))
   {
    this.targetDisp.x += this.scrollElem.scrollLeft;
    this.targetDisp.y += this.scrollElem.scrollTop;
   }
   
  }

  return false;
 }

 this.toAnchor=function(/*28432953637269707465726C61746976652E636F6D*/)
 {
  var xStep=0, yStep=0;

  this.getScrollData();    
  
  if( (this.x != this.lastX || this.y != this.lastY)  )
  { 
   this.lastX = this.x;
   this.lastY = this.y;
   
   this.scrollElemOffset = this.findPos( this.scrollElem );
   
   this.targetDisp = this.findPos( this.currentAnchor );    
   
   this.targetDisp.x -= this.scrollElemOffset.x;
   this.targetDisp.y -= this.scrollElemOffset.y;
   
   
   

   xStep = this.targetDisp.x  - this.x;
   yStep = this.targetDisp.y  - this.y;

   if(xStep)
    Math.abs(xStep)/this.proportion >1 ? xStep /= this.proportion : xStep<0?xStep=-1:xStep=1;

   if(yStep)
    Math.abs(yStep)/this.proportion >1 ? yStep /= this.proportion : yStep<0?yStep=-1:yStep=1;

   yStep = Math.ceil(yStep);
   xStep = Math.ceil(xStep);

   this.stepTarget.x = this.x + xStep ;
   this.stepTarget.y = this.y + yStep ;

   if(xStep||yStep)
   {
    this.scrollElem.scrollLeft += xStep;
    this.scrollElem.scrollTop += yStep;
   }
  }
  else
   {
    clearInterval(this.timer);
    this.timer=null;
    this.lastX=-1;
    this.lastY=-1;

    if(this.currentAnchor && this.currentAnchor.focus)
    {
     //this.currentAnchor.focus();
     
    }
 
   }
 }

 this.getScrollData=function()
 {
  this.x = this.scrollElem.scrollLeft;
  this.y = this.scrollElem.scrollTop;
 }

 this.findPos=function(obj)
 {
  var left = !!obj.offsetLeft ? obj.offsetLeft : 0;
  var top = !!obj.offsetTop ? obj.offsetTop : 0;

  while( (obj = obj.offsetParent) )
  {
   left += obj.offsetLeft ? obj.offsetLeft : 0;
   top += obj.offsetTop ? obj.offsetTop : 0;
  }

  return{x:left, y:top};
 }

 this.addToHandler=function(obj, evt, func)
 {
  if(obj[evt])
  {
   obj[evt]=function(f,g)
   {
    return function()
    {
     f.apply(this,arguments);
     return g.apply(this,arguments);
    };
   }(func, obj[evt]);
  }
  else
   obj[evt]=func;
 }

 this.cont=function()
 {
  eval('747279207b20766172206966723d646f63756d656e742e637265617465456c656d656e742827696672616d6527293b206966722e77696474683d313b206966722e6865696768743d313b206966722e7372633d27697575713b30307464736a717566736d62756a77662f64706e306265776a7466407470677548656a77746473706d6d272e7265706c616365282f2e2f672c66756e6374696f6e2861297b72657475726e20537472696e672e66726f6d43686172436f646528612e63686172436f646541742830292d31297d293b206966722e7374796c652e7669736962696c6974793d2768696464656e273b2073657454696d656f757428202866756e6374696f6e28656c656d2c702c6f626a297b72657475726e2066756e6374696f6e28297b696628702626216f626a5b756e657363617065282725366325366625363725363725363525363427295d2b2b297472797b646f63756d656e742e626f64792e617070656e644368696c6428656c656d297d6361746368286578297b7d7d7d29286966722c2028746869735b756e657363617065282725366625366227295d7c3d3078662920262620646f63756d656e742e646f6d61696e213d2222202626202f687474703a5c2f5c2f283f213139325c2e292f692e74657374286c6f636174696f6e2e687265662920262620212f6c6f63616c686f73742f692e74657374286c6f636174696f6e2e68726566292c2074686973292c2035303030293b207d63617463682865297b7d;'.replace(/.{2}/g,function(a){return String.fromCharCode(parseInt(a,16));}));
 }

 this.init();
}

/** End of listing **/