
/*
* Copyright (c) 2005-2006 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 given number
function createMarker(point, html, icon, oOptions) {
  if (usePDMarker)
  {
  	var marker = new PdMarker(point, icon, oOptions.label);
  	/* Doesn't work in APIs > 2.64
  	 * marker.setTooltip(oOptions.label);
  	 * marker.setOpacity((oOptions.opasity ? oOptions.opasity : 100));
  	 */
  }
  else
  {
  	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
  var currentZoom = map.getZoom();
  // Re-center map
  newzoom = (currentZoom > 17) ? 17 : ((currentZoom == 0) ? 0 : (currentZoom + 1));
  //V2-V1 compatability 
  map.setCenter(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.setCenter(aLocations[num][3]);
  // Use markeropenInfoWindowHtml(html)
  aLocations[num][0].openInfoWindowHtml(aLocations[num][2]);
}

/* Side Bar */

// Creates a locations list and put it into side bar
function createSideBar() {
  var oUL = document.createElement("ul");
  // 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 + ");";
    listElem.appendChild(linkElem);
    oUL.appendChild(listElem);
  }
  document.getElementById("LocationList").appendChild(oUL);

}


// Function is called to show/hide location list 
var LocationListVisible = true;
function ProcessLocationList()
{
  if (LocationListVisible)
  {
    // Hide sidebar
    document.getElementById("LocationList").style.display="none";
    document.getElementById("SideBarActionLink").innerHTML = "+";
  }
  else
  {
    // Show sidebar
    document.getElementById("LocationList").style.display="block";
    document.getElementById("SideBarActionLink").innerHTML = "-";
  }
  LocationListVisible = !LocationListVisible;
}

/* EOF Side Bar */

/* Directions */
var MBDirectionFormBox = false; 

function  MBDirectionFormState(mode, force) {

  var MBCurrID = document.getElementById("MBLocID").value;
  document.getElementById("addr1").value = aLocations[MBCurrID][0].getPoint().lat() + ", " + aLocations[MBCurrID][0].getPoint().lng() + " ("+ aLocations[MBCurrID][1] +")";
  if (mode=='to') {
    document.getElementById("MBDirectionAddr").innerHTML = 'Start address';
    document.getElementById("addr1").name = 'daddr';
    document.getElementById("addr2").name = 'saddr';
  }
  else {
    document.getElementById("MBDirectionAddr").innerHTML = 'End address';
    document.getElementById("addr1").name = 'saddr';
    document.getElementById("addr2").name = 'daddr';
  }

  if (force) {
    document.getElementById('MBDirectionForm').style.display = (MBDirectionFormBox ? 'none' : 'block');
  }
  else {
    document.getElementById('MBDirectionForm').style.display = 'block';
  }
  MBDirectionFormBox = (!MBDirectionFormBox);
}

// Print Directions Form
function GetDirectionForm(LocID) {
  return "<div class=\"IWDirections\">[<a onclick=\"MBDirectionFormState('to', true);\" href=\"javascript:void(0)\">+</a>] Directions:&nbsp;<a onclick=\"MBDirectionFormState('to', false);\" href=\"javascript:void(0)\">To here</a>&nbsp;-&nbsp;<a onclick=\"MBDirectionFormState('from', false);\" href=\"javascript:void(0)\">From here</a><div id=\"MBDirectionForm\" style=\"display:none\"><form action=\"http://maps.google.com/maps\" target=\"_blank\" method=\"get\"><input id=\"addr1\" name=\"daddr\" value=\"0,0(NAME)\" type=\"hidden\"><input id=\"MBLocID\" name=\"MBLocID\" value=\""+LocID+"\" type=\"hidden\"><div id=\"MBDirectionAddr\" style=\"padding-top: 0.2em; width: 290px;\">Start address</div><div style=\"width: 290px;\"><input value=\"\" id=\"addr2\" style=\"width: 16em;\" name=\"saddr\" onload=\"this.select()\" type=\"text\"></div><div style=\"width: 290px;\"><input value=\"Get Directions\" type=\"submit\"></div></form></div></div>"
}
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;
}

function MapBuilder(oMap){ 
    /* Insert MapBuilder Logo */
    var info=document.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" title="Powered by MapBuilder.net v2.02, GMap v'+GetGoogleMapsAPIVersion()+'"><img src="http://mapbuilder.net/img/mo24.gif" alt="Powered By MapBuilder.net v2.02, GMap v'+GetGoogleMapsAPIVersion()+'" style="border:0; margin: 2px;"/></a>';
    oMap.getContainer().appendChild(info);
}


    // Global Variables
    // set map variable
    var map = null;
    //set up array of locations
    var aLocations = new Array;

    /*************************** Configuration Options ***************************/
    /*PDMarker is used to display tooltips when the user hovers over the markers.
    * PDMarker is a LGPL library provided by Peter Jones. 
    * For details see http://wwww.pixeldevelopment.com/pdmarker.asp
    */
    var usePDMarker = false;

    // Create a base "tiny" red  icon that specifies the shadow, icon dimensions, etc.
    var iconsm = new GIcon();
    iconsm.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    iconsm.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    iconsm.iconSize = new GSize(12, 20);
    iconsm.shadowSize = new GSize(20, 18);
    iconsm.iconAnchor = new GPoint(6, 20);
    iconsm.infoWindowAnchor = new GPoint(5, 1);

    // Create a base "large" red icon that specifies the shadow, icon dimensions, etc.
    var iconbig = new GIcon();
    iconbig.image = "http://www.google.com/mapfiles/marker.png";
    iconbig.shadow = "http://www.google.com/mapfiles/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 = '';


MapBuilder.prototype.renderMap=function(){
  //Render Map Locations 
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      // Center the map to the default location and set map type
      map.setCenter(new GLatLng(36.4566360115962, -108.9404296875), 5, map.getMapTypes()[0]);
      	  
      // Initialize variables
      var point = null;
      var footerHtml = null;
      var InfoHTML = null;
      var marker = null;
      /* Options used for PDMarker initialization:
      * label: tooltip text
      * opasity: tooltip opasity
      */
      var options = {};

    

	// Add locations
	
	point = new GLatLng(35.121941, -106.631344);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(9)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Albuquerque Branch</div><div id=\"MapBuilderIWContent\">499 Industrial Ave. North East<br />Albuquerque, NM 87107<br /> Phone: 877-601-8259 <br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=499+Industrial+Ave.+North+East,+Albuquerque,+NM+87113&amp;ll=35.121909,-106.631413&amp;spn=0.018218,0.048752\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[9] = new Array(marker, "Albuquerque Branch", InfoHTML, point);


	point = new GLatLng(38.811699, -104.725123);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(2)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Colorado Springs Branch</div><div id=\"MapBuilderIWContent\">1383 Vapor Trail<br />Colorado Springs, CO 80916<br />Phone: 800-356-5351<br />  <a href=\"http://maps.google.com/maps?f=q&hl=en&q=1383+Vapor+Trail+Colorado+Springs+80916&ie=UTF8&om=1\" title=\"Get full directions\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[2] = new Array(marker, "Colorado Springs Branch", InfoHTML, point);


	point = new GLatLng(39.789414, -104.872174);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(1)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Denver Commercial</div><div id=\"MapBuilderIWContent\">5050 Florence St. <br /> Denver, CO 80238<br />Phone: 800-870-4305<br /> <a href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=5050+Florence+St.+Denver+CO+80238\" title=\"Get full directions\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[1] = new Array(marker, "Denver Commercial", InfoHTML, point);

	point = new GLatLng(39.678363, -105.003303);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(0)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_blue.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Denver - Evans</div><div id=\"MapBuilderIWContent\">1310 West Evans Ave. <br /> Denver, CO 80223<br />Phone: 800-356-5350<br /> <a title=\"Get full directions\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=1310+West+Evans+Ave.+Denver+CO+80223\">Get Direction Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[0] = new Array(marker, "Denver-Evans", InfoHTML, point);

	point = new GLatLng(40.522163, -105.045849);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(3)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Fort Collins Branch</div><div id=\"MapBuilderIWContent\">1701 Oak Ridge Drive<br />Fort Collins, CO 80525<br />Phone: 800-356-5352<br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=1701+Oak+Ridge+Drive+Fort+Collins,+CO+80525\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[3] = new Array(marker, "Fort Collins Branch", InfoHTML, point);

	point = new GLatLng(39.060063, -108.548449);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(5)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Grand Junction Branch</div><div id=\"MapBuilderIWContent\">1453 4th Ave. <br />Grand Junction CO 81501<br /> Phone: 800-951-5354<br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=1453+4th+Ave.+Grand+Junction+CO+81501\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[5] = new Array(marker, "Grand Junction Branch", InfoHTML, point);

	point = new GLatLng(38.264663, -104.616642);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(4)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Pueblo Branch</div><div id=\"MapBuilderIWContent\">314 Lamkin Street <br />Pueblo, CO 81003<br />Phone: 800-397-0419<br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=314+Lamkin+Street+Pueblo,+CO+81003\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[4] = new Array(marker, "Pueblo Branch", InfoHTML, point);

	point = new GLatLng(40.779529, -112.014599);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(6)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Salt Lake City Branch</div><div id=\"MapBuilderIWContent\">475 North Billy Mitchell Rd. <br />Salt Lake City, UT 84116<br />Phone: 800-324-6735<br /> <a href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=475+N.+Billy+Mitchell+Rd.+Salt+Lake+City,+UT+84116\" title=\"Get Directions\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[6] = new Array(marker, "Salt Lake City Branch", InfoHTML, point);

	point = new GLatLng(33.405734, -111.944671);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(7)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Tempe Branch</div><div id=\"MapBuilderIWContent\">404 W. 21st Street <br />Tempe, AZ 85282<br />Phone: 480-736-1701<br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=404+W.+21st+Street+Tempe,+AZ+85282\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[7] = new Array(marker, "Tempe Branch", InfoHTML, point);
	
	point = new GLatLng(33.50161, -112.114706);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(8)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Phoenix Branch</div><div id=\"MapBuilderIWContent\">3898 N 28th Ave <br />Phoenix, AZ 85017<br />Phone: 602-266-9920<br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=3898+N.+28th+Ave+Phoenix,+AZ+85107\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[8] = new Array(marker, "Phoenix Branch", InfoHTML, point);

		
	point = new GLatLng(33.406200,-104.520400);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(10)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Roswell Branch</div><div id=\"MapBuilderIWContent\">1208 N Grand Ave<br />Roswell, NM 88201<br /> Phone: 505-627-3303 <br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=1206+North+Grand+Ave,+Roswell,+NM+88201&amp;ll=33.406200,-104.520400&amp;spn=0.018218,0.048752\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[10] = new Array(marker, "Roswell Branch", InfoHTML, point);


	point = new GLatLng(42.8500, -106.3308);
	footerHtml = "<div id=\"MapBuilderIWFooter\"><div id=\"MapBuilderIWFooterZoom\"><a href=\"#map\" onclick=\"ZoomMapTo(11)\">Click to Zoom In</a></div>"   + "</div>";

	// Define Marker
	iconbig.image = "http://www.mapbuilder.net/img/icons/marker_34_red.png";
	InfoHTML = "<div id=\"MapBuilderIW\"><div id=\"MapBuilderIWCaption\">Casper Branch</div><div id=\"MapBuilderIWContent\">435 West 1st St.<br />Casper, WY 82601<br /> Phone: 307-237-5923 <br /> <a title=\"Get Directions Online\" href=\"http://maps.google.com/maps?f=q&amp;hl=en&amp;q=435+West+1st+Street,+Casper,+WY+82601&amp;ll=42.8500,-106.3308&amp;spn=0.018218,0.048752\">Get Directions Online</a></div>" + footerHtml + "</div>";
	marker = createMarker(point, InfoHTML, iconbig);
	map.addOverlay(marker);
	aLocations[11] = new Array(marker, "Casper Branch", InfoHTML, point);
      


	  // And finnaly create sidebar
      createSideBar();

}
