var InfoWin = null;
function InfoWinControl() {
  InfoWin = this;
}

InfoWinControl.prototype = new GControl();

/**
 * Is called by GMap2's addOverlay method. Creates the info win control
 * divs and appends to the map div.
 * @param {GMap2} map The map that has had this InfoWinControl added to it.
 * @return {DOM Object} Div that holds the gzoomcontrol button
 */ 
InfoWinControl.prototype.initialize = function(map) {
  var mapDiv = map.getContainer();
 
  // Create div for both buttons	
    var InfoWinDiv = document.createElement("div");	
    InfoWinDiv.style.cursor = 'pointer';
    InfoWinDiv.style.zIndex = 150;

    InfoWinDiv.style.border = '2px solid #444444';
    InfoWinDiv.style.color = '#F8CE26';
    InfoWinDiv.style.backgroundColor = '#64BB45';
    InfoWinDiv.style.fontWeight = 'bold';
    InfoWinDiv.style.paddingLeft = '4px';
    InfoWinDiv.style.paddingRight = '4px';
    InfoWinDiv.style.paddingTop = '1px';
    InfoWinDiv.style.paddingBottom = '1px';

    this.InfoWinDiv = InfoWinDiv;
  
  // Add the two buttons to the map 					
    mapDiv.appendChild(InfoWinDiv);
  
  // add event listeners
    GEvent.addDomListener(InfoWinDiv, 'click', function(e) {
      var selPointsLang = document.getElementById("selPointsLang");
      var points_lang = selPointsLang.options[selPointsLang.selectedIndex].value;
      OpenWin('stat.php?lang='+points_lang, 800, 600, 'yes');
    });
  
  window.setTimeout("InfoWin.getInfo()", 500);
  
  return InfoWinDiv;
};

/**
 * Required by GMaps API for controls. 
 * @return {GControlPosition} Default location for control
 */
InfoWinControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(3, 120));
};

InfoWinControl.prototype.getInfo = function() {
  var url = "markers_cont.php";
  GDownloadUrl(url, this.setInfo);
};

InfoWinControl.prototype.setInfo = function(data) {
  var xml = GXml.parse(data);
  var count = xml.documentElement.getElementsByTagName("count")[0];
  InfoWin.InfoWinDiv.innerHTML = messages['TotalMarkersCountMsg']+count.firstChild.nodeValue;
  //window.setTimeout("InfoWin.getInfo()", 5000);
};
