/*
* The original base script for this file has been modified greatly by 
* MSI Systems Integrators on behalf of Home Instead Senior Care
*
* Original base script created by:
* Copyright (c) 2005-2007 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.
*/


//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 passed html
function createMarker(point, html, icon) {

  var marker = new GMarker(point, icon);

  GEvent.addListener(marker, "click", function() {
	// Tool tip window, can have optional tabs 
	marker.openInfoWindowTabsHtml(
		[
			new GInfoWindowTab("Info", html) //,
			//new GInfoWindowTab("Directions", GetDirectionForm(id))
		]);
	 
  });

  return marker;
}

// Function is called when item is clicked.
function myInfoWindowHtml(myLocations, num)
{
  // Map rendering with open info window is very slow. Lets center map first.
  map.setCenter(myLocations[num][3]);

  // Tool tip window, can have optional tabs  
  myLocations[num][0].openInfoWindowTabsHtml(
  	[
  		new GInfoWindowTab("Info", myLocations[num][2]) //,
  		//new GInfoWindowTab("Directions", GetDirectionForm(num))
  	]);
   
}

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;
    
}

// Global Variables
// set map variable
var map = null;

// Create a base "large" red icon that specifies the shadow, icon dimensions, etc.
var iconbig = new GIcon();
iconbig.image = "/images/mapmarkers/marker.png";
iconbig.shadow = "/images/mapmarkers/shadow50.png";
iconbig.iconSize = new GSize(20, 34);
iconbig.shadowSize = new GSize(37, 34);
iconbig.iconAnchor = new GPoint(6, 34);
iconbig.infoWindowAnchor = new GPoint(5, 1);

// Custom Icon
var iconcustom = new GIcon(iconbig);
iconcustom.shadow = '';

//set up array to old functions that add locations
var allLocations = new Array;

// Runs onLoad of the page
function onLoad() {
if (!GBrowserIsCompatible()) 
{
 document.getElementById("MapBuilderMap").innerHTML = "Unfortunately your browser doesn't support Google Maps.<br /> To check browser compatibility visit the following <a href=\"http://local.google.com/support/bin/answer.py?answer=16532&topic=1499\">link</a>.";
 return;
}

map = new GMap2(document.getElementById("MapBuilderMap"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());

  // Add all locations to the map
  for (var i=0; i<allLocations.length; i++)
  {
      allLocations[i]();
  }
}
