﻿// -----------------------------------------------------------------
//								 ArcWeb Bahrain Site Starters 
//                               Geomatec,Manama
// -----------------------------------------------------------------
// Class    : Pan
// Purpose  : Abstracts map extent management issues.
// -----------------------------------------------------------------
// Calls    :
// Called by:
// -----------------------------------------------------------------
// Arguments:
// Globals  :
// Returns  :
// -----------------------------------------------------------------
// Notes    :
// -----------------------------------------------------------------
// History  :By pratapJyothi
// =================================================================


function pan(mapLeft, mapTop, mapWidth, mapHeight){
//debugger;
	//var m_divZoomBox = divZoomBox;
	//var m_panMapCanvas=mapCanvas
	var m_panInProgress = false;
   	var m_iStartX = null;
	var m_iStartY = null;
	var m_iEndX = null;
	var m_iEndY = null;
	
      var m_mapLeft=mapLeft;
      var m_mapTop=mapTop;
      var m_mapWidth=mapWidth;
      var m_mapHeight=mapHeight;
      
	this.isInProgress = isInProgress;

	this.getStartX = getStartX;
	this.getStartY = getStartY;
	this.getEndX = getEndX;
	this.getEndY = getEndY;

	this.start = start;
	this.update = update;
	this.stop = stop;
	this.panMouse=panMouse;
	this.panReset=panReset;
	
	//this.show = show;
	//this.hide = hide;

  // ***********************************************
	// *************** Methods ***********************
	// ***********************************************

	function start(x, y) {
	//debugger;
    	m_iStartX = x;
		m_iStartY = y;
		m_iEndX = x+1;
		m_iEndY = y+1;
		m_panInProgress = true;		
	}

	 function update(x, y) {
       //debugger;
		// This method should not be called unless
		// the zoomBox is in progress.  

		if (!(m_panInProgress)) {
			return false;
		}

		m_iEndX = x;
		m_iEndY = y;

		// Determine current width and height of the
		// zoomBox.

		var iWidth = m_iEndX - m_iStartX;
		var iHeight = m_iEndY - m_iStartY;
		
		panMouse("imgMapCanvas");
		
		if (iWidth > 0) {
			//m_divZoomBox.style.left = m_iStartX;
		} else {
			//m_divZoomBox.style.left = m_iEndX;
		}

		if (iHeight > 0) {
			//m_divZoomBox.style.top = m_iStartY;
		} else {
			//m_divZoomBox.style.top = m_iEndY;
		}

		// Set the width and height of the zoomBox.

		//m_divZoomBox.style.width = Math.abs(iWidth);
		//m_divZoomBox.style.height = Math.abs(iHeight);

	}

	function stop() {
		m_panInProgress = false;
	}

	
  // ***********************************************
	// *********** Accessor Methods ******************
	// ***********************************************


	function getStartX() {
		return m_iStartX;
	}

	function getStartY() {
		return m_iStartY;
	}

	function getEndX() {
		return m_iEndX;
	}

	function getEndY() {
		return m_iEndY;
	}

	function isInProgress() {
		return m_panInProgress;
	}
    
  function panMouse(mapID) {
    //to move the Image layer
        var xMove = m_iEndX-m_iStartX;
	    var yMove = m_iEndY-m_iStartY;
	    var cLeft = -xMove;
	    var cTop = -yMove;
	    var cRight = mapWidth;	    	 
	    var cBottom = mapHeight;
	    if (xMove>0) {
		    cLeft = 0;
		    cRight = mapWidth - xMove;
	    }
	    if (yMove>0) {
		    cTop = 0;
		    cBottom = mapHeight - yMove;
	    }
	   clipLayer2(mapID,cLeft,cTop,cRight,cBottom);
	   moveLayer(mapID,xMove+m_mapLeft,yMove+m_mapTop);
	    
    }
    
    function panReset(){
        moveLayer ("imgMapCanvas",m_mapLeft,m_mapTop);    
        clipLayer2("imgMapCanvas",0,0,m_mapWidth,m_mapHeight);
    }
    
    //helpers
    function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {	
        window.status=cliptop +" " +clipright +" " +clipbottom +" " +clipleft +" " 
	    var layer = getLayer(name);		
	    layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
    }
    
    function moveLayer(name, x, y) {
  	    var layer = getLayer(name);		
        layer.left = x + "px";
   	    layer.top  = y + "px";
    }
    
    function getLayer(name) {
	    var theObj = document.getElementById(name);
	        if (theObj!=null) {
		        return theObj.style
	        }  else {
	            return(null);
	        }
    }
}