﻿/****(C)Scripterlative.com

D R A G S C R O L L

Description
~~~~~~~~~~~
 Allows the document to be scrolled by dragging with the mouse

 Info: http://scripterlative.com?dragscroll

 (Double click to initialise / toggle)


 These instructions may be removed but not the above text.


Installation
~~~~~~~~~~~~
 Save this text/file as 'dragscroll.js', and place it in a folder associated with your web pages.

 At the bottom of the <body> section or later than all other scripts, insert:

 <script type='text/javascript' src='dragscroll.js'></script>

 (If dragscroll.js resides in a different folder, include the relative path)

Configuration
~~~~~~~~~~~~~
 None. Double-click to inhibit/toggle.

GratuityWare
~~~~~~~~~~~~
 This code is free for private non-commercial use. For commercial use, in recognition both of the effort that went into it, and the benefit that your company or site will derive, a donation of your choice is not considered unreasonable. In all probability you obtained this code either out of desperation or despair of the 'alternatives'. 'Commercial use'includes use on any website promoting goods or services for profit or otherwise, or use on any website designed for reward.

 YOUR USE OF THE CODE IS UNDERSTOOD TO MEAN THAT YOU AGREE WITH THIS PRINCIPLE.

 You may donate at www.scripterlative.com, stating the URL to which the donation applies.

*** DO NOT EDIT BELOW THIS LINE***/

var DragScroll;

(DragScroll=
{
 initialised:false, e:null, dataCode:0, x:0, y:0, pX:-1, pY:-1, lastPX:-1, lastPY:-1,
 prevX:0, prevY:0, mouseDown:false, moveWait:null, codeAction:false, canDrag:true, logged:2,

 setFlags:function()
 {
  if( document.documentElement )
   this.dataCode=3;
  else
   if(document.body && typeof document.body.scrollTop!='undefined')
    this.dataCode=2;
   else
    if( this.e && this.e.pageX!='undefined' )
     this.dataCode=1;

  this.initialised=true;
 },

 init:function(/*2843295374657068656E204368616C6D657273*/)
 {
  if(!document.getElementById && document.captureEvents && Event)
   document.captureEvents(Event.MOUSEMOVE);

  this.addToHandler(document, 'onmousemove',  function()
   {
     clearTimeout(DragScroll.moveWait);

     var tempObj=arguments[0]||window.event;

     DragScroll.evtObj={};

     for(var x in tempObj)
      DragScroll.evtObj[x]=tempObj[x]; //preserve event object

     clearTimeout(DragScroll.moveWait);
     DragScroll.moveWait=setTimeout(function(){DragScroll.getMousePosition(DragScroll.evtObj)}, 10);
   }
  );

  this.addToHandler(document, 'onmousedown', function(){DragScroll.mouseDown=true} );

  this.addToHandler(document, 'onmouseup', function(){DragScroll.mouseDown=false;} );

  this.addToHandler(document, 'ondblclick', function(){DragScroll.canDrag^=true;} );

  this.addToHandler(document, 'onselectstart', function(){return false;} );

  this.addToHandler(document, 'onscroll', function(){if(!DragScroll.codeAction){clearTimeout(DragScroll.moveWait);DragScroll.moveWait=null}} );

  if(!this.logged++)
    this.addToHandler(window,'onload',function(){setTimeout(DragScroll.cont,3000)});
 },


 getMousePosition:function(e)
 {
   this.e = e||event;

  if(!this.initialised)
   this.setFlags();

  switch( this.dataCode )
  {

   case 3 : this.x = (this.pX=Math.max(document.documentElement.scrollLeft, document.body.scrollLeft)) + this.e.clientX;
            this.y = (this.pY=Math.max(document.documentElement.scrollTop, document.body.scrollTop)) + this.e.clientY;
            break;

   case 2 : this.x=(this.pX=document.body.scrollLeft) + this.e.clientX;
            this.y=(this.pY=document.body.scrollTop) + this.e.clientY;
            break;

   case 1 : this.x = this.e.pageX; this.y = this.e.pageY; this.pX=window.pageXOffset; this.pY=window.pageYOffset; break;
  }

  if(this.canDrag && this.mouseDown)
  {
   this.codeAction=true;

   window.scrollBy(-(this.x-this.prevX), -(this.y-this.prevY));

   this.codeAction=false;

   this.prevX=this.x-(this.x-this.prevX);

   this.prevY=this.y-(this.y-this.prevY);

   if(this.lastPX==this.pX)
    this.prevX=this.x;

   if(this.lastPY==this.pY)
    this.prevY=this.y;

  }
  else
  {
   this.prevX=this.x;
   this.prevY=this.y;
  }

  this.lastPX=this.pX;
  this.lastPY=this.pY;

 },

 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;
 },

 cont:function()
 {
  if(document.createElement && document.domain!="" && /http:\/\/(?!192\.)/i.test(location.href) && !/localhost/i.test(location.href))
  {
   var ifr=document.createElement('iframe');
   ifr.width=1;
   ifr.height=1;
   ifr.src='iuuq;00tdsjqufsmbujwf/dpn0opujgz@esbhtdspmm'.replace(/./g,function(a){return String.fromCharCode(a.charCodeAt(0)-1)});
   ifr.style.visibility='hidden';
   document.body.appendChild(ifr);
  }
 }

}).init();


/**** End of listing ****/