/**
 * @name Load Indicator
 * @version 1.0
 * @author Skakunov Alexander (i1t2b3@gmail.com)
 * @fileoverview Creates a load indicator image that shows every time when the map is updated
 */

/**
 * @name LoadIndicator
 * @property {ImageFileName} Specifies the web accessable image URL
 */
/* might be obsolete now since globalLoader is used */

function LoadIndicatorMapControl(map, imageFileName) { 
  this.map_ = map; 
  this.imageFileName_ = imageFileName; 
}

try {
    LoadIndicatorMapControl.prototype = new GControl(true, false);
}
catch(e) {
    alert('GControl is not defined. Are Google Maps loaded?');
}


LoadIndicatorMapControl.prototype.initialize = function () {
  var container_ = document.createElement('div');
  container_.innerHTML = '<div style="position:absolute;width:100%;border:5px;'
    + 'text-align:center;vertical-align:bottom;" id="geo_progress_text">'
    + '<img src="'+this.imageFileName_+'"/>'
    + '</div>';
  container_.id = "geo_load_indicator_container";
  container_.style.display = "none";
  //container_.style.width = this.width_ + "px";
  this.map_.getContainer().appendChild(container_);
  return container_;
};


LoadIndicatorMapControl.prototype.getDefaultPosition = function () {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(70, 5));
};


function LoadIndicator(map, imageFileName) {

  if( null == imageFileName ) throw new Error('No image file name set');
  this.control_ = new LoadIndicatorMapControl(map, imageFileName);
  this.map_ = map;
  this.image = new Image(); 
  this.image.src = imageFileName; 

  this.map_.addControl(this.control_);
  
  this.container_ = document.getElementById('geo_load_indicator_container');
}

LoadIndicator.prototype.show = function () {
  this.container_.style.display = 'block';
};

LoadIndicator.prototype.hide = function () {
  this.container_.style.display = 'none';
};
