/*
COPYRIGHT 1995-2005 ESRI

TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
Unpublished material - all rights reserved under the 
Copyright Laws of the United States.

For additional information, contact:
Environmental Systems Research Institute, Inc.
Attn: Contracts Dept
380 New York Street
Redlands, California, USA 92373

20050921

email: contracts@esri.com
*/

// display_overview.js
	// Dependent on display_common.js, and assumes that display_common.js has been loaded prior to this file. 

var ovZIndex = 9990;

var ovPanStartLeft = 0;
var ovPanStartTop = 0;
var ovXOffset = 0;
var ovYOffset = 0;

var ovMoveCount = 0;
var ovMoveMax = 5;

function OverviewObject(controlName, width, height, boxLeft, boxTop, boxWidth, boxHeight, boxColor, lineWidth, lineType) {
	inheritsFrom(new ControlObject(controlName, "Overview", 0, 0, width, height), this);
	this.index = 0;
	this.right = width;
	this.bottom = height;
	this.boxLeft = boxLeft;
	this.boxTop = boxTop;
	this.boxWidth = boxWidth;
	this.boxHeight = boxHeight;
	this.boxRight = boxLeft + boxWidth;
	this.boxBottom = boxTop + boxHeight;
	this.boxColor = (boxColor==null) ? "Red" : boxColor;
	this.lineWidth = (lineWidth==null) ? 3: lineWidth;
	this.lineType = (lineType==null) ? "solid" : lineType;
	
	this.divId = "OVDiv_" + controlName;
	this.imageId = "OVImage_" + controlName;
	this.boxDivId = "OVBoxDiv_" + controlName;
	this.boxImageId = "OVBoxImage_" + controlName;
	this.containerDivId = "OVControlDiv_" + this.controlName;
	this.boxResizeDivId = "OVBoxResizeDiv_" + this.controlName;
	this.newBoxDivId = "OVNewBoxDiv_" + this.controlName;
	this.boxDivObject = null;
	this.imageObject = null;
	this.loadingObject = null;
	this.containerObject = null;
	this.boxResizeObject = null;
	this.newBoxObject = null;
	
	this.mapId = "";
	this.mapIdSet = false;
	this.dragOVBox = false;
	this.centerX = 0;
	this.centerY = 0;
	this.boxOpacity = 35;
	
	var ovTempMessage = "";
	var ovTempContext = "";
	this.windowObject = ovWindow;
	
	this.mapXRatio = 1;
	this.mapYRatio = 1;
	
	this.ovMinWidth = 15;
	this.ovMinHeight = 15;
	this.aoiResizable = true;
	this.aoiDraggable = true; //whether the aoi will be draggable
	// .NET ClientPostback properties
	this.pageID = "";
	this.enableClientPostBack = false;
	
	this.callBackFunctionString = null;
	
	this.autoAdjustExtent = true;   // if true, ov will auto adjust extent
	//this.autoAdjustFactor = 2; // ov will use this factor for auto-adjusting extent in or out
	this.minBoxPercentage = 25; // minimum percentage box size can be before auto-adjusting extent
	this.maxBoxPercentage = 90; // maximum percentage box size can be before auto-adjusting extent
	this.autoAdjustCall = 0;

	this.createDivs = function(imageUrl, blankurl, toolTip, cellName) {
	        // keep displayed aoi box within display area
	        var leftAdjust = 0;
	        var topAdjust = 0;
            if (boxLeft<0) {
                leftAdjust = boxLeft; 
                boxLeft = 0;
            }
            if (boxTop<0) {
                topAdjust = boxTop; 
                boxTop = 0;
            }
		    if (this.boxLeft + this.boxWidth+(this.lineWidth*2)>=this.width) this.boxWidth = this.width - this.boxLeft-(this.lineWidth*2) + leftAdjust;
		    if (this.boxTop + this.boxHeight+(this.lineWidth*2)>=this.height) this.boxHeight = this.height - this.boxTop-(this.lineWidth*2) + topAdjust; 

			// Create the client code 
		var s = "";
			// The overall container... position is relative... in flow
				// add table if no cellName.... if passed, it is assumed that width has been also defined as shown below
		if ((cellName==null) || (cellName=="")) s += '<table cellspacing=0 cellpadding=0 width=' + this.width + '><tr><td id="OVCell_' + this.controlName + '">';
		s += '<div id="OVControlDiv_' + this.controlName+ '" style="position: relative; background-color: White; width: ' + this.width + 'px; height: ' + this.height + 'px; overflow:hidden;">\n';	
			// OV div, holds map image ... position is absolute within container
		s += '<div id="' + this.divId + '" style="position: absolute; left: 0px; top: 0px; background-color: White; width: ' + this.width + 'px; height: ' + this.height + 'px; overflow:hidden;">\n';
			// Map image... 
		s += '	<img id="' + this.imageId + '" alt="' + toolTip + '"  title="' + toolTip + '" src="' + imageUrl + '" width="' + this.width + '" height="' + this.height + '" hspace="0" vspace="0" border="0">\n';
		s += '</div>\n';
		
			// OVBox div, holds blank image ... position is absolute within container
		style = "border: " + this.lineWidth + "px " + this.lineType + " " + this.boxColor + ";";
//		var opac = this.boxOpacity / 100;
//		var platform = navigator.platform;
//		if ((platform=="Win32") || ((platform=="MacPPC") && (!isIE))) {
//			if (navigator.userAgent.indexOf("Opera")==-1) {
//				style += "background-color: White; opacity: " + opac + "; -moz-opacity: " + opac + "; filter: alpha(opacity=" + this.boxOpacity + ");";
//			}
//		}
		var visible = (this.boxWidth>0 && this.boxHeight>0) ? "visible" : "hidden";
		s += '<div id="' + this.boxDivId + '" style="position: absolute; left: ' + this.boxLeft + 'px; top: ' + this.boxTop + 'px;' + style + ' width: ' + this.boxWidth + 'px; height: ' + this.boxHeight + 'px; overflow:hidden; visibility: ' + visible + ';">\n';
			// blank image... 
		s += '	<img id="' + this.boxImageId + '" alt="' + toolTip + '"  title="' + toolTip + '" src="' + blankurl + '" width="100%" height="100%" hspace="0" vspace="0" border="0">\n';
		s += '</div>\n';
		// resize hot spot
	    if (this.aoiResizable)
	    {  
            s += '<div id="' + this.boxResizeDivId + '" style="position: absolute; left: ' + (this.boxLeft + this.boxWidth - 8) + '; top: ' + (this.boxTop + this.boxHeight - 8) + '; cursor: nw-resize; width: 10px; height: 10px; overflow:hidden;" ';
            s += 'onmousedown="ovBoxResizeStart(event, \'' + this.controlName + '\'); return false;" ';
            s+=' >\n';
            s += '	<img  alt="Resize AOI"  title="Resize AOI" src="' + blankurl + '" width="10" height="10" hspace="0" vspace="0" border="0" >\n';
            s += '</div>\n';
        }
		s += '<div id="' + this.newBoxDivId + '" style="position: absolute; left: -1px; top: -1x; width: 1px; height: 1px; overflow:hidden; visibility: hidden; border: thin dashed black;">\n';
		s += '</div>\n';
		s += '</div>\n';
        // alert(s);		
		if ((cellName==null) || (cellName=="")) {
			s += '</td></tr></table>';
			if (this.windowObject!=null)
				this.windowObject.setContents(s);
			else
				document.writeln(s);
		} else {
			var obj = document.getElementById(cellName);	
			obj.innerHTML = s;
		}
		this.setObjects();
		if (overviewCallbackFunctionString!=null && overviewCallbackFunctionString!="")
		    this.enableClientPostBack = overviewCallbackFunctionString;
	}
	
	this.setObjects = function() {
		this.divObject = document.getElementById(this.divId);
		this.boxDivObject = document.getElementById(this.boxDivId);
		this.imageObject = document.images[this.imageId];
		this.containerObject = document.getElementById(this.containerDivId);
		this.boxResizeObject = document.getElementById(this.boxResizeDivId);
		this.newBoxObject = document.getElementById(this.newBoxDivId);
		OverviewNames[OverviewNames.length] = this.controlName;
		if (this.aoiDraggable) 
		    this.setEvents();
		if (this.aoiResizable) 
		    this.setAOIResizable(this.aoiResizable);
	}
	
	this.setEvents = function() {
		this.boxDivObject.style.cursor = "move";
		this.boxDivObject.onmousedown = ovDragStart;

		this.divObject.style.cursor = "default";
		//this.divObject.onmousedown = ovNewBoxStart;
		if (!this.mapIdSet) this.setMapBuddy();
		this.updateMapRatio();
		
	}
	
	this.update = function(boxLeft, boxTop, boxWidth, boxHeight) {
	    var argument = "";
	    var context = this.controlName;
	    boxLeft = parseInt(boxLeft);
	    boxTop = parseInt(boxTop);
	    boxWidth = parseInt(boxWidth);
	    boxHeight = parseInt(boxHeight);
	    var bHalfWidth = Math.floor(boxWidth/2);
	    var bHalfHeight = Math.floor(boxHeight/2);
	    var widthRatio = boxWidth / this.width * 100;
	    var heightRatio = boxHeight / this.height * 100;
	    var leftAdjust = 0;
	    var topAdjust = 0;
	    this.boxDivObject.style.visibility = (boxWidth>0 && boxHeight>0) ? "visible" : "hidden";
	    //alert (widthRatio + "\n" + heightRatio);
        if (this.autoAdjustCall==0 && this.autoAdjustExtent && (widthRatio < this.minBoxPercentage || heightRatio < this.minBoxPercentage || widthRatio > this.maxBoxPercentage || heightRatio > this.maxBoxPercentage)) {
            argument = "ControlType=OverviewMap&EventArg=OverviewZoom";
            eval(this.callBackFunctionString);
            this.autoAdjustCall++;
            
        } else if (this.autoAdjustCall==0 && this.autoAdjustExtent && ((boxLeft < 0) || (boxTop < 0) || (boxLeft + boxWidth+(this.lineWidth*2) > this.width) || (boxTop + boxHeight+(this.lineWidth*2) > this.height))) {
            argument = "ControlType=OverviewMap&EventArg=OverviewPan";
            eval(this.callBackFunctionString);
            this.autoAdjustCall++;
        
        } else {
	        // keep displayed aoi box within display area
            if (boxLeft<0) {
                leftAdjust = boxLeft; 
                boxLeft = 0;
            }
            if (boxTop<0) {
                topAdjust = boxTop; 
                boxTop = 0;
            }
		    if (boxLeft + boxWidth+(this.lineWidth*2)>=this.width) boxWidth = this.width - boxLeft-(this.lineWidth*2) + leftAdjust;
		    if (boxTop + boxHeight+(this.lineWidth*2)>=this.height) boxHeight = this.height - boxTop-(this.lineWidth*2) + topAdjust; 
		   	if (!this.autoAdjustExtent) //if static image mode, do not let width/height become negative.
            { 
		        var diff;
                if (boxWidth < this.ovMinWidth) 
                {
                    if (boxWidth < 0) boxWidth = 0;
                    diff = this.ovMinWidth - boxWidth;
                    if ( (boxLeft - diff) >= 0)
                        boxLeft = boxLeft - diff;
                    boxWidth = this.ovMinWidth;
                }
                if (boxHeight < this.ovMinHeight)
                {
                    if (boxHeight < 0) boxHeight = 0;
                    diff = this.ovMinHeight - boxHeight;
                    if ( (boxTop - diff) >= 0)
                        boxTop = boxTop - diff;
                    boxHeight = this.ovMinHeight;
                }
           } 

		    this.boxLeft = boxLeft;
		    this.boxTop = boxTop;
		    this.boxWidth = boxWidth;
		    this.boxHeight = boxHeight;
		    this.boxRight = boxLeft + boxWidth;
		    this.boxBottom = boxTop + boxHeight;
    		
		    this.boxDivObject.style.left = boxLeft + "px";
		    this.boxDivObject.style.top = boxTop + "px";
		    this.boxDivObject.style.width = boxWidth + "px";
		    this.boxDivObject.style.height = boxHeight + "px";
		   
		    if (this.boxResizeObject != null)//null when not resizable
            {
		        this.boxResizeObject.style.left = (boxLeft + boxWidth - 8) + "px";
		        this.boxResizeObject.style.top = (boxTop + boxHeight - 8) + "px";
		    }
		    if (!this.mapIdSet) this.setMapBuddy();
		    this.updateMapRatio();
		    this.autoAdjustCall=0;
//		    if (this.mapId!="")
//		        Maps[this.mapId].updateMapDiv2();
	    }
	}
	
	this.updateImage = function(imageUrl) {
		this.imageObject.src = imageUrl;
		if (!this.mapIdSet) this.setMapBuddy();
	}
	
	this.parseUpdateString = function(response) {
	    //alert(response);
	    var r = response.split(":::");
        this.update(r[3], r[4], r[5], r[6]);
        if (r.length>7)
            this.updateImage(r[7]);
	    
	}
	
	this.hide = function() {
		hideLayer(this.divId);
	}
	
	this.show = function() {
		showLayer(this.divId);
	}
	
	this.resize = function(width, height) {
		this.width = width;
		this.height = height;
		this.containerObject.style.width = width + "px";
		this.containerObject.style.height = height + "px";
		this.divObject.style.width = width + "px";
		this.divObject.style.height = height + "px";
		var imageUrl = this.imageObject.src;
		var toolTip = (isIE) ? this.imageObject.alt : this.imageObject.title;
		this.divObject.innerHTML = 	'	<img id="' + this.imageId + '" alt="' + toolTip + '"  title="' + toolTip + '" src="' + imageUrl + '" width="' + this.width + '" height="' + this.height + '" hspace="0" vspace="0" border="0">\n';

	}
	
	this.setMapBuddy = function() {
	    if (this.mapId!=null && this.mapId!="") {
	        var m = Maps[this.mapId];
	        if (m!=null) {
	            m.overviewId = this.controlName;
	            this.mapIdSet = true;
	        }
	    }
	}
	
	this.updateMapRatio = function() {
	    var m = Maps[this.mapId];
	    if (m!=null) {
	        this.mapXRatio = m.viewWidth / this.boxWidth;
	        this.mapYRatio = m.viewHeight / this.boxHeight;
	    }
	    //alert(this.mapId + " ..... " + this.mapXRatio + " ..... " + this.mapYRatio);
	
	}
	
	this.getAOIBox = function() {
	    // Debug stuff to be removed, or at least commented out
    if (checkForFormElement(document, 0, "MapDebugBox")) document.forms[0].MapDebugBox.value += ("Overview Request: OverviewAOIExtent"); 

	    var argument = "ControlType=OverviewMap&EventArg=OverviewAOIExtent";
	    var context = this.controlName;
	    eval(this.callBackFunctionString);
	}
	
	this.setAOIResizable = function(setIt) {
	    if (setIt==null) setIt = true;
	    this.aoiResizable = setIt;
	    this.boxResizeObject.visibility = (setIt) ? "visible" : "hidden";
	}

}

///////////////////////////////////// Mouse Down/Move/Up/Click Functions /////////////////////////////////////

/// need to be updated to object stuff!!!!!

// Start overview AOI move action - mouse down
function ovDragStart(e) {
	if (isLeftButton(e)) {
		getXY(e);
		ov = getOVObjectByXY(mouseX, mouseY,true);
		if (ov!=null) {
			if (!ov.dragOVBox) {
				ov.dragOVBox = true;
				ovPanStartLeft = parseInt(ov.boxDivObject.style.left);
				ovPanStartTop = parseInt(ov.boxDivObject.style.top);
    			ov.boxDivObject.onmousemove = ovDragMove;
				ov.boxDivObject.onmouseup = ovDragUp;
				ov.divObject.onmousemove = ovDragMove;
				ov.divObject.onmouseup = ovDragUp;
				x1 = mouseX;
				y1 = mouseY;
				x2 = mouseX;
				y2 = mouseY;
				
				
				    if (!this.mapIdSet) ov.setMapBuddy();
				    var m = Maps[ov.mapId];
				    if (m!=null) {
				        map = m;
					    panStartLeft = parseInt(map.divObject.style.left);
					    panStartTop = parseInt(map.divObject.style.top);
					    ov.updateMapRatio();
		                map.dragImage = true;
		                //window.status = "pl:" + panStartLeft + ", " + panStartTop;
		                ovMoveCount = 0;
		                if (m.vectorObject!=null) m.vectorObject.restart();
		            }
			}
		}
	}
	return false;
}

// OV AOI move action - mouse move
function ovDragMove(e) {
	getXY(e);
	if (ov!=null) {
		if (ov.dragOVBox) {
			x2 = mouseX;
			y2 = mouseY;
            var ex = ovPanStartLeft + (x2 - x1);
            var ey = ovPanStartTop + (y2 - y1);

			// move div
			moveLayer(ov.boxDivId,ex,ey);
			moveLayer(ov.boxResizeDivId, ex + ov.boxWidth - 8, ey + ov.boxHeight - 8);
			// move Main map, but only every ovMoveMax time
			if (map!=null && map.controlName==ov.mapId) {
			    if (ovMoveCount/ovMoveMax==Math.floor(ovMoveCount/ovMoveMax)) {
			        nx = 0 - Math.round((x2 - x1) * ov.mapXRatio);
			        ny = 0 - Math.round((y2 - y1) * ov.mapYRatio);
		            var currentX = panStartLeft + nx;
		            var currentY = panStartTop + ny;
			        map.moveTiles(currentX, currentY, "");
			        //window.status = currentX + ", " + currentY;
			    }
			}
			ovMoveCount++;
		}
	}
	return false
}

// overview AOI up actions - mouse up
function ovDragUp(e) {
	//alert("ovDragUp");
	getXY(e);
	if (ov!=null) {
		if (ov.dragOVBox) {
			ov.boxDivObject.onmousemove = null;
			ov.boxDivObject.onmouseup = null;
			ov.divObject.onmousemove = null;
			ov.divObject.onmouseup = null;
			ov.dragOVBox=false;
			//divObj.style.cursor = "wait";
			getXY(e);
			var bx = mouseX - ov.left;
			var by = mouseY - ov.top;
			var ovboxw = parseInt(ov.boxWidth / 2);
			var ovboxh = parseInt(ov.boxHeight / 2);
			ov.centerX=bx;
			ov.centerY=by;
			if (map!=null && map.controlName==ov.mapId) {
			        nx = 0 - Math.round((x2 - x1) * ov.mapXRatio);
			        ny = 0 - Math.round((y2 - y1) * ov.mapYRatio);
		            var currentX = panStartLeft + nx;
		            var currentY = panStartTop + ny;
			        map.moveTiles(currentX, currentY, "");
			    map.dragImage = false;
			    finishDragImage(map);
			}
			return false;
		}
	}
}



/********* AOI Resizing functions *********/
// incomplete... needs work

function ovBoxResizeStart(e, controlName) {
	if (isLeftButton(e)) {
		getXY(e);
        if (controlName!=null)
            ov = Overviews[controlName];
        else
		    ov = getOVObjectByXY(mouseX, mouseY,true);
		if (ov!=null) {
			ovPanStartLeft = parseInt(ov.boxDivObject.style.left);
			ovPanStartTop = parseInt(ov.boxDivObject.style.top);
			ov.boxResizeObject.onmousemove = ovBoxResizeDrag;
			ov.boxResizeObject.onmouseup = ovBoxResizeEnd;
			ov.boxDivObject.onmousemove = ovBoxResizeDrag;
			ov.boxDivObject.onmouseup = ovBoxResizeEnd;
			ov.divObject.onmousemove = ovBoxResizeDrag;
			ov.divObject.onmouseup = ovBoxResizeEnd;
			
			ovTempWidth = parseInt(ov.boxDivObject.style.width);
			ovTempHeight = parseInt(ov.boxDivObject.style.height);
			
			x1 = mouseX;
			y1 = mouseY;
			x2 = mouseX;
			y2 = mouseY;
				
		    ov.setMapBuddy();
		}
    }
    return false;
}

function ovBoxResizeDrag(e) {
    getXY(e);
	x2 = mouseX;
	y2 = mouseY;
	var ovXOffset = x2 - x1;
	var ovYOffset = y2 - y1;
	var width = ovTempWidth + (ovXOffset * 2);
	var height = ovTempHeight + (ovYOffset * 2);
	var whRatio = 1;
	
	var owidth =  (width > ov.ovMinWidth) ? width : ov.ovMinWidth;
	var oheight = (height > ov.ovMinHeight) ? height : ov.ovMinHeight;

    ov.boxDivObject.style.width = owidth + "px";
    ov.boxDivObject.style.height = oheight + "px";
    if (width > ov.ovMinWidth) ov.boxDivObject.style.left =  (ovPanStartLeft - ovXOffset) + "px";
    if (height > ov.ovMinHeight) ov.boxDivObject.style.top =  (ovPanStartTop - ovYOffset) + "px"; 
    ov.boxWidth = oheight;
    ov.boxHeight = oheight;
    
    return false;
}

function ovBoxResizeEnd(e) {
	ov.boxDivObject.onmousemove = null;
	ov.boxDivObject.onmouseup = null;
	ov.divObject.onmousemove = null;
	ov.divObject.onmouseup = null;
	ov.boxResizeObject.onmousemove = null;
	ov.boxResizeObject.onmouseup = null;
    ov.autoAdjustCall=0;
    var ovXOffset = x2 - x1;
	var ovYOffset = y2 - y1;
	var width = ovTempWidth + (ovXOffset * 2);
	var height = ovTempHeight + (ovYOffset * 2);
    //keep width and height positive
    if (width < ov.ovMinWidth) 
        ovXOffset = (ov.ovMinWidth - ovTempWidth) / 2;
    if (height < ov.ovMinHeight) 
        ovYOffset = (ov.ovMinHeight - ovTempHeight) / 2;
 
    var m = null;
    if (ov.mapId!="")
        m = Maps[ov.mapId];
    if (m!=null) {
	    m.xMin =Math.round((0 - ovXOffset) * ov.mapXRatio);
	    m.yMin=Math.round((0 - ovYOffset) * ov.mapYRatio);
	    m.xMax=Math.round((ovTempWidth + ovXOffset) * ov.mapXRatio);
	    m.yMax=Math.round((ovTempHeight + ovYOffset) * ov.mapYRatio);
	    m.tempMode = m.mode;
	    m.mode = m.defaultShiftMode;
	    postBack(m.controlName, m.defaultAltAction);
        //window.setTimeout('Maps["' + m.controlName + '"].mode = "' + tempMode + '";', 300); 
    }
    return false;
}

function ovBoxResizeDrag_original(e) {
    getXY(e);
	x2 = mouseX;
	y2 = mouseY;
	
	var width = ovTempWidth + (x2 - x1);
	var height = ovTempHeight + (y2 - y1);
	width =  (width < ov.MinWidth) ? ov.MinWidth : width;
	height = (height < ov.MinHeight) ? ov.MinHeight : height;
	
    ov.boxDivObject.style.width = width + "px";
    ov.boxDivObject.style.height = height + "px";
    ov.boxWidth = width;
    ov.boxHeight = height;
    
    return false;
}
function ovBoxResizeEnd_original(e) {
	ov.boxDivObject.onmousemove = null;
	ov.boxDivObject.onmouseup = null;
	ov.divObject.onmousemove = null;
	ov.divObject.onmouseup = null;
	ov.boxResizeObject.onmousemove = null;
	ov.boxResizeObject.onmouseup = null;
    ov.autoAdjustCall=0;
    var m = null;
    if (ov.mapId!="")
        m = Maps[ov.mapId];
    if (m!=null) {
	    m.xMin=0;
	    m.yMin=0;
	    m.xMax=Math.round(ov.boxWidth * ov.mapXRatio);
	    m.yMax=Math.round(ov.boxHeight * ov.mapYRatio);
	    m.tempMode = m.mode;
	    m.mode = "MapZoomIn";
	    postBack(m.controlName, 'DragRectangle');
        //window.setTimeout('Maps["' + m.controlName + '"].mode = "' + tempMode + '";', 300); 
    }
    return false;
}



function getOVObjectByXY(x,y,getdimensions) {
	var mm = null;
	for (var i=0;i<OverviewNames.length;i++) {
		var m = Overviews[OverviewNames[i]];
		var box = calcElementPosition(m.divId);
		var right = box.left + box.width;
		var bottom = box.top + box.height;
		if ((x>=box.left) && (x<=right) && (y>=box.top) && (y<=bottom)) {
			mm = m;
			if (getdimensions) {
				m.left = box.left;
				m.top = box.top;
				m.width = box.width;
				m.height = box.height;
				m.right = right;
				m.bottom = bottom;
			}
		}
		box=null;
	}
	return mm;
}


function getOVDivObject(e, getdimensions) {
	var m = null
	var d = (isNav && e != null) ? e.target : window.event.srcElement;
	//alert (d.id);
	var control = "none";
	if ((d!=null) && (d.tagName!=null)) {
		// make sure its the div that we are selecting, and not the image
		if (d.tagName.indexOf("DIV")==-1) d = d.offsetParent;
		if ((d.id!=null) && (d.id!="")) {
			//window.status = d.id;
			if (d.id.indexOf("OVBoxDiv_")!=-1)
				control = d.id.substring(9);
			else
				control = d.id.substring(6);
			//alert(control);
			if (Overviews[control]!=null) {
				m = Overviews[control];
				if (getdimensions) {
					var box = calcElementPosition(m.divId);
					m.left = box.left;
					m.top = box.top;
					m.width = box.width;
					m.height = box.height;
					m.right = box.left + box.width;
					m.bottom = box.top + box.height;
					box=null;
				}
			}
		}
	}
	return m;
}

function createOverviewMapObject(controlName, width, height, boxLeft, boxTop, boxWidth, boxHeight, mapBuddyId, cellName, imageUrl, blankUrl, toolTip, boxColor, lineWidth, lineType, aoiResizable, aoiDraggable) {
    if (lineType==null) lineType = "solid";
    Overviews[controlName] = new OverviewObject(controlName, width, height, boxLeft, boxTop, boxWidth, boxHeight, boxColor, lineWidth, lineType);
    ov = Overviews[controlName];
    if (aoiResizable!=null) ov.aoiResizable = aoiResizable;
    if (aoiDraggable!=null) ov.aoiDraggable = aoiDraggable;   
    ov.createDivs(imageUrl, blankUrl, toolTip, cellName);
    ov.mapId = mapBuddyId;
}



///////////////////////////////////// Mouse Down/Move/Up/Click Functions /////////////////////////////////////
//alert("display_overview.js");

