/**
 *  Google Map Utile Script
 *  Author: The Thunderbird 
 */ 


/* var declaration */

var map;
var geocoder = null; 
var address;
var bodytext;

var hotelkey_arr = [];
var caption_arr = [];
var address_arr = [];

/* additional vars */
var phone_arr = [];
var image_arr = [];

var markerbody_arr = [];
var infotab_arr = [];    

function createMarkersandShow(hotelshow) {
  
    for(k=0;k<hotelkey_arr.length;k++){
      
      /* form the marker body html */
      html = "<div class='mapbodycontainer'>";
      html += "<p class='mapparagraph' style='padding:0px;margin:0px'>" + caption_arr[k] + "</p>";
      html += "<p class='mapparagraph' style='padding:0px;margin:0px'>" + address_arr[k] +"</p>";
      html += "<p class='mapparagraph' style='padding:0px;margin:0px;margin-bottom: 20px'>" + phone_arr[k] +"</p>";
      html += "</div>";
      
      markerbody_arr[k] = html;
      
      infotab_arr[k] = [
         new GInfoWindowTab(
            "Information", markerbody_arr[k]
          ),
          new GInfoWindowTab("Direction", "<span id='mapdirection' class='infotabbody'><p>Enter your address and then click \"Go\" for direction.</p><form method='get' action='http://maps.google.com/maps' target='_blank'><input type='text' name='saddr' style='width:200px'></input><input type='hidden' name='daddr' value='" + address_arr[k] + "'></input><input type='submit' value='Go'></input></form></span>")
      ];
      
      
      if(hotelkey_arr[k] == hotelshow){
        createMarker(address_arr[k],infotab_arr[k],1);
      }
      else{
        createMarker(address_arr[k],infotab_arr[k],0);
      }    
    }
  
}

function createMarker(address,infotab_arr,showbody){
   
   if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          /*alert(address + " not found");*/
        } else {
          
          var marker = new GMarker(point);        
          GEvent.addListener(marker, "click", function() {
              marker.openInfoWindowTabsHtml(infotab_arr);
          });
          map.addOverlay(marker);
          
          /* should show body */
          if(showbody == 1){
            marker.openInfoWindowTabsHtml(infotab_arr);
            map.setCenter(point, 10);
          }
          
        }
      }
    );
    
  }
}


function showMap(mapkeyname){
  
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(37.38949, -122.07846), 11);
    geocoder = new GClientGeocoder();

    initMapData();
    
    createMarkersandShow(mapkeyname);
    
  
  }
  
  
  
}


function initMapData(){
  /* Arena Hotel */
  hotelkey_arr.push("arena");
  caption_arr.push("Arena Hotel");
  address_arr.push("817 The Alameda,San Jose,CA 95126");
  phone_arr.push("408-294-6500");
  image_arr.push("../mapimages/arena_shot.jpg");  
  
  /* Valley Park Hotel*/
  hotelkey_arr.push("valleypark");
  caption_arr.push("Valley Park Hotel");
  address_arr.push("2404 Stevens Creek Blvd., San Jose, CA 95128");
  phone_arr.push("408-293-5000");
  image_arr.push("../mapimages/valleypark_shot.jpg");
  
  
  /* Crestview Hotel */
  hotelkey_arr.push("crestview");
  caption_arr.push("Crestview Hotel");
  address_arr.push("901 E El Camino Real,Mountain View, CA 94040");
  phone_arr.push("650-966-8848");
  image_arr.push("../mapimages/crestview_shot.jpg");
  
  /* The Hotel Lodge */
  hotelkey_arr.push("hotellodge");
  caption_arr.push("Hotel Lodge");
  address_arr.push("64 W El Camino Real, Mountain View, CA 94040");
  phone_arr.push("650-965-0585");
  image_arr.push("../mapimages/hotellodge_shot.jpg");
  
  /* The Pacific Inn of Redwood City */
  hotelkey_arr.push("redwoodcity");
  caption_arr.push("Pacific Inn of Redwood City");
  address_arr.push("2610 El Camino Real, Redwood City, CA 94061");
  phone_arr.push("650-368-1495");
  image_arr.push("../mapimages/redwoodcity_shot.jpg");
  
  /* The Pacific Inn of Sunnyvale */
  hotelkey_arr.push("sunnyvale");
  caption_arr.push("The Pacific Inn of Sunnyvale");
  address_arr.push("170 S. Sunnyvale Ave, Sunnyvale, CA 94086");
  phone_arr.push("408-732-1760");
  image_arr.push("../mapimages/sunnyvale_shot.jpg");
  
      /* Bayside Inn */
  hotelkey_arr.push("bayside");
  caption_arr.push("Bayside Inn at the Wharf");
  address_arr.push("1201 Columbus Ave San Francisco, CA");
  phone_arr.push("415-776-7070");
  image_arr.push("../mapimages/bayside_shot.jpg");
  
  
  
}
