var centerLocation = '5875 Falls Avenue, Niagara Falls, Ontario, L2G 3K7';
var latlngCordinates = '43.091801,-79.071184';
var getCordinatesMode = 'off';
var startZoom = 15;
var map;

var latLngArray = new Array();
latLngArray[0] = new GLatLng(43.09167577415739, -79.07149091362953); //Crowne
latLngArray[1] = new GLatLng(43.09123702063152, -79.07231569290161); //Sheraton
latLngArray[2] = new GLatLng(43.09393217121289, -79.07368898391724); //Hampton
latLngArray[3] = new GLatLng(43.093838156328665, -79.07192945480347); //Skyline
latLngArray[4] = new GLatLng(43.089074546619486, -79.06262218952179); //Days Inn
latLngArray[5] = new GLatLng(43.09198916760861, -79.07192945480347); //Waterpark
latLngArray[6] = new GLatLng(43.091166506378826, -79.07310426235199); //Rainforest Cafe
latLngArray[7] = new GLatLng(43.09100197280685, -79.0733939409256); //WWE Store
latLngArray[8] = new GLatLng(43.0908374387929, -79.0731793642044); //MGM Studios
latLngArray[9] = new GLatLng(43.09097846797479, -79.0729433298111); //Adventure City
latLngArray[10] = new GLatLng(43.09144856290245, -79.0717202425003); //Casino Niagara
latLngArray[11] = new GLatLng(43.09299201587607, -79.07077610492706); //Planet Hollywood
latLngArray[12] = new GLatLng(43.09316437876829, -79.0728360414505); //Perkins
var addressTextArray = new Array();
addressTextArray[0] = '<strong>Crowne Plaza Niagara Falls</strong><br />5685 Falls Avenue,<br />Niagara Falls,<br />Ontario,<br >L2E 6W7<br />(905) 374-4447 &bull; 1-800-263-7135<br /><a href="http://www.niagarafallscrowneplazahotel.com/index.php" target="_blank">www.niagarafallscrowneplazahotel.com</a>'; //Crowne
addressTextArray[1] = '<strong>Sheraton on the Falls</strong><br />5875 Falls Avenue,<br />Niagara Falls,<br />Ontario,<br />L2G 3K7<br />(905) 374-4445 &bull; 1-888-234-8410<br /><a href="http://www.sheratononthefalls.com/index.php" target="_blank">www.sheratononthefalls.com</a>'; //Sheraton
addressTextArray[2] = '<strong>Hampton Inn at the Falls</strong><br />5591 Victoria Avenue,<br />Niagara Falls,<br />Ontario,<br />L2E 3L4<br />(905) 357-1626 &bull; 1-800-688-3535<br /><a href="http://www.hamptoninnatthefalls.com/index.php" target="_blank">www.hamptoninnatthefalls.com</a>'; //Hampton
addressTextArray[3] = '<strong>Skyline Inn Niagara Falls</strong><br />4800 Bender Hill,<br />Niagara Falls,<br />Ontario,<br />L2G 3K1<br />(905) 374-4444 &bull; 1-800-263-7135<br /><a href="http://www.skylineinnniagarafalls.com/index.php" target="_blank">www.skylineinnniagarafalls.com</a>'; //Skyline
addressTextArray[4] = '<strong>Days Inn at the Falls</strong><br />443 Main Street,<br />Niagara Falls,<br />New York,<br />14301<br />(716) 284-8801 &bull; 1-800-263-7135<br /><a href="http://www.daysinnatthefalls.com/index.php" target="_blank">www.daysinnatthefalls.com</a>'; //Days Inn
addressTextArray[5] = '<strong>Fallsview Indoor Waterpark</strong><br />5685 Falls Avenue,<br />Niagara Falls,<br />Ontario,<br />L2E 6W7<br />(905) 374-4444 &bull; 1-888-234-8408<br /><a href="http://www.fallsviewwaterpark.com/index.php" target="_blank">www.fallsviewwaterpark.com</a>'; //Waterpark
addressTextArray[6] = '<strong>Rainforest Cafe</strong><br />4915 Clifton Hill,<br />Niagara Falls,<br />Ontario,<br />L2G 3N5<br />(905) 374-2233'; //Rainforest Cafe
addressTextArray[7] = '<strong>WWE Store</strong><br />4915 Clifton Hill,<br />Niagara Falls,<br />Ontario,<br />L2G 3N5<br />(905) 354-SLAM(7526)'; //WWE Store
addressTextArray[8] = '<strong>MGM Studios 4D Theatre</strong><br />4915 Clifton Hill,<br />Niagara Falls,<br />Ontario,<br />L2G 3N5'; //MGM Studios
addressTextArray[9] = '<strong>Adventure City</strong><br />4915 Clifton Hill,<br />Niagara Falls,<br />Ontario,<br />L2G 3N5'; //Adventure City
addressTextArray[10] = '<strong>Casino Niagara</strong><br />5705 Falls Avenue,<br />Niagara Falls,<br />Ontario,<br />L2H 6T3'; //Casino Niagara
addressTextArray[11] = '<strong>Planet Hollywood</strong><br />4608 Bender Hill,<br />Niagara Falls,<br />Ontario,<br />L2G 3N5<br />(905) 374-8332'; //Planet Hollywood
addressTextArray[12] = '<strong>Perkins Restaurant</strong><br />4800 Bender Hill,<br />Niagara Falls,<br />Ontario,<br />L2G 3K1<br />(905) 371-8688'; //Planet Hollywood

///////////////
// LOAD MAP //
//////////////
function init()
{
 if(GBrowserIsCompatible())
 {
  map = new GMap2(document.getElementById("directionsMap"));
  geocoder = new GClientGeocoder();
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(43.091801,-79.071184), 15);
  map.setMapType(G_NORMAL_MAP);
  
  if(getCordinatesMode=='on') { GEvent.addListener(map,'click',function(overlay,latlng){ addMarker(overlay,latlng); }); }
  setTimeout('showMarkers();',1000);
 }
}
window.onload = init;
window.onunload = GUnload;

/////////////////////////////
// GET LAT LNG CORDINATES //
////////////////////////////
function addMarker(overlay,latlng)
{
 var marker = new GMarker(latlng);
 map.addOverlay(marker);
 document.getElementById("directionsDirections").innerHTML = latlng;
}

//////////////////////////
// SET CENTER LOCATION //
/////////////////////////
    function setCenterLocation(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, startZoom);
            }
          }
        );
      }
    }
	
function createTabbedMarker(point,html1,index) {
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);

	// Create a lettered icon for this point using our icon class
	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	markerOptions = { icon:letteredIcon };
	
	var marker = new GMarker(point, markerOptions);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html1);
		//marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html1), new 
		//GInfoWindowTab(label2,html2)]);
	});
	return marker;
}
function showMarkers() {
	for (i=0; i<latLngArray.length; i++) {
	  addressText = addressTextArray[i];
	  addressLatLng = latLngArray[i];
	  addressMarker = createTabbedMarker(addressLatLng, addressText, i);
	  map.addOverlay(addressMarker);
	}
}

/////////////////////
// GET DIRECTIONS //
////////////////////
function getDirections()
{
 var from = document.getElementById("directionsFrom").value;
 var to;
 if(latlngCordinates) { to = latlngCordinates; }
 else { to = centerLocation; }
 if(window.gDirections) { window.gDirections.clear(); }
 window.gDirections = new GDirections(map, document.getElementById("directionsDirections"));
 window.gDirections.load("from: "+from+" to: "+to);
}