
/*
* Copyright (c) 2005 Andriy Bidochko.  
* http://www.mapbuilder.net
*
* The script has been generated by MapBuilder.net service and released to the customer under 
* The GNU General Public License (GPL), which can be found at: http://www.opensource.org/licenses/gpl-license.php
* 
* This program is free software; you can redistribute it and/or modify it under the terms of the 
* GNU General Public License as published by the Free Software Foundation; 
* either version 2 of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
* for more details.
*/

MapBuilder.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;

} 

MapBuilder.prototype.addMBInfo=function(oMap){

	var v = MapBuilder.GetGoogleMapsAPIVersion();

	var info=document.createElement('div');

	if (v > 2)
	{
		oMap.getContainer().appendChild(info);
	}
	
	else
	{
		//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) {
	// v1
	return ;
	 
    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.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("td");
    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);
  	document.getElementById("LocationList").bgColor = '#ebeac9';
  	document.getElementById("LocationList").style.height = '100px';
  	document.getElementById("LocationList").style.width = '100px';
  }
}

// Function is called to hide location list 
function HideLocationList()
{
  document.getElementById("LocationList").innerHTML = '';
  document.getElementById("SideBarAction").innerHTML = 'Event List [<a href="#" onclick="ShowLocationList()">+</a>]';
}

// Function is called to show location list 
function ShowLocationList()
{
  document.getElementById("LocationList").innerHTML = listNodeContent;
  document.getElementById("SideBarAction").innerHTML = 'Event List [<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);
}

