function ZoomNavigator(parent)
{
	this.oCanvas = parent;
	
	this.oMiniMap = $('MiniMapContainer');
	this.oDraw = new SimpleCanvas('ZoomLines');
	
	this.oManIn = $('ManZoomIn');
	this.oManOut = $('ManZoomOut');

	this.oManInEvt = $('ManZoomInEvt');
	this.oManOutEvt = $('ManZoomOutEvt');

	addEvent(this.oManInEvt, "click", function(evt){ if(evt = checkEvent(evt) && (matchClass(evt.target, 'selected') || matchClass(evt.target.parentNode, 'selected'))){ zoom(0); } })
	addEvent(this.oManOutEvt, "click", function(evt){ if(evt = checkEvent(evt) && (matchClass(evt.target, 'selected') || matchClass(evt.target.parentNode, 'selected'))){ zoom(0); } })
	
	this._MMwidth = this.oMiniMap.offsetWidth;
	this._MMheight = this.oMiniMap.offsetHeight;
	this.oRect = $('ZoomRect');
	this.onResize();
	this.onDrag();
	
	
	//this.oMiniMap.style.border = '1px solid red';
	
}

ZoomNavigator.prototype.onResize = function ()
{
	if (this.oCanvas._cZoom == 1)
	{
		this.oRect.style.display = 'block';
		this.oRect.style.width = (this._width = Math.floor(this._MMwidth*(aWindowSize[0]/this.oCanvas._width)) - (isMSIE?-1:1)*2) + 'px';
		this.oRect.style.height = (this._height = Math.floor(this._MMheight*(aWindowSize[1]/this.oCanvas._height)) - (isMSIE?-1:1)*2) + 'px';
	}
	else
	{
		this.oRect.style.display = 'none';
	}
	
	
	var oMMCoord = getAbsolutePos(this.oMiniMap);
	this._MMx = oMMCoord.x;
	this._MMy = oMMCoord.y;
	
	
	
}
ZoomNavigator.prototype.onDrag = function ()
{
	this.oRect.style.left = (this._x = Math.floor(-this.oCanvas._x*(this._MMwidth/this.oCanvas._width))) + 'px';
	this.oRect.style.top = (this._y = Math.floor(-this.oCanvas._y*(this._MMheight/this.oCanvas._height)) - 1) + 'px';
	if(this.oManIn && this.oManOut)
		this.redrawLines();
	
}

ZoomNavigator.prototype.redrawLines = function (){
	this.oDraw.clear();
	if(this.oCanvas._cZoom == 1){
		/* In */
		
		removeClass(this.oManOut, "selected");
		removeClass(this.oManInEvt, "selected");
		addClass(this.oManIn, "selected");
		addClass(this.oManOutEvt, "selected");
		
		this.oDraw.drawLine({x: this.oManIn.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oRect.offsetLeft+this.oRect.offsetWidth+20), y: (this.oRect.offsetTop+this.oRect.offsetHeight)}, {color: '#EF7876', width: 1});
		this.oDraw.drawLine({x: this.oManIn.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oRect.offsetLeft+this.oRect.offsetWidth+20), y: (this.oRect.offsetTop + 1)}, {color: '#EF7876', width: 1});
	} else {
		/* Out */
		removeClass(this.oManIn, "selected");
		removeClass(this.oManOutEvt, "selected");
		addClass(this.oManOut, "selected");
		addClass(this.oManInEvt, "selected");
		
		if (this.oCanvas._restrictions)
		{

			var cX = -Math.round((this.oCanvas._restrictions.minX - aWindowSize[0] + this.oCanvas._zWidth)*(this._MMwidth/this.oCanvas._zWidth));
			var cY1 = -Math.round(this.oCanvas._restrictions.maxY*(this._MMheight/this.oCanvas._zHeight));
			var cY2 = -Math.round((this.oCanvas._restrictions.minY - aWindowSize[1] + this.oCanvas._zHeight)*(this._MMheight/this.oCanvas._zHeight));
			
			//document.title = cX + ' : ' + this.oCanvas._width/this.oCanvas._cZoom + ' : ' + this.oCanvas._zWidth;
			
			this.oDraw.drawLine({x: this.oManOut.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oMiniMap.offsetLeft + this.oMiniMap.offsetWidth + cX), y: (this.oMiniMap.offsetTop+this.oMiniMap.offsetHeight + cY2)}, {color: '#EF7876', width: 1});
			this.oDraw.drawLine({x: this.oManOut.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oMiniMap.offsetLeft+this.oMiniMap.offsetWidth + cX), y: this.oMiniMap.offsetTop+1 + cY1}, {color: '#EF7876', width: 1});
			
//			debug(this.oDraw.Renderer.getContext());
			
		}
		else
		{
			this.oDraw.drawLine({x: this.oManOut.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oMiniMap.offsetLeft+this.oMiniMap.offsetWidth), y: (this.oMiniMap.offsetTop+this.oMiniMap.offsetHeight-1)}, {color: '#EF7876', width: 1});
			this.oDraw.drawLine({x: this.oManOut.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oMiniMap.offsetLeft+this.oMiniMap.offsetWidth), y: this.oMiniMap.offsetTop+1}, {color: '#EF7876', width: 1});
		}
	}
}

ZoomNavigator.prototype.startDrag = function (ev)
{
	if (!this.oCanvas._zoomed && this.oCanvas.blockDrag)
		return false;
	if (ev = checkEvent(ev))
	{
		var oDelta={x: ev.clientX, y: ev.clientY};
		var oPos=getAbsolutePos(this.oRect);
		oOffset={x: oPos.x - oDelta.x, y: oPos.y - oDelta.y};
		
		if (oOffset.x > 0 || oOffset.x < -this._width || oOffset.y > 0 || oOffset.y < -this._height)
		{
			return this.oCanvas.startDrag(ev);
		}
		
		if (this.oCanvas._xyTween)
		{
			this.oCanvas._xyTween.stop();
			this.oCanvas._xyTween = false;
		}
		addEvent(document, 'mousemove', doDrag);
		return CancelEvent(ev);
		
	}
}

ZoomNavigator.prototype.doDrag = function (ev)
{
	if (this.oCanvas._drag)
	{
		return this.oCanvas.doDrag(ev);
	}
	else if((ev=checkEvent(ev))){
		
		var newX, newY;
		//*(this.oCanvas._width/this.oMiniMap.offsetWidth)
		
		newX = Math.floor(-(ev.clientX - this._MMx + oOffset.x)*(this.oCanvas._width/this._MMwidth));
		newY = Math.floor(-(ev.clientY - this._MMy + oOffset.y)*(this.oCanvas._height/this._MMheight));
		
		if (!this.oCanvas._restrictions)
		{
			this.oCanvas.oElem.style.left=(this.oCanvas._x = newX)+'px';
			this.oCanvas.oElem.style.top=(this.oCanvas._y = newY)+'px';
		}
		else
		{
			this.oCanvas.oElem.style.left = (this.oCanvas._x = Math.min(Math.max(this.oCanvas._restrictions.minX,newX),this.oCanvas._restrictions.maxX)) + 'px';
			this.oCanvas.oElem.style.top = (this.oCanvas._y = Math.min(Math.max(this.oCanvas._restrictions.minY,newY),this.oCanvas._restrictions.maxY)) + 'px';
		}
		//debug(this._x + ' : ' + this._y);
		this.oCanvas.onDrag(ev);
	}
	
}

ZoomNavigator.prototype.stopDrag = function (ev)
{
	if (this.oCanvas._drag)
		this.oCanvas._drag = false;
	removeEvent(document, 'mousemove', doDrag);
}



