function SortListing(Action) { 
	SetClasses();
	//document.getElementById("li" + Action).setAttribute("class", "Selected");
	//document.getElementById("a" + Action).setAttribute("class", "Selected");
	$("a#a" + Action).addClass("Selected");
	$("li#li" + Action).addClass("Selected");
	switch(Action) { 
		case "LowestPrice" : 
			SetLowestPrice("up");
			break;
		case "StarRating":
			SetStarRatingTopDown("down");
			//document.getElementById("frmStarRating").style.display="";
			//document.getElementById("TabForm").style.height="50px";	
			break;
		case "RoomType":
			//document.getElementById("frmRoomType").style.display="";
			//document.getElementById("TabForm").style.height="50px";	
		case "MostPopular":
			SetDefault();
	}
}
function SetRoomTypes() {
	var	value = document.getElementById("ddlRoomType").options[document.getElementById("ddlRoomType").selectedIndex].text;
	value = value.substring(0,1);
	for(var i=0;i<Properties.length;i++) {
		if(document.getElementById("ddlRoomType").selectedIndex==0) {
			document.getElementById("dv" + Properties[i].PropertyID).style.display="";
		 }
		 else { 
			if(Properties[i].AccommTypes.indexOf(value)>-1) { 
				document.getElementById("dv" + Properties[i].PropertyID).style.display="";
			}
			else {
				document.getElementById("dv" + Properties[i].PropertyID).style.display="none";
			} 			
		 }
	 }
}
function SetStarRating(value) { 
	var style="none";
	var bShow=false;
	
	alert(Properties.toSource());
	for(var i=0;i<Properties.length;i++) {
	style="none";
		if(value==6 && Properties[i].Rating==5) {style="";}
		if(value==55 && Properties[i].Rating==6) {style="";}
		if(value==5 && (Properties[i].Rating==66 || Properties[i].Rating==7 || Properties[i].Rating==75)) {style="";}		
		if(value==45 && (Properties[i].Rating==8 || Properties[i].Rating==65 || Properties[i].Rating==74)) {style="";}		
		if(value==4 && (Properties[i].Rating==9 || Properties[i].Rating==64 || Properties[i].Rating==73)) {style="";}
		if(value==35 && (Properties[i].Rating==10 || Properties[i].Rating==63 || Properties[i].Rating==72)) {style="";}		
		if(value==3 && (Properties[i].Rating==11 || Properties[i].Rating==62 || Properties[i].Rating==71)) {style="";}				
		if(value==25 && (Properties[i].Rating==49 || Properties[i].Rating==61 || Properties[i].Rating==70)) {style="";}				
		document.getElementById("dv" + Properties[i].PropertyID).style.display=style;
		
	}		
}
function SetDefault() { 
	var prop = Properties[0].PropertyID;
	Properties.sort(DefaultSearch);
	for(var i=0;i<Properties.length;i++) {
		if(Properties[i].PropertyID!=prop) { 
			document.getElementById("dv"+Properties[i].PropertyID).style.display="";
			$("#dv"+Properties[i].PropertyID).insertBefore("#dv"+prop);
		}
		prop = Properties[i].PropertyID;
	}
}
function DefaultSearch(a,b) { 
	return a.Default-b.Default;
}
function SetLowestPrice(direction) { 
	var prop = Properties[0].PropertyID;
	if (direction == "up") {
		Properties.sort(lp);
	} else if (direction = "down") {
		Properties.sort(hp);
	}
	for(var i=0;i<Properties.length;i++) {
		if(Properties[i].PropertyID!=prop) { 
			document.getElementById("dv"+Properties[i].PropertyID).style.display="";
			$("#dv"+Properties[i].PropertyID).insertBefore("#dv"+prop);
		}
		prop = Properties[i].PropertyID;
	}
}
function SetStarRatingTopDown(direction) { 
	var prop = Properties[0].PropertyID;
	if (direction == "up") {
		Properties.sort(lsr);
	} else if (direction = "down") {
		Properties.sort(hsr);		
	}
	for(var i=0;i<Properties.length;i++) {
		if(Properties[i].PropertyID!=prop) { 
			document.getElementById("dv"+Properties[i].PropertyID).style.display="";
			$("#dv"+Properties[i].PropertyID).insertBefore("#dv"+prop);
		}
		prop = Properties[i].PropertyID;
	}
}
function lp(a,b) { 
	return b.Price-a.Price;
}

function hsr(a,b) { 
	return a.Rating - b.Rating;
}

function hp(a,b) { 
	return a.Price-b.Price;
}

function lsr(a,b) { 
	return b.Rating-a.Rating;
}
function SetClasses() { 
	$("a#aMostPopular").removeClass("Selected");
	$("li#liMostPopular").removeClass("Selected");
	
	$("a#aLowestPrice").removeClass("Selected");
	$("li#liLowestPrice").removeClass("Selected");
	
	$("a#aStarRating").removeClass("Selected");
	$("li#liStarRating").removeClass("Selected");
	//document.getElementById("TabForm").style.height="3px";
	//document.getElementById("frmStarRating").style.display="none";
	document.getElementById("frmRoomType").style.display="none";
	$("a#aRoomType").removeClass("Selected");
	$("li#liRoomType").removeClass("Selected");
}
var gPropertyID;
function ShowPMap(PropertyID, PropName) { 
	gPropertyID=PropertyID;
	if(document.getElementById('dvMap' + PropertyID).style.display=="none") { 
		var img = new Image();
		img.id = "img" + PropertyID;
		img.src="/images/loadingbar.gif";
		document.body.appendChild(img);
		$("#img"+PropertyID).insertBefore("#fr"+PropertyID);
		document.getElementById("fr" + PropertyID).src="/hotel-map/" + PropName + ".html";
	}
	else { 				
		
	}
	SlideDiv('dvMap' + PropertyID);
}
function iFrameLoaded(PropName) { 

	var img = document.getElementById("img" + gPropertyID);
	img.parentNode.removeChild(img);

}
function HideMapImg(PropertyID) { 	
	document.getElementById("fr" + PropertyID).style.display="";
}
function SlideDiv(dv) { 
	$("div#" +dv).slideToggle("slow");
	
}

	function findMarker(id) {
	var mLen = markers.length;
		for (x = 0; x < mLen; x++) {
			if (id == markers[x].propertyid) { return x; x = mLen; }
		}
	}
		  
	function createMarkerClickHandler(marker, text, address, link, image, price) {
	  return function() {
		var showPrice = '';
		openMap(1, -1);
		document.location.href = '#summit';
		if (price != 0) {
			showPrice = '<strong>Prices from $' + price + ' per night.</strong><br><br>';
		}
		var txtItem = '<table class=\'sz11 fs2\'><tr><td style=\'width: 65px\' valign=\'top\'><img class=\'pixBox\' rel=\'mini-pics\' width=\'55\' height=\'55\' src=\'' + image + '\'></td>' +
		'<td valign=\'top\' style=\'padding-left: 4px;\'><span class=\'sz12 bold\' style=\'color: #CC3300\'>' + text + '</span><br>' + address + '<br><br>' + showPrice + '<span style=\'color: #000000; font-weight: bold;\'><a target=\'_blank\' href=\'' + link + '\'>Go to ' + text + ' Website</a></span>' + 
		'<br><a href=\'#summit\' onClick=\'map.zoomIn();\'>Zoom In</a> - <a href=\'#summit\' onClick=\'map.zoomOut();\'>Zoom Out</a>' + 
		'</td></tr></table>';
		
		marker.openInfoWindowHtml(txtItem);
		return false;
	  };
	}
	
	function createMarker(pointData, iNum) {

	  var latlng = new GLatLng(pointData.lat, pointData.long);
	
	  var icon = new GIcon();
	  icon.image = '/images/pin-single-b.png';
	  icon.iconSize = new GSize(19, 19);
	  icon.iconAnchor = new GPoint(1, 18);
	  icon.infoWindowAnchor = new GPoint(17, 19);
	
	  opts = {
		"icon": icon,
		"clickable": true,
		"labelText": pointData.label,
		"labelOffset": new GSize(3, -18)
	  };
	 
	  var marker = new LabeledMarker(latlng, opts);
	  var handler = createMarkerClickHandler(marker, pointData.property, pointData.address, pointData.ws, pointData.image, pointData.price);
		
      GEvent.addListener(marker, "click", handler);
//	  GEvent.addListener(marker, "mouseover", handler);
//<div class="label">'+pointData.label+'</div>
	  var listItem = document.createElement('div');
	  listItem.innerHTML = '<a href="' + pointData.ws + '" target="_blank"><b>' + pointData.property + ' </b>[' + pointData.label + ']</a>';
	  listItem.getElementsByTagName('a')[0].onclick = handler;
	  handlers.push(handler);
		
	  document.getElementById('sidebar-list').appendChild(listItem);

	  return marker;
	}
	
	function createMarkerLM(pointData, iNum) {

	  var latlng = new GLatLng(pointData.lat, pointData.long);
	
	  var icon = new GIcon();
	  icon.image = '/images/' + pointData.label + '.png';
	  icon.iconSize = new GSize(30, 30);
	  icon.iconAnchor = new GPoint(1, 28);
	  icon.infoWindowAnchor = new GPoint(27, 30);
	
	  opts = {
		"icon": icon,
		"clickable": true,
		"labelText": '',
		"labelOffset": new GSize(3, -28)
	  };
	 
	  var marker = new LabeledMarker(latlng, opts);
	  var handler = createMarkerClickHandlerLM(marker, pointData.landmark, pointData.address, pointData.ws);
		
      GEvent.addListener(marker, "click", handler);
	  handlers.push(handler);
		
	  return marker;
	}
	
	function createMarkerClickHandlerLM(marker, landmark, address, url) {
	  return function() {
		openMap(1, -1);
		document.location.href = "#summit";	
		marker.openInfoWindowHtml('<table class=\'sz11 fs2\'><tr>' +
		'<td valign=\'top\' style=\'padding-left: 4px;\'><span class=\'sz12 bold\' style=\'color: #CC3300\'>' + landmark + '</span><br>' + address + '<br><br><span style=\'color: #000000; font-weight: bold;\'><a target=\'_blank\' href=\'' + url + '\'>Go to Website</a></span>' + 
		'<br><a href=\'#summit\' onClick=\'map.zoomIn();\'>Zoom In</a> - <a href=\'#summit\' onClick=\'map.zoomOut();\'>Zoom Out</a>' + 
		'</td></tr></table>'
		);
		return false;
	  };
	}
	
	function openMap(onoff, pid) {
	 	// 1 = open, 0 = close
		var mLay = document.getElementById("menu-layer");
		var mDiv = document.getElementById("mapdiv");
		if (onoff == 1) {
			// 
			document.location.href = '#summit';
			mLay.style.top = '725px';
			if (mapLoad == 0) {
				mDiv.style.display = 'block';
				loadMap();
			} else if (mapLoad == 1) {
				mDiv.style.display = 'block';
			}
			/*
			if (pid != -1) {
				var sDiv = document.getElementById("smap" + pid);
				sDiv.onclick();
			}
			*/
			// 
		} else if (onoff == 0) {
			if (mDiv.style.display = 'block') {
				mDiv.style.display = 'none';
				mLay.style.top = '400px';
				mapOpen = 0;		
			}
			//
		}
	
	}
	
    function loadMap() {
      if (GBrowserIsCompatible()) {
	  
	  	if (isG)
			zoomlevel = 14;
		else 
			zoomlevel = 13;
		
		map = new GMap2(document.getElementById("map"));

		var icon = new GIcon();
		icon.image = "/images/pin-single.png";
		icon.shadow = "/images/pin-single-shadow.png";
		icon.iconSize = new GSize(35, 32);
		icon.shadowSize = new GSize(41, 34);
		icon.iconAnchor = new GPoint(4, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
/*
		var icon2 = new GIcon();
		icon2.image = "/images/mm_blue_globe.png";
		icon2.shadow = /images/mm_grey_shadow.png";
		icon2.iconSize = new GSize(22, 34);
		icon2.shadowSize = new GSize(41, 34);
		icon2.iconAnchor = new GPoint(4, 20);
		icon2.infoWindowAnchor = new GPoint(5, 1);
*/
//		map.addControl(new GOverviewMapControl());
		map.addControl(new GSmallMapControl());
//		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.enableDoubleClickZoom();
//		map.setCenter(new GLatLng(lngX, latY), zoomlevel);
		map.setCenter(new GLatLng(markers[0].lat, markers[0].long), zoomlevel);

		//var marker = new GMarker(map.getCenter(), icon2);	
		//map.addOverlay(marker);


		// Create our "cluster" marker icon
		/*
		var clusterIcon = new GIcon();
		clusterIcon.image = '<%=gImageURL%>/system2/images/pin-cluster.png';
		clusterIcon.shadow = '<%=gImageURL%>/system2/images/pin-single-shadow.png';
		clusterIcon.iconSize = new GSize(35, 32);
		clusterIcon.shadowSize = new GSize(41, 34);
		clusterIcon.iconAnchor = new GPoint( 6, 20 );
		clusterIcon.infoWindowAnchor = new GPoint( 13, 3 );
		clusterIcon.infoShadowAnchor = new GPoint( 5, 1 );
		
		clusterer = new Clusterer(map);
		clusterer.icon = clusterIcon; 
		*/
				
		var to_htmls = [];
		var from_htmls = []; 
		
		  manager = new MarkerManager(map);
//		  markers.sort(function(a, b) { return (a.abbr > b.abbr) ? +1 : -1; });
		  
		  batch = [];
		  batchlm = [];
		  
		  vPropLoc.length = 0;
		  mLen = markers.length;
		  lLen = landmarks.length;
		  
		  var v = 0;
		  for (x = 0; x < mLen; x++) {
			batch.push(createMarker(markers[x], x));
			if (vPropID[v] == markers[x].propertyid) { vPropLoc.push(x); v++; }
		  }
		  
		  var vl = 0;
		  for (xl = 0; xl < lLen; xl++) {
			batchlm.push(createMarkerLM(landmarks[xl], xl));
		  }
		  
 		  manager.addMarkers(batchlm, 11);
		  manager.addMarkers(batch, 11);
		  manager.refresh(); 
			
			
		  for (w = 0; w < vPropLoc.length; w++) {
			tLocID = vPropLoc[w];
  			//document.getElementById("smap" + w).onclick = handlers[tLocID];
			/*
			document.getElementById("iflag" + w).innerHTML = (tLocID + 1);
			document.getElementById("iflag" + w).onclick = handlers[tLocID];
			document.getElementById("iflag" + w).style.display = 'block';
			*/
		  }
		  mapLoad = 1;
      }
    }
	