MapBuilder.prototype.addMBInfo=function(oMap){
  var info=oMap.ownerDocument.createElement('div');
  info.id='MapBuilderInfo';
  info.style.position='absolute';
  info.style.right='1px';
  info.style.bottom='-25px';
  info.style.backgroundColor='transparent';
  info.style.zIndex=25500;
  info.innerHTML='<a id="CreatedByMapBuilder" href="http://www.mapbuilder.net" style="font: 10px verdana; text-decoration: none; padding: 2px; color: #FFFFFF;">FREE Map Code by MapBuilder.net</a>';
  oMap.div.parentNode.appendChild(info);
}

GMap.prototype.addMapBuilder=function(oMap){
  oMap.initialize(this);
}

MapBuilder.prototype.registerMBEvent=function(oMap){
  GEvent.addListener(oMap, "maptypechanged", function() {
  	setCreatedColor(oMap);
  });
}

GMap.prototype.addMapBuilder=function(oMap){
  oMap.initialize(this);
}

//Set "Created By Mapbuilder" color based on map type
function setCreatedColor(oMap) {
    var info=oMap.ownerDocument.getElementById('CreatedByMapBuilder');
  	currmaptype = getCurrentMapTypeNumber(oMap);
	// Regular map
  	if (currmaptype == 0)
      info.style.color='#000000';
    else
      info.style.color='#FFFFFF';
}

//That function will return the element of the array returned by map.getMapTypes() that identifies the current map
function getCurrentMapTypeNumber(oMap){
  var type=-1;
  for(var ix=0;ix<oMap.getMapTypes().length;ix++){
    if(oMap.getMapTypes()[ix]==oMap.getCurrentMapType())
      type=ix;
  }
  return type;

} 




// Creates a marker whose info window displays the given number
function createMarker(point, html, icon) {
  var marker = new GMarker(point, icon);

  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });

  return marker;
}

// Zoom map to. Used from InfoWindow
function ZoomMapTo(num) {
  // Get current zoom level
  currentZoom = map.getZoom();
  // Re-center map
  newzoom = (currentZoom > 7) ? 7 : ((currentZoom == 0) ? 0 : (currentZoom - 1));
  map.centerAndZoom(aLocations[num][3], newzoom);
}

// Function is called when sidebar item is clicked or we are dealing with group boxes.
function myInfoWindowHtml(num)
{
  // Map rendering with open info window is very slow. Lets center map first.
  map.centerAtLatLng(aLocations[num][3]);
  // Use markeropenInfoWindowHtml(html)
  aLocations[num][0].openInfoWindowHtml(aLocations[num][2]);

  // Move focus to the map
  // Depricated 
  //window.scrollTo(10, 10);
}

 

// Creates a locations list and put it into side bar
function createSideBar() {
  // write links into document.
  for (var i=0; i<aLocations.length; i++) {
    var linkElem = document.createElement("a");
    var listElem = document.createElement("li");
    linkElem.innerHTML = aLocations[i][1];

    // must use this approach instead.
    linkElem.href = "javascript:myInfoWindowHtml(" + i + ");";
    var listNode = document.getElementById("LocationList").appendChild(listElem);
    listNode.appendChild(linkElem);
  }
}


// Function is called to hide location list 
function HideLocationList()
{
  document.getElementById("LocationList").innerHTML = '';
  document.getElementById("SideBarAction").innerHTML = 'Map Locations [<a href="#" onclick="ShowLocationList()">+</a>]';
}

// Function is called to show location list 
function ShowLocationList()
{
  document.getElementById("LocationList").innerHTML = listNodeContent;
  document.getElementById("SideBarAction").innerHTML = 'Map Locations [<a href="#" onclick="HideLocationList()">-</a>]';
}

    

function MapBuilder(){}
MapBuilder.prototype.initialize=function(oMap){
  // Show info
  this.addMBInfo(oMap);
  // Event on maptype cahnge
  this.registerMBEvent(oMap);
  // Analize current maptype
  setCreatedColor(oMap);
}
