function GMLoadingDiv(MOptions) {
	MOptions = MOptions ? MOptions : {};
	this.slim = MOptions.slim ? MOptions.slim : false;
	this.width = MOptions.width ? MOptions.width : 400;
	this.position = MOptions.position ? MOptions.position : new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(150,50));

	this.cellsHigh = 1;
	this.cellsWide = 9;
	this.visible = false;

}

GMLoadingDiv.prototype = new GControl(true,false);


GMLoadingDiv.prototype.redraw = function(force) {
}
GMLoadingDiv.prototype.remove = function(force) {
}

GMLoadingDiv.prototype.initialize = function(map) {
	var that = this;
	this.map = map;
	this.cells = Array();

	this.container = document.createElement('div');

	this.container.style.display = 'none';
	this.container.style.width = this.width + 'px';

	this.innerDiv = document.createElement('div');
	this.container.appendChild(this.innerDiv);

	this.labelDiv = document.createElement('div');
	this.innerDiv.appendChild(this.labelDiv);
	this.labelDiv.innerHTML = sTradLoading;
	this.labelDiv.style.marginBottom = '5px';
	this.labelDiv.style.font = 'bold 16px verdana';

	// Set container style
	this.container.style.width = this.width + 'px';
	this.container.style.textAlign = 'center';
	this.container.style.padding = '10px';
	this.container.style.border = '5px double #CC0000';
	this.container.style.background = 'silver';
	this.container.style.color = '#CC0000';
	this.container.style.zIndex = '1';
	this.container.style.filter = "alpha(opacity=70)";
	this.container.style.opacity = '0.7';


	
	// Calculate position	
	if (!this.position) {
		var mapContainer = this.map.getContainer();
		var x = (mapContainer.clientWidth / 2) - (this.width / 2);
		var y = 100;
		this.position = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));
	}
	
// -------------------------------------

	var oTable = document.createElement('table');
	oTable.setAttribute('cellSpacing','1');
	oTable.setAttribute('cellPadding','0');
	oTable.setAttribute('width','100%');
	var oTbody = document.createElement('tbody');
	oTable.appendChild(oTbody);


	if (!this.slim) {
		for (var r = 0 ; r < this.cellsHigh ; r++ ) {
			var oRow = document.createElement('tr');
			oTbody.appendChild(oRow);

			for (var c = 0 ; c < this.cellsWide ; c++ ) {
				var oCell = document.createElement('td');
				this.setStyle(oCell);
				oRow.appendChild(oCell);
				this.cells.push(oCell);
				oCell.innerHTML = '&nbsp;'
			}
		}

		this.innerDiv.appendChild(oTable);
	}



	this.animate = function() {

		var maxRGB = 255;
		var minRGB = 0;
		
		var cellIx = this.getRandomInt(0, this.cells.length-1);
		var oLCell = this.cells[cellIx];
		oLCell.style.background = 'RGB('+
				this.getRandomInt(minRGB, maxRGB) + ',' +
				this.getRandomInt(minRGB, maxRGB) + ',' + 
				this.getRandomInt(minRGB, maxRGB) + ')';

		if (this.visible){
			window.setTimeout(function(){that.animate()},50);
		}
		else {
			this.hide();
		}
	}


	this.map.getContainer().appendChild(this.container);
	return this.container;
}



GMLoadingDiv.prototype.getRandomInt = function(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}



GMLoadingDiv.prototype.setStyle = function(obj) {
	obj.style.width = '50px';
	obj.style.border = '2px solid black';
	obj.style.padding = '2px';

}

GMLoadingDiv.prototype.getDefaultPosition = function() {
	return this.position;
}

GMLoadingDiv.prototype.setText1 = function(text) {
	this.innerDiv.innerHTML = text;
	this.show();
}

GMLoadingDiv.prototype.show = function() {
	this.container.style.display = '';
	this.visible = true;
	
	if (!this.slim) {
		this.animate();
	}
}

GMLoadingDiv.prototype.hide = function() {
	this.container.style.display = 'none';
	this.visible = false;
}

