﻿var Sawbuck = window.Sawbuck || {}; Sawbuck.AreaHelper = function() {
	function renderNeighborhoods(list) {
		var box = document.createElement("div"); box.id = "neighborhoodsList"; box.title = "All Neighborhoods"; var column1 = document.createElement("div"); column1.style.cssFloat = "left"; column1.style.styleFloat = "left"; column1.style.width = "45%"; for (var i = 0; i < Math.ceil(list.length / 2); i++) { var entry = document.createElement("a"); var li = document.createElement("li"); li.className = "neighboorhoods"; entry.href = Sawbuck.Page.getURL() + list[i].Url; entry.innerHTML = list[i].AreaName; entry.className = "hash"; entry.onclick = function() { Sawbuck.MapManager.switchArea(list[i].GeographicAreaID); return false; }; li.appendChild(entry); column1.appendChild(li); }
		box.appendChild(column1); var column2 = document.createElement("div"); column2.style.cssFloat = "right"; column2.style.styleFloat = "right"; column2.style.textAlign = "left"; column2.style.width = "50%"; for (var i = Math.ceil(list.length / 2) + 1; i < list.length; i++) { var entry = document.createElement("a"); var li = document.createElement("li"); li.className = "neighboorhoods"; entry.href = Sawbuck.Page.getURL() + list[i].Url; entry.innerHTML = list[i].AreaName; entry.className = "hash"; li.appendChild(entry); column2.appendChild(li); }
		box.appendChild(column2); var clear = document.createElement("div"); clear.className = "clear"; box.appendChild(clear); document.body.appendChild(box); $j("#neighborhoodsList").dialog({ buttons: { OK: function() { $j(this).dialog('close'); } }, width: 500, height: 400, maxHeight: 600 }); Sawbuck.SearchManager.changeHashLinks();
	}
	function showAllNeighborhoods(areaID) { var data = { AreaID: areaID }; $j.ajax({ type: "POST", url: "/service/WebService.asmx/GetAllChildAreas", data: Sawbuck.Utilities.toJson(data), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function(response) { renderNeighborhoods(response.d); }, error: function() { } }); }
	function updateRSSLink() { var hash = Sawbuck.SearchManager.getHash().replace(/#/, "").replace(/a_([^\/]*)\//, ""); var q = "?"; q += (hash.length > 0) ? hash.replace(/\//g, "&").replace(/_/g, "=") : ""; var bounds = Sawbuck.MapManager.getBounds(); delete bounds["big"]; q += "&lat=" + bounds.latMin + "," + bounds.latMax; q += "&lng=" + bounds.lngMin + "," + bounds.lngMax; jQuery("a.rssLink").each(function() { this.href = (this.getAttribute("href").split("?")[0] + q); this.className = "rssLink"; }); }
	return { showAllNeighborhoods: function(areaID) {
		if (document.getElementById("neighborhoodsList"))
			$j("#neighborhoodsList").dialog("open"); else
			showAllNeighborhoods(areaID);
	}, updateRSSLink: updateRSSLink}
	} ();