function MapControls(container, mapObject, app) {
	this.Application = app;
	this.mapObject = mapObject;
	mapObject.ControlPanel = this;
	this.map = mapObject.map;
	this.arHistory = new Array();
	this.ImagesBasePath = this.Application.ImagesBasePath;
	this.BackgroundColor = '#F0F0F0';
	this.font = 'Verdana, Arial, Helvetica, sans-serif';
	this.fontColor = '#000000';
	this.fontBold = 'bold';
	this.fontSize = '8pt';
	this.Box = document.createElement('DIV');
	this.Box.style.position = 'relative';
	this.Box.style.display = 'block';
	this.Box.style.width = '226px';
	this.Box.style.height = '160px';
	this.Box.style.border = '0px inset silver';
	this.Box.style.overflow = 'hidden';
	this.Box.style.fontFamily = this.font;
	this.Box.style.fontSize = this.fontSize;
	this.Box.style.textAlign = 'center';
	this.Box.style.backgroundColor = 'transparent';
	if (container == null) {
		if (containerId != null) {
			container = document.getElementById(containerId);
		}
	}
	if (container == null) {
		container = document.body;
	}
	container.appendChild(this.Box);

/*
	var sTable = '<table id="tblZoomControls" style=\"position: absolute;\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">';
	sTable += '<tr><td>&nbsp;</td></tr>';
	sTable += '</table>';
	this.Box.innerHTML = sTable;
	var tbl = document.getElementById('tblZoomControls');
	with (tbl.style) {
		left = '33px';
		top = '64px';
		width = '160px';
		height = '54px';
	}
*/
	
	this.BtnTypeMap = document.createElement('DIV');
	this.BtnTypeMap.style.position = 'absolute';
	this.BtnTypeMap.style.display = 'block';
	this.BtnTypeMap.style.border = '0px outset silver';
	this.BtnTypeMap.style.left = '4px';
	this.BtnTypeMap.style.top = '4px';
	this.BtnTypeMap.style.width = '69px';
	this.BtnTypeMap.style.height = '24px';
	this.BtnTypeMap.style.cursor = 'pointer';
	this.BtnTypeMap.style.textAlign = 'center';
	this.BtnTypeMap.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_map.jpg)';
	this.Box.appendChild(this.BtnTypeMap);
	//this.Box.insertBefore(this.BtnTypeMap, document.getElementById('tblZoomControls'));
	this.BtnTypeMap.owner = this;
	this.BtnTypeMap.idaction = 'map';
	this.Application.bindEvent(this.BtnTypeMap, 'click', this, this.buttonsHandler);

	this.BtnTypeSat = document.createElement('DIV');
	this.BtnTypeSat.style.position = 'absolute';
	this.BtnTypeSat.style.display = 'block';
	this.BtnTypeSat.style.border = '0px outset silver';
	this.BtnTypeSat.style.left = '77px';
	this.BtnTypeSat.style.top = '4px';
	this.BtnTypeSat.style.width = '69px';
	this.BtnTypeSat.style.height = '24px';
	this.BtnTypeSat.style.cursor = 'pointer';
	this.BtnTypeSat.style.textAlign = 'center';
	this.BtnTypeSat.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_sat.jpg)';
	this.Box.appendChild(this.BtnTypeSat);
	//	this.Box.insertBefore(this.BtnTypeSat, document.getElementById('tblZoomControls'));
	this.BtnTypeSat.owner = this;
	this.BtnTypeSat.idaction = 'sat';
	this.Application.bindEvent(this.BtnTypeSat, 'click', this, this.buttonsHandler);

	this.BtnTypeHyb = document.createElement('DIV');
	this.BtnTypeHyb.style.position = 'absolute';
	this.BtnTypeHyb.style.display = 'block';
	this.BtnTypeHyb.style.border = '0px outset silver';
	this.BtnTypeHyb.style.left = '150px';
	this.BtnTypeHyb.style.top = '4px';
	this.BtnTypeHyb.style.width = '69px';
	this.BtnTypeHyb.style.height = '24px';
	this.BtnTypeHyb.style.cursor = 'pointer';
	this.BtnTypeHyb.style.textAlign = 'center';
	this.BtnTypeHyb.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_hybrid.jpg)';
	this.Box.appendChild(this.BtnTypeHyb);
	//	this.Box.insertBefore(this.BtnTypeHyb, document.getElementById('tblZoomControls'));
	this.BtnTypeHyb.owner = this;
	this.BtnTypeHyb.idaction = 'hyb';
	this.Application.bindEvent(this.BtnTypeHyb, 'click', this, this.buttonsHandler);

	this.BtnBack = document.createElement('DIV');
	this.BtnBack.style.position = 'absolute';
	this.BtnBack.style.display = 'block';
	this.BtnBack.style.border = '0px outset silver';
	this.BtnBack.style.left = '4px';
	this.BtnBack.style.top = '34px';
	this.BtnBack.style.width = '101px';
	this.BtnBack.style.height = '38px';
	this.BtnBack.style.cursor = 'pointer';
	this.BtnBack.style.textAlign = 'center';
	this.BtnBack.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_back.jpg)';
	this.Box.appendChild(this.BtnBack);
	//	this.Box.insertBefore(this.BtnBack, document.getElementById('tblZoomControls'));
	this.BtnBack.owner = this;
	this.BtnBack.idaction = 'back';
	this.Application.bindEvent(this.BtnBack, 'click', this, this.buttonsHandler);

	this.BtnZoom = document.createElement('DIV');
	this.BtnZoom.style.position = 'absolute';
	this.BtnZoom.style.display = 'block';
	this.BtnZoom.style.border = '0px outset silver';
	this.BtnZoom.style.left = '118px';
	this.BtnZoom.style.top = '34px';
	this.BtnZoom.style.width = '101px';
	this.BtnZoom.style.height = '38px';
	this.BtnZoom.style.cursor = 'pointer';
	this.BtnZoom.style.textAlign = 'center';
	this.BtnZoom.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_zoom.jpg)';
	this.Box.appendChild(this.BtnZoom);
	//	this.Box.insertBefore(this.BtnZoom, document.getElementById('tblZoomControls'));
	this.BtnZoom.owner = this;
	this.BtnZoom.idaction = 'zoom';
	this.Application.bindEvent(this.BtnZoom, 'click', this, this.buttonsHandler);

	this.BtnDef = document.createElement('DIV');
	this.BtnDef.style.position = 'absolute';
	this.BtnDef.style.display = 'block';
	this.BtnDef.style.border = '0px outset silver';
	this.BtnDef.style.left = '35px';
	this.BtnDef.style.top = '78px';
	this.BtnDef.style.width = '156px';
	this.BtnDef.style.height = '24px';
	this.BtnDef.style.cursor = 'pointer';
	this.BtnDef.style.textAlign = 'center';
	this.BtnDef.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_default.jpg)';
	this.Box.appendChild(this.BtnDef);
	//	this.Box.insertBefore(this.BtnDef, document.getElementById('tblZoomControls'));
	this.BtnDef.owner = this;
	this.BtnDef.idaction = 'center';
	this.Application.bindEvent(this.BtnDef, 'click', this, this.buttonsHandler);

	this.BtnMinus = document.createElement('DIV');
	this.BtnMinus.style.position = 'absolute';
	this.BtnMinus.style.display = 'block';
	this.BtnMinus.style.border = '0px outset silver';
	this.BtnMinus.style.left = '35px';
	this.BtnMinus.style.top = '108px';
	this.BtnMinus.style.width = '32px';
	this.BtnMinus.style.height = '24px';
	this.BtnMinus.style.cursor = 'pointer';
	this.BtnMinus.style.textAlign = 'center';
	this.BtnMinus.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_minus.jpg)';
	this.Box.appendChild(this.BtnMinus);
	//	this.Box.insertBefore(this.BtnMinus, document.getElementById('tblZoomControls'));
	this.BtnMinus.owner = this;
	this.BtnMinus.idaction = 'zoomout';
	this.Application.bindEvent(this.BtnMinus, 'click', this, this.buttonsHandler);
	
	this.BtnPlus = document.createElement('DIV');
	this.BtnPlus.style.position = 'absolute';
	this.BtnPlus.style.display = 'block';
	this.BtnPlus.style.border = '0px outset silver';
	this.BtnPlus.style.left = '159px';
	this.BtnPlus.style.top = '108px';
	this.BtnPlus.style.width = '32px';
	this.BtnPlus.style.height = '24px';
	this.BtnPlus.style.cursor = 'pointer';
	this.BtnPlus.style.textAlign = 'center';
	this.BtnPlus.style.backgroundImage = 'url(' + this.ImagesBasePath + 'btn_cbox_plus.jpg)';
	this.Box.appendChild(this.BtnPlus);
	//	this.Box.insertBefore(this.BtnPlus, document.getElementById('tblZoomControls'));
	this.BtnPlus.owner = this;
	this.BtnPlus.idaction = 'zoomin';
	this.Application.bindEvent(this.BtnPlus, 'click', this, this.buttonsHandler);
	
	this.ZoomLayer = document.createElement('DIV');
	with (this.ZoomLayer.style) {
		position = 'absolute';
		display = 'none';
		border = '0px solid red';
		cursor = 'url(' + this.ImagesBasePath + 'lente.cur, default)';
		backgroundImage = 'url(' + this.ImagesBasePath + 'blank.gif)';
		top = '0px';
		left = '0px';
		width = this.mapObject.DOMContainer.offsetWidth + 'px';
		height = this.mapObject.DOMContainer.offsetHeight + 'px';
		zIndex = -1;
	}
	this.ZoomLayer.owner = this;
	this.mapObject.DOMContainer.appendChild(this.ZoomLayer);
	this.isDragging = false;
	this.dragRect = null;
	this.mouseXStart = 0;
	this.mouseXEnd = 0;
	this.mouseYStart = 0;
	this.mouseYEnd = 0;
	this.zoomChanged();
}

MapControls.prototype.zoomChanged = function() {
	//var step = this.map.getZoom() - 2;
	//if (step < 1) step = 1;
	//this.ZoomSlider.style.backgroundPosition = (step * 12 - 158) + 'px 0px';
}


MapControls.prototype.buttonsHandler = function(obj, ev) {
	switch (obj.idaction) {
		case 'map':
			this.map.setMapType(G_NORMAL_MAP);
			break;
		case 'sat':
			this.map.setMapType(G_SATELLITE_MAP);
			break;
		case 'hyb':
			this.map.setMapType(G_HYBRID_MAP);
			break;
		case 'back':
			this.mapObject.ctrlHistory.zoomBack();
			break;
		case 'zoom':
			this.prepareDragZoom();
			break;
		case 'zoomin':
			this.map.setZoom(this.map.getZoom() + 1);
			break;
		case 'zoomout':
			this.map.setZoom(this.map.getZoom() - 1);
			break;
		case 'center':
			this.map.returnToSavedPosition();
	}
}

MapControls.prototype.prepareDragZoom = function() {
	with (this.ZoomLayer.style) {
		top = '0px';
		left = '0px';
		width = this.mapObject.DOMContainer.offsetWidth + 'px';
		height = this.mapObject.DOMContainer.offsetHeight + 'px';
		display = 'block';
		zIndex = 100;
	}
	this.Application.bindEvent(this.ZoomLayer, 'mousedown', this, this.zoomDragStart);
	this.Application.bindEvent(this.ZoomLayer, 'mousemove', this, this.mouseMoveHandler);
	this.Application.bindEvent(this.ZoomLayer, 'mouseup', this, this.zoomDragEnd);
}

MapControls.prototype.zoomDragStart = function(obj, ev, offsetX, offsetY, clientX, clientY) {
	this.mouseXStart = offsetX;
	this.mouseYStart = offsetY;
	this.dragRect = document.createElement('DIV');
	this.dragRect.style.position = 'absolute';
	this.dragRect.style.display = 'block';
	this.dragRect.style.border = '2px dotted #808080';
	this.dragRect.style.left = this.mouseXStart + 'px';
	this.dragRect.style.top = this.mouseYStart + 'px';
	this.dragRect.style.width = '2px';
	this.dragRect.style.height = '2px';
	this.mapObject.DOMContainer.appendChild(this.dragRect);
	this.dragRect.style.zIndex = 99;
	this.isDragging = true;
}


MapControls.prototype.mouseMoveHandler = function(obj, ev, offsetX, offsetY, clientX, clientY) {
	if (this.isDragging) {
		var newX = offsetX;
		var newY = offsetY;
		if (newX > this.mouseXStart) {
			this.dragRect.style.left = this.mouseXStart + 'px';
			this.dragRect.style.width = (newX - this.mouseXStart) + 'px';
		} else {
			this.dragRect.style.left = newX + 'px';
			this.dragRect.style.width = (this.mouseXStart - newX) + 'px';
		}
		if (newY > this.mouseYStart) {
			this.dragRect.style.top = this.mouseYStart + 'px';
			this.dragRect.style.height = (newY - this.mouseYStart) + 'px';
		} else {
			this.dragRect.style.top = newY + 'px';
			this.dragRect.style.height = (this.mouseYStart - newY) + 'px';
		}
	}
}

MapControls.prototype.zoomDragEnd = function(obj, ev, offsetX, offsetY, clientX, clientY) {
	if (this.isDragging) {
		this.isDragging = false;
		this.mapObject.DOMContainer.removeChild(this.dragRect);
		this.dragRect = null;
		
		this.mouseXEnd = offsetX;
		this.mouseYEnd = offsetY;
		obj.style.zIndex = -1;
		obj.style.display = 'none';
		var sw = this.map.fromContainerPixelToLatLng(new GPoint(Math.min(this.mouseXStart, this.mouseXEnd), Math.max(this.mouseYStart, this.mouseYEnd)));
		var ne = this.map.fromContainerPixelToLatLng(new GPoint(Math.max(this.mouseXStart, this.mouseXEnd), Math.min(this.mouseYStart, this.mouseYEnd)));
		var bounds = new GLatLngBounds(sw, ne);
	  this.map.setCenter(bounds.getCenter(), this.map.getBoundsZoomLevel(bounds));
		this.mouseXStart = 0;
		this.mouseXEnd = 0;
		this.mouseYStart = 0;
		this.mouseYEnd = 0;
		this.Application.unbindEvent(this.ZoomLayer, 'mousedown');
		this.Application.unbindEvent(this.ZoomLayer, 'mousemove');
		this.Application.unbindEvent(this.ZoomLayer, 'mouseup');
		//owner.BtnZoom.style.border = '1px outset silver';
		//this.BtnZoom.style.backgroundColor = 'transparent';
	}
}



