<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <!--

    cross_api.xml
    
    Google Gadget/Mapplet cross-API template by Sterling Udell (sterling@udell.name)
    
    Free speech and beer license. Enjoy!

    
    Usage notes:
      - Probably most useful for situations where most/all functionality is on the map itself.
      - Uses Mike Geary's excellent GAsync add-on for Maps/Mapplets cross-API support. See http://mg.to/2007/06/22/
      - Any non-map (mapplet sidebar) content simply appears above the map on iGoogle. If
        you want anything more sophisticated it's up to you to lay it out.
      - Otherwise, just follow the comments below and insert your own code where noted.
  -->
  <ModulePrefs title="Gadget/Mapplet Cross-API Support"
               description="For mapplet and map gadget developers: run the same code on both maps.google.com and iGoogle."
               title_url="http://gad.getpla.net/"
               author="Sterling Udell"
               author_email="sterling.udell+gadgets@gmail.com"
               author_location="North Wales, UK"
               author_affiliation="Udell Enterprises, Inc"
               author_photo="http://gad.getpla.net/images/my_photo.jpg"
               author_aboutme="Free-range programmer developing gadgets, map applications, and anything else that catches my interest."
               author_link="http://gad.getpla.net"
               author_quote="Is there no sun in this cursed country?">

    <!-- Both sharedmap and dynamic-height are required for full cross-API support -->
    <Require feature="sharedmap"/>
    <Require feature="dynamic-height" /> 
  </ModulePrefs>
  <Content type="html"><![CDATA[
    <p>
      Any content to appear on both platforms should go here.
    </p>
    <script type="text/javascript">
      var map;
      var isMapplet = !!window.GMap2;   // Are we running as a mapplet or not?
      if (!isMapplet)
      {
        // Not running as a mapplet => a few additional HTML elements are required
        document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2"><\/script>');
        document.write('<script type="text/javascript" src="' + 
          _IG_GetCachedUrl('http://gad.getpla.net/include/async.js') + '"><\/script>');
        document.write('<div id="map" style="height: 300px"></div>');
      }

      _IG_RegisterOnloadHandler(function ()
      {
        // Note that, for cross-API compatibility, all map init needs to be in here

        map = new GMap2(document.getElementById('map'));   // add any other map options you need - they'll be ignored in the mapplet

        if (isMapplet)
        {
          // Any mapplet-specific init for your own functionality goes in here

        }
        else
        {
          // Gadget-specific init goes in here

          // First, do setup required by the Maps API that's n/a to mapplets.
          //   This should be tailored to your functionality but will always include 
          //   _IG_AdjustIFrameHeight and setCenter, and usually some addControls

          _IG_AdjustIFrameHeight();
          map.setCenter(new GLatLng(53, -4), 12);

          map.addControl(new GMapTypeControl(true));
          map.addControl(new GSmallMapControl());

          // Second, do any setup specific to this gadget (put your own code in here)
        }

        // Other, non-API-specific initialization for this map/gadget

        GAsync(map, 'getCenter', function (center)          // Demo of GAsync
          {
            var marker = new GMarker(center);
            map.addOverlay(marker);
            GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('Hello world!')});
          });
      });

      // Define any other functions you need here
    </script>
  ]]></Content>
</Module>
