   
var map = "";
var side_bar_html = "";
var gmarkers = [];
var htmls = [];
var ii = 0;
var  map_base = "";
var  img_base = "";
var  subsite  = "";
var icon = ""; 
var mapCenterZoom = "";




addLoadListener(showMap);

function showMap(){

    if (GBrowserIsCompatible()) {
  

      // A function to create the marker and set up the event window
      
       map_base = document.getElementById("mapxmlinfo").innerHTML; 
       img_base = document.getElementById("mapimginfo").innerHTML;  
      
      // create the map
       map = new GMap2(document.getElementById("map"));
       map.addControl(new GLargeMapControl());
       map.addControl(new GMapTypeControl());
       map.setCenter(new GLatLng(25.244695951306028, 135),4);
       
       // A function to read the data

      
      // When initially loaded, use the data from "map11a.xml"
        
       readMap("marlin.xml");
      
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm

}



  


     function createMarker(point,name,html,zm) {
     
          //alert(zm);
        var marker = new GMarker(point,icon);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers[ii] = marker;
        htmls[ii] = html;
        side_bar_html += '<tr><td><a href="javascript:myclick(' + ii + ',9)">' + name + '</a></td></tr>';
        ii++;
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i,zm) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
        map.setZoom(parseInt(zm));
        
        
      }      
      
       function readMap(url) {      
        
        var request = GXmlHttp.create();
        request.open("GET", map_base + url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
          // alert(request.responseText);
            var xmlDoc = GXml.parse(request.responseText);
            // obtain the array of markers and loop through it 
            
               
      
          
              var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            
          
            
                   
              var mapcenter = xmlDoc.getElementsByTagName("markers");
              
              mapCenterLat  =  mapcenter[0].getAttribute('mapCenterLat');
		 	        mapCenterLng  =  mapcenter[0].getAttribute('mapCenterLng');
              mapCenterZoom =  mapcenter[0].getAttribute("mapCenterZoom");
              map.setCenter(new GLatLng( mapCenterLat,mapCenterLng), parseInt(mapCenterZoom));
              
              //alert(mapCenterZoom);
          
            
            // hide the info window, otherwise it still stays open where the removed marker used to be
            
         
            
            
            map.getInfoWindow().hide();            
            map.clearOverlays(); 
              
            //map.setZoom(parseInt(mapCenterZoom));
            //  alert(mapCenterZoom);       
            
            // empty the arrays
            gmarkers = [];
            htmls = [];
            ii = 0;

            // reset the side_bar
            side_bar_html="";
            side_bar_html += '<table class="maps" cellpadding="5" cellspacing="1">';
       
            for (var i = 0; i < markers.length; i++) {
              // obtain the attribues of each marker
              var lat = parseFloat(markers[i].getAttribute("lat"));
              var lng = parseFloat(markers[i].getAttribute("lng"));
              var zm   = parseFloat(markers[i].getAttribute("zoom"));
              //alert(zm);
              var point = new GLatLng(lat,lng);
              var html = '<div class="map_info_desc"><img src="' + img_base + "maps/" +  markers[i].getAttribute("img") + '" width="104" height="104">' + markers[i].getAttribute("html") + '</div>';
              var label = markers[i].getAttribute("label");
              // create the marker
              var marker = createMarker(point,label,html,zm);
              map.addOverlay(marker);
              
            
              
          
            }
            side_bar_html += "</table>";
            
            // put the assembled side_bar_html contents into the side_bar div
            document.getElementById("side_bar").innerHTML = side_bar_html;
            
             //blink();
             
             
          
          
          
          
              


      

          }
        }
        request.send(null);
      }
      
      
      function show()
      {
      	if (document.getElementById)
      	document.getElementById("side_bar").style.visibility = "visible";
      }
      // blink "off" state
      function hide()
      {
      	if (document.getElementById)
      	document.getElementById("side_bar").style.visibility = "hidden";
      }
      // toggle "on" and "off" states every 450 ms to achieve a blink effect
      // end after 2700 ms (less than three seconds)
      function blink(){
      for(var i=900; i < 2700; i=i+900)
      {
      	setTimeout("hide()",i);
      	setTimeout("show()",i+450);
      }
      }
      
      
      
      
      

   
    
    
    
function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
};
