//Scripting for google maps API

//Global variables
var map;
var businessLocation;

//On load function - initialises the map
window.onload = function() {
    initialise();
}

//Unload function - prevents memory leaks
window.onunload = GUnload();

//Function which initalises the map and sets the centre to the address of the business
function initialise() {
    //As long as the browser is compatible
    if (GBrowserIsCompatible()) {
        //Create a new map object
        map = new GMap2(document.getElementById('googleMap'));

        //Centre the map on the latitude and longitude co-ordinates of the business' address and set zoom level
        businessLocation = new GLatLng(51.3119, -0.7518);
        map.setCenter(businessLocation, 13);
        map.setUIToDefault();

        //Create a marker at the location and bind an info window (bubble) to it
        var marker = new GMarker(businessLocation);
        marker.bindInfoWindow(createInfoWindow(), { maxWidth: 50, maxHeight: 30 });
        map.addOverlay(marker);

        //Automatically open window
        map.openInfoWindow(businessLocation, createInfoWindow(), { maxWidth: 50, maxHeight: 30 });
    }
    else {
        alert('Your browser is not compatible with Google Maps');
    }
}

//Function which creates an info window (bubble) at the marker's location
function createInfoWindow() {
    //Create a new div node
    var container = document.createElement("div");
    container.className = "info";

    //Render the business' name and contact details
    var span = document.createElement("span");
    span.innerHTML = "Speed Check Services Limited";
    span.className = "mapBold";
    container.appendChild(span);

    span = document.createElement("span");
    span.innerHTML = "430 Frimley Business Park";
    container.appendChild(span);

    span = document.createElement("span");
    span.innerHTML = "Frimley, Surrey";
    container.appendChild(span);

    span = document.createElement("span");
    span.innerHTML = "GU16 7SG";
    container.appendChild(span);
    
    //Return the completed info window
    return container;
}