/*
This class handles the DHTML necessary to visually represent a pan operation in ArcIMS client applications.
*/

function Pan(imgMapCanvas)
{
   //if imgMapCanvas is undefined then the constructor was called only for creating
   //the class prototype object for the assignment of instance functions
   if (imgMapCanvas)
   {
      //connect to the window imgMapCanvas
      this.imgMapCanvas = imgMapCanvas;
	
      //positioning of the imgMapCanvas must be absolute
      //relative causes lagging in the rendering
      this.imgMapCanvas.style.position = "absolute";
      
      //preset the panning flag
      this.panning = false;
   }
}

//main event handler function, this function handles all drawing based on events
function Pan_processEvent(e)
{
   switch (e.type)
   {
      case "mousedown":

	 if (!this.panning && e.button == 1)
	 {
            //envelope coordinates in pixels
            this.absOrigX = e.clientX;
            this.absOrigY = e.clientY;
            this.absDestX = e.clientX;
            this.absDestY = e.clientY;

	    //location of the mousedown relative to image for repositioning relative to cursor location
            this.dragPointX = e.offsetX;
            this.dragPointY = e.offsetY;

	    //initialize
	    this.imgMapCanvas.style.left = this.absOrigX - this.dragPointX;
	    this.imgMapCanvas.style.top = this.absOrigY - this.dragPointY;

            //switch panning on
            this.panning = true;
	 }

         break;

      case "mousemove":

         if (this.panning && e.button == 1)
         {
		//store current mouse location
	    this.absDestX = e.clientX;
	    this.absDestY = e.clientY;

	    // Rey - Original code the 2 lines below take action to transpose imgMapCanvas
	    //this.imgMapCanvas.style.left = this.absDestX - this.dragPointX;
	    //this.imgMapCanvas.style.top = this.absDestY - this.dragPointY;
		
		/* Added by Rey	*/
			var w;
			var h;
			var xm;
			var ym;
			var cl;
			var ct;
			
			h = 500; //559; //400;
			w = 440; //354; //400;
			xm = this.absDestX - this.dragPointX;
			
			cl = -cl;
			ym = this.absDestY - this.dragPointY;
			ct = -ct;
			cr = h;
			cb = w;
			if (xm>0) {
				cl = 0;
				cr = w - xm;
			}
			if (ym>0) {
				ct = 0;
				cb = h - ym;
			}			
		m_newLeft = 60 - xm;
		m_newTop = 65 - ym;
		m_newRight = 60 + cr;
		m_newBottom = 65 + cb;
		
	
		 //alert("mousemove");
         //break;
         
        // Rey - the 3 lines below does not work for Netscape
		clipLayer("imgMapCanvas",300-xm,30-ym,cr,cb-140);
		moveLayer("imgMapCanvas",xm,ym);
		//document.all.imgMapCanvas.style.pixelLeft = xm;
		//document.all.imgMapCanvas.style.pixelTop = ym;
		
         }
         break;

      case "mouseup":

	 if (this.panning && e.button == 1)
	 {
            //switch panning off
            this.panning = false;
	    //restore the imgMapCanvas to it's original location
	    alert("test");
	    this.imgMapCanvas.style.pixelleft = 100;
	    this.imgMapCanvas.style.pixeltop = 30;
		this.imgMapCanvas.style.pixelwidth = 440;
	    this.imgMapCanvas.style.pixelheight = 500;
	    moveLayer("imgMapCanvas", 130,30);
	 }
         break;
   }
}

//force the creation of a prototype object for assigning instance methods
new Pan();
Pan.prototype.processEvent = Pan_processEvent;
