var $jq = jQuery.noConflict();
$jq(document).ready(function(){
		
		// initialize google map
		if (GBrowserIsCompatible() && ($jq('input[name=maplat]').size() > 0)) {
		
		    var typ = $jq('input[name=t]').val();
        	var map = new GMap2(document.getElementById("map_canvas"));
		    var center = new GLatLng($jq('input[name=maplat]').val(), 
		                             $jq('input[name=maplng]').val());
		    map.setCenter(center, 13);

			// Creates a marker whose info window displays the letter 
			// corresponding to the given index.
			function createMarker(point, index, html) {
			  var letteredIcon = new GIcon(G_DEFAULT_ICON);
			  if(typ == 'item'){
			  	letteredIcon.image = "/img/flags/flag-lg-red-" + index + ".png";
			  }else{
			    letteredIcon.image = "/img/flags/flag-lg-green-" + index + ".png";
			  }
			  var marker = new GMarker(point, { icon:letteredIcon });
			  GEvent.addListener(marker, "click", function() {map.openInfoWindowHtml(point, html); });
			  return marker;
			}
		
		   var idx = 0;
		   var bounds = new GLatLngBounds();
		   $jq('div[class^=additional-info]').each(function(){
		        var html = $jq(this).find("div.content").html();
		        var slat = $jq(this).find("div.slatitude").html();
		        var slng = $jq(this).find("div.slongitude").html();
		        var point = new GLatLng(slat,slng);
		        var marker = createMarker(point,++idx,html);
		   		map.addOverlay(marker);
		   		bounds.extend(marker.getPoint());
		   		
		   		// $jq(this).prev("h3 > a.menu")
		   		//	.mouseover(function(){
		   		//		map.openInfoWindowHtml(point, html);
		   		//		$jq("#result-display").html(html);
		   		//		$jq('a.cluetip').cluetip({local:true, width:200,cursor: 'pointer',dropShadow: false,showTitle: false, mouseOutClose:true});
		   		//	})
		   		//	.mouseout(function(){map.closeInfoWindow();});
	       });
	       
	       // Reset center and zoom level based on queried hotel locations 
		   map.setCenter(bounds.getCenter());
		   map.setZoom(map.getBoundsZoomLevel(bounds)); 
	     }
});