
	var map;
	var hotel;
	var radius;
	var aDate = "today";
	var dDate = "tomorrow";
	var aDay;
	var dDay;
	var aMonth;
	var dMonth;
	var months = new Array(13);

	months[0]  = "January";
	months[1]  = "February";
	months[2]  = "March";
	months[3]  = "April";
	months[4]  = "May";
	months[5]  = "June";
	months[6]  = "July";
	months[7]  = "August";
	months[8]  = "September";
	months[9]  = "October";
	months[10] = "November";
	months[11] = "December";


  //creates new icons for each category of event
  
  var iconLandmark = new GIcon(); 
  iconLandmark.image = '/images/marker-landmark.png';
  iconLandmark.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconLandmark.iconAnchor = new GPoint(25, 35);
  iconLandmark.infoWindowAnchor = new GPoint(25, 25);  
  
	var iconMusic = new GIcon(); 
  iconMusic.image = '/images/marker-music.png';
  iconMusic.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconMusic.iconAnchor = new GPoint(25, 35);
  iconMusic.infoWindowAnchor = new GPoint(25, 25);
  
  var iconTheatre = new GIcon(); 
  iconTheatre.image = '/images/marker-theatre.png';
  iconTheatre.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconTheatre.iconAnchor = new GPoint(25, 35);
  iconTheatre.infoWindowAnchor = new GPoint(25, 25);
  
  var iconArt = new GIcon(); 
  iconArt.image = '/images/marker-art.png';
  iconArt.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconArt.iconAnchor = new GPoint(25, 35);
  iconArt.infoWindowAnchor = new GPoint(25, 25);
  
  var iconComedy = new GIcon(); 
  iconComedy.image = '/images/marker-comedy.png';
  iconComedy.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconComedy.iconAnchor = new GPoint(25, 35);
  iconComedy.infoWindowAnchor = new GPoint(25, 25);
  
  var iconSport = new GIcon(); 
  iconSport.image = '/images/marker-sport.png';
  iconSport.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconSport.iconAnchor = new GPoint(25, 35);
  iconSport.infoWindowAnchor = new GPoint(25, 25);
  
  var iconChildren = new GIcon(); 
  iconChildren.image = '/images/marker-kids.png';
  iconChildren.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconChildren.iconAnchor = new GPoint(25, 35);
  iconChildren.infoWindowAnchor = new GPoint(25, 25);
  
  var iconWorld = new GIcon(); 
  iconWorld.image = '/images/marker-world.png';
  iconWorld.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconWorld.iconAnchor = new GPoint(25, 35);
  iconWorld.infoWindowAnchor = new GPoint(25, 25);
	
  var iconMarkets = new GIcon(); 
  iconMarkets.image = '/images/marker-markets.png';
  iconMarkets.iconSize = new GSize(45, 42);
  //iconMusic.shadowSize = new GSize(22, 20);
  iconMarkets.iconAnchor = new GPoint(25, 35);
  iconMarkets.infoWindowAnchor = new GPoint(25, 25);
	
	var customIcons = [];
	customIcons["0"] = iconLandmark;
	customIcons["1"] = iconMusic;
	customIcons["2"] = iconTheatre;
	customIcons["3"] = iconSport;
	customIcons["4"] = iconArt;
	customIcons["5"] = iconChildren;
	customIcons["6"] = iconWorld;
	customIcons["7"] = iconMarkets;
	customIcons["8"] = iconComedy;  
	customIcons["11"] = iconMusic;
	customIcons["12"] = iconMusic;

  function load() {
  	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(53.3504, -6.2531), 13);
		//alert(document.getElementById('vid').value);
		hotel = document.getElementById('vid').value;
		var searchUrl = '/scripts/genxml.php?hotel=' + hotel;
		//var searchUrl = '/scripts/genxml.php';

        GDownloadUrl(searchUrl, function(data) {
			var xml = GXml.parse(data);
			//alert(xml);
			updateResults(xml);
		});
	}
   }

	function createMarker(point, markerObj) {	
		//alert("create marker function called");
		var html = "";
		var marker = new GMarker(point, customIcons[markerObj.getAttribute("category")]);
	  //alert("the value of marker is " + marker);
	  if (markerObj.getAttribute("image") != null && markerObj.getAttribute("image") != "") {
	  	html = "<img class='pgImageBubble' src='/db.pepperguides.com/pics/thumb_" + markerObj.getAttribute("image") + "'>";
	  }
	  html += "<h1>" + markerObj.getAttribute("event") + "</h1>";
	  if (markerObj.getAttribute("name") != null) html += "<b>" + markerObj.getAttribute("name") + "</b><br/>";
	  if (markerObj.getAttribute("start") != null) html += markerObj.getAttribute("start") + " " + markerObj.getAttribute("duration") + "<br />";
	  if (markerObj.getAttribute("end") != markerObj.getAttribute("start")) html += "until " + markerObj.getAttribute("end") + "<br />";
	  html += markerObj.getAttribute("address") + "<br />";
	  html += markerObj.getAttribute("contact");
	  //alert("html = " + html);
	  //if (bodyText == '') { strBodyText = '&nbsp;'; }
	  //var infoTabs = [new GInfoWindowTab("Tab A", html), new GInfoWindowTab("Tab B", strBodyText),	new GInfoWindowTab("Tab C", "This is tab C content"), new GInfoWindowTab("Tab D", "This is tab D content")];
	  //var infoTabs = [new GInfoWindowTab("Tab A", html)];
	 // alert("infotabs = " + infoTabs);
      
    //  if(marker.maxWidth) opts = {maxWidth : marker.maxWidth}
      //marker.marker.openInfoWindowHtml(marker.text, opts);
    	maxWidth = 250;
    	GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(html,{maxWidth:maxWidth});			
		});
		 
                    
	  //alert("marker about to be returned ");
      return marker;
	  //alert("marker returned ");
   }
   
function createSidebarInfo() {
	var div = document.createElement('div');
  	div.className = 'pgSidebarInfo';
  	var html = "<h1>Viewing Events from " + aDate + " to " + dDate + "</h1><h2>Select an entry to locate venue on map</h2>";
  	div.innerHTML = html;
  	return div;
}
	
function createSidebarEntry(marker, markerObj) {
	var div = document.createElement('div');
	var html = "";
    if (markerObj.getAttribute("image") != "" && markerObj.getAttribute("image") != null) html = "<img class='pgSidebarImage' src='/db.pepperguides.com/pics/thumb_" + markerObj.getAttribute("image") + "'>";
    html += "<h1>";    
	//alert(markerObj.getAttribute("category"));
    if (markerObj.getAttribute("category") != null) {
    	html += "<img src='/images/icon-" + markerObj.getAttribute("category") + ".png'> "
    }
    html += markerObj.getAttribute("event") + "</h1>";
	  if (markerObj.getAttribute("name") != null) html += "<b>" + markerObj.getAttribute("name") + "</b><br/>";
	  if (markerObj.getAttribute("start") != null) html += "Date: " + markerObj.getAttribute("start") + " Time: " + markerObj.getAttribute("duration") + "<br />";
	  if (markerObj.getAttribute("end") != markerObj.getAttribute("start")) html += "until " + markerObj.getAttribute("end") + "<br />";
	  html += markerObj.getAttribute("address") + "<br/>";
	  html += markerObj.getAttribute("contact");
		div.innerHTML = html;
		div.className = 'pgSidebarEntry';
		
		GEvent.addDomListener(div, 'click', function() {
				GEvent.trigger(marker, 'click');
		});
		GEvent.addDomListener(div, 'mouseover', function() {
			div.style.backgroundColor = '#f2f2f2';
		});
		GEvent.addDomListener(div, 'mouseout', function() {
		  div.style.backgroundColor = '#fff';
		});
		return div;
	}

	
	function searchMap(){
		//alert("function searchMap called");
		cbResults = "";
		for (var i = 0; i < document.pgGeneratePDF.elements.length; i++ ) {		
        if (document.pgGeneratePDF.elements[i].type == 'checkbox') {        	
            if (document.pgGeneratePDF.elements[i].checked == true) {
            		if (cbResults.length > 0) cbResults += ',';
                cbResults += document.pgGeneratePDF.elements[i].value;
				//alert("the value of cbResults is " + cbResults);
            }
        }
    }
	
    hotel= document.getElementById('vid').value;
	  radius = document.getElementById('radius').value;
	  aDay = document.getElementById('aDaySelect').value;
	  dDay = document.getElementById('dDaySelect').value;
	  aMonth = document.getElementById('aMonthSelect').value;
	  dMonth = document.getElementById('dMonthSelect').value;	
		aDate = aDay + " " + months[aMonth-1];
		dDate = dDay + " " + months[dMonth-1];
	  

     var searchUrl = '/scripts/genxml.php?hotel=' + hotel + '&radius=' + radius + '&aDay=' + aDay + '&dDay=' + dDay + '&aMonth=' + aMonth + '&dMonth=' + dMonth + '&categories=' + cbResults;
 
	// alert(searchUrl);
      GDownloadUrl(searchUrl, function(data) {
        var xml = GXml.parse(data);
        updateResults(xml);
      });
    }
    
    
function updateResults(xml) {	
	
	var markers = xml.documentElement.getElementsByTagName('marker');  
	map.clearOverlays();
	
	var sidebar = document.getElementById('pgSidebar');
	if (sidebar) {
  		sidebar.innerHTML = '';
		sidebar.appendChild(createSidebarInfo());
	}
	if (markers.length == 0) {
		if (sidebar) sidebar.innerHTML = 'No results found.';
		map.setCenter(new GLatLng(53.3504, -6.2531), 13);
		return;
	}

	var bounds = new GLatLngBounds();
	for (var i = 0; i < markers.length; i++) {
		var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')), parseFloat(markers[i].getAttribute('lng')));
		var marker = createMarker(point, markers[i]);
		map.addOverlay(marker);
		//alert(markers[i].getAttribute('category'));
		if (sidebar && markers[i].getAttribute('category') != "0") { 
			var sidebarEntry = createSidebarEntry(marker, markers[i]);
			sidebar.appendChild(sidebarEntry);
		}
		bounds.extend(point);       
	}
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
}  
