var mapBoxes = new Array();

function AddMapBox(id, parentDiv, x1, y1, x2, y2) {
	if (parentDiv) {
		mapBoxes[id] = new mapBox(parentDiv, x1, y1, x2, y2);
	}
}

function ShowAllZoomBoxes() {
	for (var i in mapBoxes) {
		mapBoxes[i].Show();
	}
}

function HideAllZoomBoxes() {
	for (var i in mapBoxes) {
		mapBoxes[i].Hide();
	}
}

var zoomBoxDestX = 500;
var zoomBoxDestY = -20;
var nZoomBoxSteps = 40;
var zoomBoxTimeStep = 10;
var zoomBoxStep = 0;

function ZoomBoxStep() {
	for (var i in mapBoxes) {
		var box = mapBoxes[i];

		box.div.style.left   = box.x1 + (box.xDelta * zoomBoxStep);
		box.div.style.top    = box.y1 + (box.yDelta * zoomBoxStep);

		var width = (box.x2 - box.x1) - box.hDelta * zoomBoxStep;
		var height = (box.y2 - box.y1) - box.vDelta * zoomBoxStep;
		
		if (width > 0)
			box.div.style.width  = width;
		if (height > 0)
			box.div.style.height = height;
	}

	if (zoomBoxStep <= nZoomBoxSteps) {
		zoomBoxStep++;
		setTimeout(ZoomBoxStep, zoomBoxTimeStep);
	} else {
		HideAllZoomBoxes();
	}
}

function ZoomBoxVaccume() {
	var x = zoomBoxDestX;
	var y = zoomBoxDestY;
	zoomBoxStep = 0;

	for (var i in mapBoxes) {
		var box = mapBoxes[i];

		box.xDelta = (x - box.x1) / nZoomBoxSteps;
		box.yDelta = (y - box.y1) / nZoomBoxSteps;
		box.hDelta = (box.x2 - box.x1) / nZoomBoxSteps;
		box.vDelta = (box.y2 - box.y1) / nZoomBoxSteps;
	}
	setTimeout(ZoomBoxStep, zoomBoxTimeStep);
}

function ShowZoomBox(id) {
	mapBoxes[id].Show();
}

function HideZoomBox(id) {
	mapBoxes[id].Hide();
}

function mapBox(parentDiv, x1, y1, x2, y2) {

	this.parentDiv = parentDiv;
	this.x1 = x1;
	this.y1 = y1;
	this.x2 = x2;
	this.y2 = y2;

	this.div = document.createElement("div");
	this.div.style.visibility = 'hidden';
	this.div.style.display    = 'inline';
	this.div.style.position   = "absolute";
	this.div.style.border     = "1px solid black";

	this.SetPosition = function() {
		this.div.style.left       = this.x1 + "px";
		this.div.style.top        = this.y1 + "px";
		this.div.style.width      = this.x2 - this.x1;
		this.div.style.height     = this.y2 - this.y1;
	}
	this.SetPosition();

	this.parentDiv.appendChild(this.div);

	this.Show = function() {
		this.SetPosition();
		this.div.style.visibility = 'visible';
	}

	this.Hide = function() {
		this.div.style.visibility = 'hidden';
		this.SetPosition();
	}

}

