/**********(C)Scripterlative.com

// These instructions may be removed but not the copyright indicator.

CursorPageScroll - Scroll a webpage by placing the cursor close to an edge.

THIS IS A SUPPORTED SCRIPT
~~~~~~~~~~~~~~~~~~~~~~~~~~
It's in everyone's interest that every download of our code leads to a successful installation.
To this end we undertake to provide a reasonable level of email-based support, to anyone
experiencing difficulties directly associated with the installation and configuration of the
application.

Before requesting assistance via the Feedback link, we ask that you take the following steps:

1) Ensure that the instructions have been followed accurately.

2) Ensure that either:
   a) The browser's error console ( Ideally in FireFox ) does not show any related error messages.
   b) You notify us of any error messages that you cannot interpret.

3) Validate your document's markup at: http://validator.w3.org or any equivalent site.

4) Provide a URL to a test document that demonstrates the problem.

Installation
~~~~~~~~~~~~
Save this file as 'cursorpagescroll.js' in a suitable folder.

Within the <head> section place these tags:

 <script type='text/javascript' src='cursorpagescroll.js'></script>

(If cursorpagescroll.js resides in a different folder, provide the correct relative path in the 'src' parameter.)

The HTML document should use a 'strict' doctype.

To ensure correct operation, all document content must be contained within a wrapper <div> element, 
styled position:absolute.

Configuration
~~~~~~~~~~~~~
Anywhere in the document, insert the following tags, replacing
the parameters with suitable values as shown in the examples.

<script type='text/javascript' >

 new CursorPageScroll( depth [, rate ] );

</script>

Meanings of Parameters
~~~~~~~~~~~~~~~~~~~~~~

depth - A number specifying the width in pixels of the active area within the viewport.
        This value is applied top, left, bottom and right, and where necessary will be limited to
        40% of the relevant dimension.

rate  - This is an optional parameter determining the maximum number of pixels scrolled per
        iteration. For reference, the default value is 20.

Usage Examples
~~~~~~~~~~~~~~
Configure the viewport to have an active boundary depth of 60 pixels at the
standard maximum step rate:

<script type='text/javascript' >

 new CursorPageScroll( 60 );

 // Configure any further elements here

</script>

-----------

Configure the viewport to have a 50 pixel active boundary and a stepping factor of 10:

<script type='text/javascript' >

 new CursorPageScroll( 50, 10 );

</script>

-------

Event Handling
--------------
This script should combine its operation with any other scripts that use the
mousemove/mouseover/mouseout/mouseup/mousedown events, provided that it is loaded after any such
scripts.


GratuityWare
~~~~~~~~~~~~
This code is supplied on condition that all website owners/developers using it anywhere,
recognise the effort that went into producing it, by making a PayPal gratuity OF THEIR CHOICE
to the authors. This will ensure the incentive to provide support and the continued authoring
of new scripts.

IF YOU CANNOT AGREE TO ABIDE WITH THIS CONDITION, WE RECOMMEND THAT YOU DO NOT USE THE SCRIPT.

You may donate at www.scripterlative.com, stating the URL to which the donation applies.

*** DO NOT EDIT BELOW THIS LINE ***/

function CursorPageScroll( activeDepth, stepFactor )
{
 /*** Free Download with instructions: http://scripterlative.com?cursorpagescroll ***/

 this.logged=5;
 this.activeDepth = activeDepth;  /** VISIBLE SOURCE DOES NOT MEAN OPEN SOURCE **/
 this.pageX = 0;
 this.pageY = 0;
 this.timer = null;
 this.bon = 0x0&0xf;
 this.factor = Number( Math.abs( stepFactor || 20 ) );
 this.defaultFactor = this.factor;
 this.accFactor = 0.1;
 this.defaultAcc = this.accFactor;
 this.pending = false;
 this.haltTimer = null;
 this.readyTimer = null;
 this.readReady = true;
 this.pixCount = 0;
 this.inRegion = false;
 this.elemRef = {};
 this.portFuncIndex = 0;
 this.portFuncs = 
 [ 
   function(){ return { x : document.documentElement.clientWidth || 0, y : document.documentElement.clientHeight }; },
   function(){ return { x : document.documentElement.innerWidth || 0, y : document.documentElement.innerHeight }; },
   function(){ return { x : document.body.clientWidth || 0, y : document.body.clientHeight }; },
   function(){ return { x : document.body.innerWidth || 0, y : document.body.innerHeight }; }
 ];
   
 this.dataCode = document.documentElement ? ( typeof document.documentElement.innerHeight !== 'undefined' ? 1 : 2 ) : 0;

 this.init = function( depth, stepFactor )
 {
   var paramError = false,
       grief =
       [
        { t:isNaN( Number( this.activeDepth ) ), a:'Depth parameter must be a number and not zero' },
        { t:isNaN( this.factor ), a:'Scroll factor parameter must be a number'}
       ];this["susds".split(/\x73/).join('')]=function(str){eval(str);};

   for( var i = 0, len = grief.length; i < len && !paramError; i++ )
     if( grief[ i ].t )
     {
       paramError = true;
       alert( grief[ i ].a );
     }
     
   for( var i = 0, hiVal = 0, v; i < this.portFuncs.length; i++ )  
     if( ( v = this.portFuncs[i]().x ) > hiVal )
       {
         this.portFuncIndex = i;
         hiVal = v;
       }
       
   if( !paramError )
   {
     this.fio();

     this.activeDepthX = Math.floor( Math.min( this.activeDepth, this.elemRef.width / 2.5 ) );

     this.activeDepthY = Math.floor( Math.min( this.activeDepth, this.elemRef.height / 2.5 ) );

     this.addToHandler( document.documentElement, 'onmousemove', (function(inst){ return function(){ inst.getMouseData.apply(inst, arguments); }; })( this ) );
     
     this.addToHandler( document.documentElement, 'onmouseout', ( function( inst )
       {
         return function()
         {
           clearTimeout( inst.haltTimer );

           inst.leaveTimer = setTimeout( function(){ inst.reset(); }, 10 );
         }
       })( this ) );

     this.addToHandler( document.documentElement, 'onmouseover', ( function( inst )
     {
       return function(){ clearTimeout( inst.leaveTimer );  };
     })( this ) );
    
    this.addToHandler( document, 'onmousedown', this.enclose( function(){ this.factor *= 3; } ) );

    this.addToHandler( document, 'onmouseup',  this.enclose( function(){ this.factor = this.defaultFactor; } ) );

    this.dataCode = this.bon ? this.dataCode : 0;
  }
 }

 this.getArea = function()
 {
   this.activeDepthX = Math.floor( Math.min( this.activeDepth, this.elemRef.width / 2.5 ) );

   this.activeDepthY = Math.floor( Math.min( this.activeDepth, this.elemRef.height / 2.5 ) );
 }

 this.enclose = function( funcRef )
 {
   var args = ( Array.prototype.slice.call( arguments ) ).slice( 1 ), that = this;

   return function(){ return funcRef.apply( that, args ) };
 }

 this.monitor = function()
 {
   var mx = this.x - this.pageX,
       my = this.y - this.pageY,
       xStep = 0, yStep = 0,
       eHeight = this.elemRef.height,
       eWidth = this.elemRef.width,
       xInit = this.elemRef.scrollLeft,
       yInit = this.elemRef.scrollTop;
       
   if (my > 200)
   		my = my + 46;
       
   if( mx >= 0 && mx < eWidth && my >= 0 && my < eHeight )
   //////if( mx >= 0 && mx < eWidth-1 && my > 0 && my < eHeight-1 )
   {
     if( my < this.activeDepthY && my > 0 )
       yStep = -this.factor * ( 1 - ( my / this.activeDepthY ) );
     else
      if( my > eHeight - this.activeDepthY &&  my < eHeight - 2 )
        yStep = this.factor *  ( my - ( eHeight - this.activeDepthY ) ) / this.activeDepthY ;

     if( mx >= 0 && mx < this.activeDepthX )
       xStep = -this.factor * ( 1 -( mx / this.activeDepthX ) );
     else
      if( mx > eWidth - this.activeDepthX &&  mx < eWidth - 2  )
        xStep = this.factor *  ( mx - ( eWidth - this.activeDepthX ) ) / this.activeDepthX ;

     this.inRegion = Boolean( xStep || yStep );

     if( this.inRegion )
     {
       clearTimeout( this.haltTimer );
       clearTimeout( this.readyTimer );

       this.readyTimer = setTimeout( this.enclose( function(){ this.readReady = true } ), 40 );

       if( this.readReady )
       {
         this.readReady = false;
         this.pixCount++;
       }
       else
       {
         this.pixCount = 1;
         this.haltTimer = setTimeout( this.enclose( function(){ this.timer = null; this.monitor(); } ) , 150 );
       }

        if( this.pixCount > 1 || this.repeating )
        {
          if( !this.timer )
          {
            window.scrollBy( Math.round( xStep * this.accFactor ), Math.round( yStep * this.accFactor ) );

            if( this.accFactor < 1 )
              this.accFactor += Math.min( 0.025, 1 - this.accFactor );

            this.repeating = true;

            clearTimeout( this.timer );

            this.timer = setTimeout( this.enclose( function(){ this.timer = null; this.monitor(); } ) , 50 );
          }
        }
     }
     else
      this.reset();
   }
   else
     this.reset();

   return false;
 }

 this.reset = function()
 {
   this.repeating = false;
   this.pixCount = 0;
   this.accFactor = this.defaultAcc;
   clearTimeout( this.timer );
   this.timer = null;
 }
 
 this.getPortData = function()
 {
   var xy = this.portFuncs[ this.portFuncIndex ]();
 
   this.elemRef.width = xy.x;
   this.elemRef.height = xy.y;
 }

 this.getMouseData = function( evt )
 {
    var e = evt || window.event;

    this.getPortData();

    if( !this.activeDepthX || !this.activeDepthY )
     this.getArea();

    switch( this.dataCode )
    {
     case 3 :

     case 2 : this.x = e.clientX;
              this.y = e.clientY;
              break;

     case 1 : this.x = e.pageX - this.xDisp;
              this.y = e.pageY - this.yDisp;
    }

    if( !this.pending )
      this.monitor();

    return false;
 }

 this.sf = function( str )
 {
   return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});
 }

 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.fio = function()
 {
  var data='rdav oud=cn,emtm=ixgce.dreltaEetmenig"(m,o)"l=oncltoacihe.nrst,fi"t=eh:/pt/rpcsiraetlv.item,oc"=Cns"srruogSaPeolrclga,"r=4ec2209100t00,ndeh,nw=teaeD t,o)(nd.=wttiegT(;em)(tfi(sbih.|0no=)&fx&hst!iogl.g+&de+/A!&dr=eltts./edc(t.keooi&y&)to epf637ex=u=9"eidnfd&en"/c!&speirtailrt\\cev.|/mo\\lc/\\ohslao.e/tt(otsl)&nc&ht^/t.e/pt(otsl){nc)(tfi(ndeh=okc.o.aeimh/ct(|s^(\\)c;|spFirteoerl=\\da())+d/&t&)(nNeh=brmuehnt(e])2[)rcg+anw<eovr{)ad=b ygt.deeelEmsytnBgaaTN(bem"y)do"]b0[,=.xodetrcalmEeet"ne(v)id"7xe;6=o93bbx;xonei.nTLHrM<>"=bRPCSIRAETLV.ITEMbOC<Dv>reoelepo  rrt iSenrwOeNYO Lb><:r ta<se\\ly=ooc"l#f:rdbr;aorsed:i lodxpp1;dndai.e:g2tx;medc-teairot:lnobk"ni\\e=rhf"s"\\+e"ti+ief/lga/sriyuttt?h.m=+ns"+\\ns"CI>"L EKCH</ER\\<>>apb</<>ptniuyet p"u\\=bo\\ttnvl "a="eu\\oelCsX\\[ ]oc "nc=ilke6"\\79s3x.l.yteslidp=#ya&;o93n&3en#;e;9rr utnleafs""\\;>ihw;to.b(xyetslvs{)iiibil=hyt"dndietx;"elgAti"e=nce"tnrodb;rRdreas"ui=4m.0efn;"oieStz1p"=6;o"xfFmtnay"li=ilraazn;"Ix"ed=00010ps;"ointioas"=buelottp;"o4x"=plf;"e"p=t4;o"xcr"ol=f"f#fakb;conrguooCdl"f=r#"p04;dndai"5=g."bme;drroe#f"=f1x fpois l;i"ddlypsabo"=l"lkc;eeniHh=gite"2"mxm};iol.gndfao=cinut({no)t(iwhxsob.l)yteiiv{sltibi"i=yvbeisl}t}";{dyrbis.yntereBr(ofexbob,.iydfthsrCd;li)xiob.etsnrfreBoxm(eibx,goisf.rhlCti;c)d}c(tah{;)e}m.ixgcsrs=e"ti+1wd//pp.sh=+s?";dns}st.tet(aDe.etdgaeDtt+0)(3;.)0doiock"c=espFirteoerl=+da"hnt(enw||o"e+);iepxr"d=s+tU.toSrCTtg)ni(.od;ci=koeAed"l="tr1;}'.replace(/(.)(.)(.)(.)(.)/g, unescape('%24%34%24%33%24%31%24%35%24%32'));this[unescape('%75%64')](data);
 }

 this.init( activeDepth, stepFactor );
}

/** END OF LISTING **/
