// location.js - jvn@vns.nl - 2008 May 4. 
// Scripting to insert Google map on VNS website upon button press
// and flash replacement with swfobject2 of the vns map image

//=============================================================
// For Google map:
// Let HTML have a container <div> for the Map with id="mapdiv"
// Call gmap_load() javascript function.. Pass true or false to have an
// or hide an initial info window at the home marker. That's it ;-)

    var _initial_info = false;
    
    // **** Load Google Map.  ****
    function gmap_load2() {
      if (GBrowserIsCompatible()) {
        // Get the element that will house the Map
        var box = document.getElementById("gmapbox");
        if (!box) return;
        // We will size it here..
        box.style.width = "550px";
        box.style.height = "440px";
        // Give some extra vertical margin...
        box.style.margin = "20px 0px";
        // Create the Map
        var map = new GMap2(box);
        //Set centre coordinates and zoom factor 
        // map.setCenter(new GLatLng(51.287205, 5.317125), 14);      
        map.setCenter(new GLatLng(51.406916, 5.476685), 10);
        // Change map type
        //map.setMapType(G_HYBRID_MAP);
        // Add a Zoom/Pan Control 
        map.addControl(new GSmallMapControl());
        // Add a Map Type Control
        map.addControl(new GMapTypeControl());
        // Place a standard marker on the home coordinates
        var mylatlng = new GLatLng(51.282048,5.306008);
        var mymarker = new GMarker(mylatlng);
        map.addOverlay(mymarker); 
        // Show a popup bubble when clicking the marker with link to google map site
        // The logo is 188x44. Note that inherited css styles apply for the text and link
        var html="<img src='data/about/vns_logo.png' width='188' height='44'/>" +
         "<br />Boscheind 55 - 5575AA - Luyksgestel<br />"+
         "<a href='http://maps.google.com/maps?f=q" + 
         "&amp;hl=en&amp;geocode="+
         "&amp;q=Boscheind+55,+5575+Luyksgestel,+Bergeijk+(Noord-Brabant),+Netherlands" +
         "&amp;sll=37.0625,-95.677068&amp;sspn=44.25371,66.181641"+
         "&amp;ie=UTF8&amp;ll=51.282048,5.306008&amp;spn=2.405205,4.669189&amp;z=9" +
         "&amp;source=embed' " +
         "target='_blank'>get directions<\/a>";      
        GEvent.addListener(mymarker, "click", function() {
           mymarker.openInfoWindowHtml(html);
        });    
        // Start with initial info when requested
        if (_initial_info) mymarker.openInfoWindowHtml(html);         
      }        
      // The Google Map API provides GUnload() to help prevent memory leaks. It should be called when closing up.
      // We install it here, allowing cascade of any previously existing unload handler
      if (typeof window.onunload == 'function') {
         var oldUnload = window.onunload;
         window.onunload = function() {
           GUnload();
           oldUnload();
         }
      } 
      else window.onunload = GUnload;
    }
    
    //**** Main function: Load the Google Maps API and then load our Map through a callback ****
    function gmap_load(initial_info) {
        // Remember parameter
        _initial_info = initial_info;
        // The Google Map Key is needed when going through a webserver (local or public), but immaterial for direct testing
        // So we have to determine what key to use here by looking at location.host.
        if (location.host == "www.vns.nl")       
          // key for  http://www.vns.nl     
          var key = "ABQIAAAAbGsv14c65MBRuhIFeJzcSRTJWEe_PPJwMcZznOKiuaHLkebtYxSke5wSDwFPVXzKYxraS-eiKbjnHg";   
        else
          // key for  http://maindesk  
          var key = "ABQIAAAAbGsv14c65MBRuhIFeJzcSRTzumVL627oryVasciEGyKGOTBkQRRA2kEyfxzxAB4Qvfug_IUPq9aG2A";    
        // Assemble the script to load the Google Map API and then insert it.
        // The API ha a callback that will call gmap_load2() to do the actual map loading
        var script = document.createElement("script");
        script.setAttribute("src",
        "http://maps.google.com/maps?file=api&v=2"+
        "&key="+key+
        "&async=2&callback=gmap_load2");
        script.setAttribute("type", "text/javascript");
        document.documentElement.firstChild.appendChild(script);
    }    

//=============================================================
// For Flash map:
// Function to replace the static VNS map with a Flash variant, using swfobject V2 
// Note that the swfobject V2 script automatically tries to bind when the DOM is loaded
// Showing the Location page with the flash will invoke expressInstall.swf (expected in the 
// common dir) when needed

    swfobject.embedSWF("data/about/vns_map.swf", "vnsmapbox", "550", "400", "7.0.0" );
