// Copyright 2005 MapBuilder.net
// You can't use this script or parts of this script without written permission from MapBuilder.net or Andrew Bidochko.
// This script is a part of free service provided by MapBuilder.net and the script can be used from MapBuilder.net server only.

//Created from my master JavaScript

// 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 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.drawZoomAndCenter(aLocations[num][3],map.getZoomLevel());
  aLocations[num][0].openSmartWindow(aLocations[num][2]);
}

// Zoom map to. Used from InfoWindow
function ZoomMapTo(num) {
  // Get current zoom level
  currentZoom = map.getZoomLevel();
  // Re-center map
  newzoom = (currentZoom > 15) ? 15 : ((currentZoom == 0) ? 0 : (currentZoom - 1));
  map.drawZoomAndCenter(aLocations[num][3], newzoom);
}
