	function add(property_key) {
		Fed.Faves.add(property_key);
		Fed.Faves.refreshHeader();
		$("#add-" + property_key).remove();
		alert("This property has been added to your favorites list!\nClick My Favorites in the upper right to compare your favorites.");
		return false;
	}

	var Email = {
		prepare: function() {
			$("#email-form").html($("#email-form").html().replace("<p><big><b>Message sent!</b></big></p>", ""));
			var v = $("#email-message").val();
			v = v.replace(/http:\/\/.*list.*-e/, "");
			if (0) {
			var d = document.domain;
			var arrive = $("#arrive").val().replace(/\//g, "");
			var depart = $("#depart").val().replace(/\//g, "");
			var landmark = $("#landmark").val();
			var hotel_lst = fnotempty(fpluck(hotels, "property_key")).join(",");
			var url = "http://" + d + "/list?" + arrive + "-" + depart + "-" + landmark + "-" + hotel_lst + "-e";
			}
			var url = location.href;
			$("#email-message").val(v + url);
		},

		send: function() {
			var from_ = $("#email-from").val();
			var to_ = $("#email-to").val();
			var msg = $("#email-message").val();

			if (!from_ || !from_.match(/.+@.+/) ||
					!to_ || !to_.match(/.+@.+/) ||
					!msg)
				return alert("You must fill out all fields before the email can be sent!");

			$("#email-go").attr("disabled", "disabled");
			$.post("/list_email",
				{
					from: from_,
					to: to_,
					msg: msg
				},
				Email.thanks
			);
		},

		thanks: function() {
			$("#email-form").html("<p><big><b>Message sent!</b></big></p>" + $("#email-form").html());
			$("#email-go").attr("disabled", "");
			setTimeout(tb_remove, 2500);
		}
	};

	function get_idx_for_hotel_id(hotel_id) {
		for (var idx in hotels) {
			if (hotels[idx].property_key == hotel_id)
				return idx;
		}
		return -1;
	}

	function get_hotel_id_for_idx(idx) {
		return hotels[idx].property_key;
	}

	function init() {
		// hover-over effect for data cells
		$(".data-cell").hover(
			function() {
				// the row gets a light highlight
				var id = this.id.replace(/^.*-.*-/, "");
				$("#row" + id).addClass("highlight1");
				$("#more-info-row-" + id).addClass("highlight1");  //**CHANGE LINE
				return;

				// the row gets a very light highlight
				var id = this.id.replace(/-[0-9]+/, "");
				$("//td[@id^=" +id + "]").addClass("highlight2");
			},
			function() {
				var id = this.id.replace(/^.*-.*-/, "");
				$("#row" + id).removeClass("highlight1");
				$("#more-info-row-" + id).removeClass("highlight1");  //**CHANGE LINE
				return;

				var id = this.id.replace(/-[0-9]+/, "");
				$("//td[@id^=" +id + "]").removeClass("highlight2");
			}
		);
		// mark name field as sorted ascending
		$("#comp th").eq(1).addClass("sort-down");

		setTimeout(
			function() {
			$("#comp").tablesorter({
				doneCallback: MoreInfo.refreshAll,
				startCallback: function() {
					$("#comp").trigger("update");
					MoreInfo.closeAll();
				},
				0: {
					sorter: false
				},
				4: {
					sorter: "floating"
				},
				5: {
					sorter: "text"
				},
				6: {
					sorter: false
				}
			})
			}, 2000
		);
	}

	function interp(str, arr) {
		for (var i in arr) {
			str = str.replace('{' + i + '}', arr[i]);
		}
		return str;
	}

	var MoreInfo = {

		// vars
		idx: -1,
		idxToPropertyKey: {},

		closeAll: function(cell) {
			if (cell) {
				$("#comp th").lt(cell).removeClass("sort-down").removeClass("sort-up");
				$("#comp th").gt(cell).removeClass("sort-down").removeClass("sort-up");
				var e = $("#comp th").eq(cell);
				if (e.is(".sort-up"))
					e.removeClass("sort-up").addClass("sort-down");
				else if (e.is(".sort-down"))
					e.removeClass("sort-down").addClass("sort-up");
				else
					e.addClass("sort-down");
			}
			$(".more-info-row").remove();
			$(".more-info-open").removeClass("more-info-open");
		},

		createEmptyPane: function(idx) {
			var new_div = $("<tr id='more-info-row-" + idx + "' class='more-info-row'><td colspan='5' class='more-info data-cell' id='more-info-" + idx + "'>&nbsp;</td></tr>");  //**CHANGE LINE
			new_div.insertAfter($("#row" + idx));
			$("#row" + idx).addClass("more-info-open");
			$("#more-info-" + idx).html(Fed.Html.loading);
		},

		displayProfile: function(data) {
			var parts = data.split("====");
			var idx = parts[0];
			var data = parts[1];
			$("#more-info-" + idx).html(data);
			MoreInfo.Map.load(idx);
		},

		getProfile: function(property_key, idx) {
			$.get("/list_info", { hotel_id: property_key, idx: idx }, MoreInfo.displayProfile);
		},
		
		Map: {
			getHtml: function(idx) {
				var name = hotels[idx].name;
				var address_1 = hotels[idx].address;
	    	var html = "";
	    	html = html + "<strong>" + name + "</strong>";
	    	return html;
	    },
	    load: function(idx) {
	      if (GBrowserIsCompatible()) {
	        var map = new GMap2($("#map" + idx).get(0));
	       	map.addControl(new GSmallMapControl());
	        //map.addControl(new GMapTypeControl());
	        var geocoder = new GClientGeocoder();
	        var address = hotels[idx].address;
					var point = new GLatLng(hotels[idx].latitude, hotels[idx].longitude);
					map.setCenter(point, 13);
					var marker = new GMarker(point);
					map.addOverlay(marker);
	      }
	    }
	  },

		// display (or close) the more info pane for given property
		open: function(property_key, idx) {
			if (!($("#more-info-row-" + idx).get(0))) {
				// more info pane doesn't exist? create it
				MoreInfo.createEmptyPane(idx);
				MoreInfo.idxToPropertyKey[idx] = property_key;
				MoreInfo.getProfile(property_key, idx);
				$("#details-" + idx).html("Hide details").addClass("details-link-hide"); //**CHANGE LINE
				return false;
			} else {
				// if they clicked this a second time, hide it
				delete MoreInfo.idxToPropertyKey[idx];
				$("#more-info-row-" + idx).remove();
				$("#row" + idx).removeClass("more-info-open");
				$("#details-" + idx).html("Show details").removeClass("details-link-hide"); //**CHANGE LINE
				return false;
			}
		},

		Photo: {
			next: function(property_key) {
				$("#pic-" + property_key + " img").attr("src", "/assets/shared/loading.gif");
				var pics = eval("pics_" + property_key);
				var cur = eval("pics_" + property_key + "_cur");
				var last_i = 0;
				var seen = 0;
				for (var i in pics) {
					if (cur == last_i) {
						MoreInfo.Photo.set(property_key, pics[i]);
						seen = 1;
						eval("pics_" + property_key + "_cur = " + i);
						break;
					} else
						last_i = i;
				}
				if (!seen) {
					for (var first_idx in pics) {
						break;
					}
					MoreInfo.Photo.set(property_key, pics[first_idx]);
					eval("pics_" + property_key + "_cur = " + first_idx);
				}
			},

			set: function(property_key, url) {
				$("#pic-" + property_key +" img").attr("src", url);
			}
		},

		refreshAll: function() {
			MoreInfo.closeAll();
			for (var idx in MoreInfo.idxToPropertyKey) {
				var prop = MoreInfo.idxToPropertyKey[idx];
				MoreInfo.createEmptyPane(idx);
				MoreInfo.getProfile(prop, idx);
			}
		}
	}

	$(document).ready(init);