function init() {
	emailCloak();
	toggleLocations();
	toggleneigh();
	togglezips();
	togglebuilding();
	selectAll();
	if(document.body.className == "home") {doFeatured();}
}

function emailCloak() {
	if (document.getElementById) {
		var alltags = document.all? document.all : document.getElementsByTagName("span");
		for (i=0; i < alltags.length; i++) {
		  if (alltags[i].className == "emailCloak") {
			var oldText = alltags[i].firstChild;
			var emailAddress = alltags[i].firstChild.nodeValue;
			var user = emailAddress.substring(0, emailAddress.indexOf("("));
			var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			var newText = user+"@"+website;
			var a = document.createElement("a");
			a.href = "mailto:"+newText;
			var address = document.createTextNode(newText);
			a.appendChild(address);
			alltags[i].replaceChild(a,oldText);
		  }
		}
	}
}

function toggleLocations() {
	var locationsToggle = document.getElementById("locationsToggle");
	locationsToggle.onclick = function() {
		if(this.className == "show") {
			this.className = "hide";
			this.innerHTML = "Click to hide locations";
			document.getElementById("locations").style.display = "block";
		}
		else {
			this.className = "show";
			this.innerHTML = "Click to show locations";
			document.getElementById("locations").style.display = "none";
		}
	}
}

function toggleneigh() {   //nbf
	var locationsToggle = document.getElementById("neighToggle");
	locationsToggle.onclick = function() {
		if(this.className == "show") {
			this.className = "hide";
			//this.innerHTML = "Hide Neighborhoods";
			document.getElementById("neighs").style.display = "block";
			//hide everything else
			document.getElementById("zips").style.display = "none";
			document.getElementById("zipToggle").className="show";
			document.getElementById("buildings").style.display = "none";
			document.getElementById("buildingToggle").className="show";
			}
		else {
			this.className = "show";
			//this.innerHTML = "Center City Neighborhoods";
			document.getElementById("neighs").style.display = "none";
		}
	}
}

function togglezips(force) {   //nbf
	var locationsToggle = document.getElementById("zipToggle");
	locationsToggle.onclick = function() {
		if(this.className == "show") {
			this.className = "hide";
			//this.innerHTML = "Hide zip codes";
			document.getElementById("zips").style.display = "block";
			//hide everything else
			document.getElementById("neighs").style.display = "none";
			document.getElementById("neighToggle").className="show";
			document.getElementById("buildings").style.display = "none";
			document.getElementById("buildingToggle").className="show";
		}
		else {
			this.className = "show";
			//this.innerHTML = "Philadelphia zip codes";
			document.getElementById("zips").style.display = "none";
		}
	}
}

function togglebuilding(force) {   //nbf
	var locationsToggle = document.getElementById("buildingToggle");
	locationsToggle.onclick = function() {
		if(this.className == "show") {
			this.className = "hide";
			document.getElementById("buildings").style.display = "block";
			//hide everything else
			document.getElementById("neighs").style.display = "none";
			document.getElementById("neighToggle").className="show";
			document.getElementById("zips").style.display = "none";
			document.getElementById("zipsToggle").className="show";
		}
		else {
			this.className = "show";
			document.getElementById("buildings").style.display = "none";
			document.getElementById("buildings").style.display = "none";
		}
	}
}


function show_locs() {
			var locationsToggle = document.getElementById("locationsToggle");
			locationsToggle.className = "hide";
			locationsToggle.innerHTML = "Click to hide locations";
			document.getElementById("locations").style.display = "block";
}

function selectAll() {
	var selectAll = document.getElementById("locationAll");
	selectAll.onclick = function() {
		var inputs = document.searchForm["id1[]"]
		if(selectAll.checked) {for(var q = 0; q < inputs.length; q++) {inputs[q].checked = true;}}
		else {for(var q = 0; q < inputs.length; q++) {inputs[q].checked = false;}}
	}
}

function doFeatured() {
	document.getElementById("thumb01").onmouseover = function() {document.getElementById("go01").className = "go hover2";}
	document.getElementById("thumb01").onmouseout = function() {document.getElementById("go01").className = "go";}
	document.getElementById("thumb02").onmouseover = function() {document.getElementById("go02").className = "go hover2";}
	document.getElementById("thumb02").onmouseout = function() {document.getElementById("go02").className = "go";}
	document.getElementById("go01").onmouseover = function() {document.getElementById("thumb01").className = "thumb hover1";}
	document.getElementById("go01").onmouseout = function() {document.getElementById("thumb01").className = "thumb";}
	document.getElementById("go02").onmouseover = function() {document.getElementById("thumb02").className = "thumb hover1";}
	document.getElementById("go02").onmouseout = function() {document.getElementById("thumb02").className = "thumb";}
}

function loginPopup() {
	var black = document.createElement('div');
	black.id = "black";
	document.body.appendChild(black);
	black.style.height = black.offsetTop + 'px';
	black.style.width = "100%"; black.style.position = "absolute"; black.style.left = "0"; black.style.top = "0";
	var popup = document.createElement('div');
	popup.id = "popup";
	var popupInt = document.createElement('iframe');
	popupInt.setAttribute('frameBorder', '0'); popupInt.setAttribute('marginwidth', '0'); popupInt.setAttribute('marginheight', '0'); popupInt.setAttribute('scrolling', 'no'); popupInt.setAttribute('border', '0');
	popupInt.src = "register.html";
	popup.appendChild(popupInt);
	document.body.appendChild(popup);
}

window.onload = init;
