
MojoMap.prototype.GetGoogleMapsAPIVersion = function() {
    var v = 0;
    var scripts = document.getElementsByTagName("SCRIPT")
    for (var i=0; i<scripts.length; i++) {
        var pattern = /\/maps([0-9])?(\.?[0-9]+)(\.api)?\.js/;
        var m = pattern.exec(scripts[i].src);
        if (m != null) {
            if (m[1] == null) { v = parseFloat('1'+m[2]); }
            else { v = parseFloat(m[1]+m[2]); }
            break;
        }
    }
    return v;

} 

MojoMap.prototype.addMBInfo=function(oMap){

	var v = MojoMap.GetGoogleMapsAPIVersion();

	var info=document.createElement('div');
	info.id='MojoMapInfo';
	info.style.position='absolute';
	info.style.right='1px';
	info.style.bottom='25px';
	info.style.backgroundColor='transparent';
	info.style.zIndex=25500;
	info.innerHTML='';

	if (v >= 0)
	{
		oMap.getContainer().appendChild(info);
	}
	else
	{
		oMap.getContainer().appendChild(info);
	}
}

GMap.prototype.addMojoMap=function(oMap){
  oMap.initialize(this);
}

MojoMap.prototype.registerMBEvent=function(oMap){
  GEvent.addListener(oMap, "maptypechanged", function() {
  	setCreatedColor(oMap);
  });
}

GMap.prototype.addMojoMap=function(oMap){
  oMap.initialize(this);
}

//Set "Created By MojoMap" color based on map type
function setCreatedColor(oMap) {
	// v1
	return ;
	 
    var info=oMap.ownerDocument.getElementById('CreatedByMojoMap');
  	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.getZoomLevel();
  // 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 MojoMap(){}
MojoMap.prototype.initialize=function(oMap){
  // Show info
  this.addMBInfo(oMap);
  // Event on maptype cahnge
  this.registerMBEvent(oMap);
  // Analize current maptype
  setCreatedColor(oMap);
}

