﻿//<![CDATA[
var map;
var gmarkers = [];
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var i=0;

// create the marker and set up the event window
function createMarker(point,name,html) {
  var marker = new GMarker(point);

  // The info window version with the "to here" form open
  to_htmls[i] = html + '<p class=\"mapinfo\">Directions: <strong>To here</strong> - <a href="javascript:fromhere(' + i + ')">From here</a>' +
     '<form class=\"mapinfo\" action="http://maps.google.com/maps" method="get" target="_blank">' +
     '<label for=/"saddr/">Start address:</label><input type="text" size=30 maxlength=40 name="saddr" id="saddr" value="" /><br/>' +
     '<input value="Get Directions" TYPE="submit">' +
     '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
            // "(" + name + ")" + 
     '"/><br/><br/><br/><br/></p>';
  // The info window version with the "to here" form open
  from_htmls[i] = html + '<p class=\"mapinfo\">Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <strong>From here</strong>' +
     '<form class=\"mapinfo\" action="http://maps.google.com/maps" method="get"" target="_blank">' +
     '<label for=/"daddr/">End address:</label><input type="text" size=30 maxlength=40 name="daddr" id="daddr" value="" /><br/>' +
     '<input value="Get Directions" TYPE="submit">' +
     '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
            // "(" + name + ")" + 
     '"/><br/><br/><br/><br/></p>';
  // The inactive version of the direction info
  html = html + '<p class=\"mapinfoend\">Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a><br/><br/></p>';

  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  gmarkers[i] = marker;
  htmls[i] = html;
  i++;
  return marker;
}

function tohere(i) {
    gmarkers[i].openInfoWindowHtml(to_htmls[i]);
  }
  
function fromhere(i) {
  gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}

function loadMap() {
    if (GBrowserIsCompatible()) {
        if (document.getElementById("map")) {
            //document.getElementById("largemap").style.display = 'none';
            var map = new GMap2(document.getElementById("map"));
            var point = new GLatLng(52.220149, -1.515727);
            map.setCenter(point, 13);
            //map.addControl(new GLargeMapControl());
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());

            var marker = createMarker(point, 'Freestyle', '<p class=\"mapinfo\"><span class=\'bold\'>Freestyle Interactive Ltd</span>' +
		'<br\>Harwoods House' +
		'<br\>Ashorne' +
		'<br\>Warwickshire' +
		'<br\>CV35 0AA' +
		'<br\>T: +44 (0)1926 652832' +
		'<br\>F: +44 (0)1926 651366</p>')
            map.addOverlay(marker);

        }	
	}
}
window.onload=loadMap;
//window.unload=GUnload();;
//]]>