﻿
if (GBrowserIsCompatible()) {
	  // === Get Query String
	  var qString = location.search.substring(4);
	
      // ==== first part of the select box ===
      var select_html = '<select onChange="handleSelected(this)">' +
                        '<option selected> - Select a location - </option>';
      // =====================================
      var gmarkers = [];
      var htmls = [];
	  var gName = [];
      var i = 0;


      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers[i] = marker;
        htmls[i] = html;
		gName[name] = marker;
        
        // ======= Add the entry to the select box =====
        select_html += '<option> ' + name + '</option>';
        // ==========================================================
        
        i++;
        return marker;
      }


      // ======= This function handles selections from the select box ====
      // === If the dummy entry is selected, the info window is closed ==
      function handleSelected(opt) {
        var i = opt.selectedIndex - 1; 
        if (i > -1) {
          GEvent.trigger(gmarkers[i],"click");
        }
        else {
          map.closeInfoWindow();
        }
      }


// Set up the copyright information
// Each image used should indicate its copyright permissions
var myCopyright = new GCopyrightCollection("© ");
myCopyright.addCopyright(new GCopyright('Demo',
  new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)),
  0,'©2007 Google'));

// Create the tile layer overlay and 
// implement the three abstract methods                 
var tilelayer = new GTileLayer(myCopyright);
tilelayer.getTileUrl = function() { return "images/blank.jpg"; };
tilelayer.isPng = function() { return false;};
tilelayer.getOpacity = function() { return 1.0; }


  // create the map
	function initialize() {
    var myTileLayer = new GTileLayerOverlay(tilelayer);
 	var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(21.290334,-157.838516), 13);
	map.addOverlay(myTileLayer);

      
// ======= Ground Overlay ====
	var boundaries = new GLatLngBounds(new GLatLng(21.268821,-157.892933), new GLatLng(21.316965,-157.809849));
	var Level1 = new GGroundOverlay("images/levelone.jpg"		
	, boundaries);
	map.addOverlay(Level1);
	
	  // ======= Disable Dragging & open info window ==== map.disableDragging()


	
	
	// ======= Disables Zooming====
	var mapTypes = G_DEFAULT_MAP_TYPES;
		for(var i = 0; i < mapTypes.length; i++){
			mapTypes[i].getMaximumResolution = function(latlng){ return 13;};
			mapTypes[i].getMinimumResolution = function(latlng){ return 13;};
		}
		
		
		

    // add the points 
	  
	  var point = new GLatLng(21.29241331670117, -157.81774520874023);
      var marker = createMarker(point,"Auditorium","<h4>Auditorium</h4><ul><li>Visit the <a href='http://www.scheduling.wsu.edu' target='blank'>Scheduling Website</a> to Reserve this space </li></ul>")
      map.addOverlay(marker);
	
      var point = new GLatLng(21.30136988846569, -157.8761100769043);
      var marker = createMarker(point,"TheBookie","<h4>The Bookie</h4><ul><li>(509) 332-2537</li><li><a href='http://wsubookie.bncollege.com' target='blank'>wsubookie.bncollege.com</a>")
      map.addOverlay(marker);

      var point = new GLatLng(21.294492569503646, -157.88640975952148);
      var marker = createMarker(point, "TheBookieCafe", "<h4>The Bookie Cafe</h4><ul><li>(509) 332-2537</li><li><a href='http://cub.wsu.edu/shop_dine_bookiecafe.aspx' target='blank'>cub.wsu.edu/shop_dine_bookiecafe.aspx</a></li></ul>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.295292274288997, -157.86048889160156);
	  var marker = createMarker(point, "Carlitas", "<h4>Carlita's</h4><ul><li>(509) 335-8595</li><li><a href='http://cub.wsu.edu/shop_dine_carlitas.aspx' target='blank'>cub.wsu.edu/shop_dine_carlitas.aspx</a></li></ul>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.28809477460972, -157.83422470092773);
	  var marker = createMarker(point, "CUBAdministration", "<h4>CUB Administration</h4><ul><li>CUB 140</li><li>(509) 335-9444</li><li><a href='mailto:cub.adminfront@wsu.edu'>cub.adminfront@wsu.edu</a></li><li><a href='http://cub.wsu.edu/about_admin.aspx' target='blank'>cub.wsu.edu/about_admin.aspx</a></li></ul>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.31272475713391, -157.8289031982422);
      var marker = createMarker(point,"CUBTower","<h4>CUB Tower</h4>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.30168975593375, -157.85104751586914);
      var marker = createMarker(point,"FoodCourt","<h4>Food Court</h4>")
      map.addOverlay(marker);

      var point = new GLatLng(21.289973188189193, -157.86117553710938);
      var marker = createMarker(point, "Freshens", "<h4>Freshëns</h4><ul><li>(509) 335-8595</li><li><a href='http://cub.wsu.edu/shop_dine_freshens.aspx' target='blank'>cub.wsu.edu/shop_dine_freshens.aspx</a></li></ul>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.282336521195344, -157.81362533569336);
      var marker = createMarker(point,"Gallery","<h4>Art Gallery</h4>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.284735820850408, -157.8434944152832);
	  var marker = createMarker(point, "InformationDesk", "<h4>Information Desk</h4><ul><li>(509) 335-8426</li></ul>")
      map.addOverlay(marker);

	  var point = new GLatLng(21.27561827396124, -157.85911560058594);
      var marker = createMarker(point,"Lair","<h4>Lair</h4>")
      map.addOverlay(marker);

      var point = new GLatLng(21.308886589867587, -157.86066055297852);
      var marker = createMarker(point, "PandaExpress", "<h4>Panda Express</h4><ul><li>(509) 332-7310</li><li><a href='http://cub.wsu.edu/shop_dine_pandaxpress.aspx' target='blank'>cub.wsu.edu/shop_dine_pandaxpress.aspx</a></li></ul>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.27561827396124, -157.8325080871582);
      var marker = createMarker(point,"QuietLounge","<h4>Quiet Lounge</h4>")
      map.addOverlay(marker);

      var point = new GLatLng(21.289935820850408, -157.8451944152832);
      var marker = createMarker(point, "Redbox", "<h4>Redbox</h4><ul><li>(509) 335-8595</li><li><a href='http://cub.wsu.edu/shop_dine_redbox.aspx' target='blank'>cub.wsu.edu/shop_dine_redbox.aspx</a></li></ul>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.299770540681386, -157.86117553710938);
	  var marker = createMarker(point, "Subway", "<h4>Subway</h4><ul><li>(509) 334-0615</li><li><a href='http://cub.wsu.edu/shop_dine_subway.aspx' target='blank'>cub.wsu.edu/shop_dine_subway.aspx</a></li></ul>")
      map.addOverlay(marker);
	  
	  var point = new GLatLng(21.304568531812233, -157.86066055297852);
	  var marker = createMarker(point, "VillaFreshItalianKitchen", "<h4>Villa Fresh Italian Kitchen</h4><ul><li>(509) 332-2700</li><li><a href='http://cub.wsu.edu/shop_dine_villa.aspx' target='blank'>cub.wsu.edu/shop_dine_villa.aspx</a></li></ul>")
	  map.addOverlay(marker);
  

                       
      // put the assembled side_bar_html contents into the side_bar div
     document.getElementById("selection").innerHTML = select_html;
	 
 
	 //Get Map Value and display box
 		if (qString != "") {
          GEvent.trigger(gName[qString],"click");
        }
	 
	}
}


