var Pittsburgh2050 = function(){
}

Pittsburgh2050 = {};
Pittsburgh2050.Settings = {mapBackgroundColor:"#000"};
Pittsburgh2050.Util = {div:document.createElement("div"),span:document.createElement("span"),a:document.createElement("a"),mapPopup:null,connection:new Ext.data.Connection({
				beforerequest:function(){},
				requestcomplete:function(){},
				requestexception:function(){}
				}),
				emailTimer:null,
				mapMoveEvent:null
			};
Pittsburgh2050.init = function(){
	
	var $$ = Ext.select;
		clearBaseText($$("#send-to-friend .your-email-input").elements[0],"Your Email");
		clearBaseText($$("#send-to-friend .friend-email-input").elements[0],"Friend's Email");
		clearBaseText($$("#update-me .email-input").elements[0],"Your Email");
		
		if($$("#entry .essay-box").elements.length){
		clearBaseText($$("#entry .essay-box").elements[0],"I want Pittsburgh to be...");
		clearBaseText($$("#entry .name-box").elements[0],"Your Name");
		clearBaseText($$("#entry .email-box").elements[0],"Email Address");
		clearBaseText($$("#entry .zip-box").elements[0],"Zip Code");
		}
		essayBox = $$("#entry .essay-box").elements[0];
		Ext.get($$("#about-this-site h2").elements[0]).on("click",function(e){
			dd = Ext.get($$("#about-this-site .email-drop-down").elements[0])
			Pittsburgh2050.hideSendToFriend();
			Pittsburgh2050.hideUpdateMe();
			if(dd.getStyle("display") != "block"){
				dd.setStyle("display","block");
			}else{
				dd.setStyle("display","none");
			}
		});
		Ext.get($$("#print-ads-link").elements[0]).on("click",function(e){
			Pittsburgh2050.printwindow = window.open('print-ads.aspx','printads','width=500,height=636,resizeable=no');
			Pittsburgh2050.printwindow.focus();
			this.setStyle("ouline","none");
			e.preventDefault();
			return false;
		})
		Ext.get($$("#send-to-friend h2").elements[0]).on("click",function(e){
			Pittsburgh2050.updateHideTimeOut()
			Ext.EventManager.addListener(window,"keydown",Pittsburgh2050.updateHideTimeOut);
			dd = Ext.get($$("#send-to-friend .email-drop-down").elements[0])
			Pittsburgh2050.hideUpdateMe();
			Pittsburgh2050.hideAboutThisSite();
			if(dd.getStyle("display") != "block"){
				dd.setStyle("display","block");
			}else{
				dd.setStyle("display","none");
			}
		});
		Ext.get($$("#send-to-friend .button").elements[0]).on("click",function(e){
			yourEl = $$("#send-to-friend .your-email-input").elements[0];
			your = yourEl.value;
			friendEl = $$("#send-to-friend .friend-email-input").elements[0];
			friend = friendEl.value
			var conn = Pittsburgh2050.Util.connection;
			conn.request(
			{
				url:"/service/v1/sendToFriend.aspx",
				params:{yourEmail:your,friendEmail:friend},
				method:"POST",
				callback:function(options,success,response){
					if(success){
						var responseObj = Ext.decode(response.responseText)
						if(responseObj.success){
							$$("#send-to-friend .form").elements[0].style.display = "none";
							$$("#send-to-friend .thank-you").elements[0].style.display = "block";
							$$("#send-to-friend .errors").elements[0].innerHTML = "";
							setTimeout(Pittsburgh2050.hideSendToFriend,1500);
						}else{
							var message = ""
							for(i = 0; i < responseObj.messages.length; i++){
								message += "<p class=\"alert\">"+responseObj.messages[i]+"</p>";
							}
							errors = $$("#send-to-friend .errors").elements[0];
							errors.style.display = "block"
							errors.innerHTML = message;
						}
					}
				}
			});
			e.stopEvent();
		});
		Ext.get($$("#update-me h2").elements[0]).on("click",function(e){
			Pittsburgh2050.updateHideTimeOut()
			Ext.EventManager.addListener(window,"keydown",Pittsburgh2050.updateHideTimeOut);
			dd = Ext.get($$("#update-me .email-drop-down").elements[0])
			Pittsburgh2050.hideSendToFriend();
			Pittsburgh2050.hideAboutThisSite();
			if(dd.getStyle("display") != "block"){
				dd.setStyle("display","block");
			}else{
				dd.setStyle("display","none");
			}
		});
		Ext.get($$("#update-me .button").elements[0]).on("click",function(e){
			
			yourEl = $$("#update-me .email-input").elements[0];
			
			your = yourEl.value;
			var conn = Pittsburgh2050.Util.connection;
			conn.request(
			{
				url:"/service/v1/keepMeUpdated.aspx",
				params:{email:your},
				method:"POST",
				callback:function(options,success,response){
					if(success){
						var responseObj = Ext.decode(response.responseText)
						if(responseObj.success){
							$$("#update-me .form").elements[0].style.display = "none";
							$$("#update-me .thank-you").elements[0].style.display = "block";
							$$("#send-to-friend .errors").elements[0].innerHTML = "";
							setTimeout(Pittsburgh2050.hideSendToFriend,1500);
						}else{
							var message = ""
							for(i = 0; i < responseObj.messages.length; i++){
								message += "<p class=\"alert\">"+responseObj.messages[i]+"</p>";
							}
							errors = $$("#update-me .errors").elements[0]
							errors.style.display = "block";
							errors.innerHTML = message;
						}
					}
				}
			});
			e.stopEvent();
		});
		Ext.get("about-close").on("click",Pittsburgh2050.hideAboutThisSite);
		if(Ext.select("#entry .extra-info p a").elements.length){
			Ext.get(Ext.select("#entry .extra-info p a").elements[0]).on("mouseover",function(e){
				Ext.select("#entry .optional-explanation").elements[0].className = "optional-explanation-on";
			});
			Ext.get(Ext.select("#entry .extra-info p a").elements[0]).on("mouseout",function(e){
				Ext.select("#entry .optional-explanation-on").elements[0].className = "optional-explanation";
			});
		}
		Ext.each(Ext.select(".viewer").elements,function(el){
			el = Ext.get(el)
			el.setDisplayed(true);
			el.setStyle({"visibility":"hidden","height":"1px","overflow":"hidden"});
			
		});
		Ext.get("scroller").setDisplayed(true);
		Ext.get("scroller").setStyle({"display":"block","visibility":"visible","height":"344px"});
		
		Ext.each(Ext.select("#view-switcher li a"),function(el){
			el = Ext.get(el);
			el.on("click",function(e){
				if(e.target.tagName == "A"){
					var t = e.target;
					var h = t.href+"";
					var viewerType = h.substring(h.indexOf("#")+1)
					if(viewerType.length){
						t.style.outline = "none";
						Ext.each(Ext.select(".viewer").elements,function(el){
							el = Ext.get(el)
							el.setDisplayed(true);
							el.setStyle({"visibility":"hidden","height":"1px","overflow":"hidden","margin-top":"0"});
							
						});
						Ext.each(Ext.select("#view-switcher li a"),function(el){
							el = Ext.get(el)
							el.removeClass("selected");
						});
						t.className = "selected";
						
						switch(viewerType){
							case "recent":
								if(!Pittsburgh2050.Recent.isInit){
									Pittsburgh2050.Recent.init();
								}
								break;
							case "location":
								if(!Pittsburgh2050.Mapping.isInit){
									var initMap = function(){
									Pittsburgh2050.Mapping.init();
									}
									setTimeout(initMap,100);
								}
								break;
							case "tags":
								if(!Pittsburgh2050.Tags.isInit){
									Pittsburgh2050.Tags.init();
								}
								break;
							default:
						}
						Ext.get(viewerType).setDisplayed(true);
						Ext.get(viewerType).setStyle({"display":"block","visibility":"visible","height":"344px","margin-top":null});
						//viewerType.style.marginTop = null;
					}
					e.stopEvent();
				}
			});
		});
}
Pittsburgh2050.hideSendToFriend = function(){
		Ext.EventManager.removeListener(window,"keydown",Pittsburgh2050.updateHideTimeOut);
		Ext.get(Ext.select("#send-to-friend .email-drop-down").elements[0]).setStyle("display","none");
		errors = Ext.select("#update-me .errors").elements[0];
		errors.style.display = "none";
		errors.innerHTML = "";
		Ext.select("#send-to-friend .form").elements[0].style.display = "block";
		Ext.select("#send-to-friend .thank-you").elements[0].style.display = "none";
}
Pittsburgh2050.hideUpdateMe = function(){
		Ext.EventManager.removeListener(window,"keydown",Pittsburgh2050.updateHideTimeOut);
		Ext.get(Ext.select("#update-me .email-drop-down").elements[0]).setStyle("display","none");
		errors = Ext.select("#update-me .errors").elements[0]
		errors.style.display = "none";
		errors.innerHTML = "";
		Ext.select("#update-me .form").elements[0].style.display = "block";
		Ext.select("#update-me .thank-you").elements[0].style.display = "none";
}
Pittsburgh2050.hideAboutThisSite = function(){
		Ext.get(Ext.select("#about-this-site .email-drop-down").elements[0]).setStyle("display","none");
}
Pittsburgh2050.updateHideTimeOut = function(){
	if(Pittsburgh2050.Util.emailTimer != null){
		clearTimeout(Pittsburgh2050.Util.emailTimer);
	}
	Pittsburgh2050.Util.emailTimer = setTimeout(function(){
		Ext.EventManager.removeListener(window,"keydown",Pittsburgh2050.updateHideTimeOut);
		Pittsburgh2050.hideSendToFriend();
		Pittsburgh2050.hideUpdateMe();
		Pittsburgh2050.Util.emailTimer = null;
	},10000);
}
Pittsburgh2050.SmallPager = function(el,data, message){
	el.innerHTML = "";
	this.message_ = message
	this.el_ = el;
	this.data_ = data;
	this.currentIndex_ = 0;
	this.init();
}
Pittsburgh2050.SmallPager.prototype = {
	init:function(){
		
		var status = Pittsburgh2050.Util.div.cloneNode(false);
		status.innerHTML = "loading...";
		status.className = "pager-status"
		this.el_.appendChild(status);
		this.status_ = status;
		if(this.data_.length){
			this.buildViewer();
		}else{
			this.failure();
		}
	},
	buildViewer:function(){
		
		this.status_.style.display = "none";
		
		var textbox = Pittsburgh2050.Util.div.cloneNode(false);
		textbox.className = "text-box";
		var namebox = Pittsburgh2050.Util.div.cloneNode(false);
		namebox.className = "name-box";
		var datebox = Pittsburgh2050.Util.div.cloneNode(false);
		datebox.className = "date-box";
		textbox.innerHTML = "No entries for this zip code";
		this.el_.appendChild(namebox);
		this.el_.appendChild(datebox);
		this.el_.appendChild(textbox);
		this.namebox_ = namebox;
		this.datebox_ = datebox;
		this.textbox_ = textbox;
		var controls = Pittsburgh2050.Util.div.cloneNode(false);
		controls.className = "controls";
		if(this.data_.length > 1){
			var previous = Pittsburgh2050.Util.a.cloneNode(false);
			previous.className = "previous-button";
			previous.controler = this;
			Ext.get(previous).on("click",function(e){
				e.target.controler.showPrev();
			});
			previous.innerHTML ="Previous";
			controls.appendChild(previous);
			
			var next = Pittsburgh2050.Util.a.cloneNode(false);
			next.className = "next-button";
			next.controler = this;
			Ext.get(next).on("click",function(e){
				e.target.controler.showNext();
			});
			next.innerHTML ="Next";
			controls.appendChild(next);
			
		}
		
		this.el_.appendChild(controls);
		this.popuplate();
	},
	failure:function(){
		if(this.message_ != null){
			this.status_.innerHTML = this.message_;
		}else{
			this.status_.innerHTML = "Failed to load essays";
		}
	},
	showNext:function(){
		if(this.currentIndex_ + 1 > this.data_.length-1){
			this.currentIndex_ = 0;
		}else{
			this.currentIndex_++
		}
		this.popuplate();
	},
	showPrev:function(){
		if(this.currentIndex_ - 1 < 0){
			this.currentIndex_ = this.data_.length-1;
		}else{
			this.currentIndex_--
		}
		this.popuplate();
	},
	popuplate:function(){
		for(i in this.data_){
		//alert(i+" "+this.data_[i]);
		}
		var ci = this.currentIndex_
		this.textbox_.innerHTML = this.data_[ci].essay;
		this.datebox_.innerHTML = "Submitted "+ new Date(this.data_[ci].submissionDate).format('F j, Y');
		this.namebox_.innerHTML = "<span>"+(this.data_[ci].name != ""?this.data_[ci].name:"Someone")+"</span> from "+this.data_[ci].zip;
	}
}

Pittsburgh2050.Recent = function(){
}

Pittsburgh2050.Recent = {};


Pittsburgh2050.Recent.init = function(){
	Pittsburgh2050.Recent.isInit = true;
	Pittsburgh2050.Recent.viewer = Ext.get("recent-viewer").dom;
	Ext.each(Ext.select("#recent-dates td a").elements,function(el){
		Ext.get(el).on("click",function(e){
			e.stopEvent();
		});
	});
	Ext.each(Ext.select("#recent-dates td a.active").elements,function(el){
		Ext.get(el).on("click",function(e){
			Ext.each(Ext.select("#recent-dates td").elements,function(el){
				Ext.get(el).removeClass("selected");
			});
			Ext.each(Ext.select("#recent-dates th").elements,function(el){
				Ext.get(el).removeClass("selected");
			});
			var t = e.target;
			Ext.get(t).up("td").addClass("selected");
			Ext.select("th",true,Ext.get(t).up("tr").dom).elements[0].addClass("selected");
			var conn = Pittsburgh2050.Util.connection;
			var h = t.href+"";
			var params = h.substring(h.indexOf("#")+1)
			conn.request({url:"/service/v1/entriesByMonth.aspx",params:params,method:"GET",callback:Pittsburgh2050.Recent.load,me:this});
			e.stopEvent();
		});
	});
	var conn = Pittsburgh2050.Util.connection;
	d = new Date();
	conn.request({url:"/service/v1/entriesByMonth.aspx",params:"month="+(d.getMonth()+1)+"&year="+(d.getFullYear()),method:"GET",callback:Pittsburgh2050.Recent.load,me:this});
}
Pittsburgh2050.Recent.load = function(options,success,response){			
	Pittsburgh2050.Recent.viewer.innerHTML = "";
	me = options.me
	var data = null;
	var message = null;
	if(success){
		var baseObj = Ext.decode(response.responseText);
		data = baseObj.entries;
		message = baseObj.message;
	}
	new Pittsburgh2050.SmallPager(Pittsburgh2050.Recent.viewer, data, message);
}

Pittsburgh2050.Tags = function(){
}

Pittsburgh2050.Tags = {};

Pittsburgh2050.Tags.init = function(){
	Pittsburgh2050.Tags.isInit = true;
	var single = Ext.get(Ext.select("#tags .single").elements[0]);
	var two = Ext.get(Ext.select("#tags .two").elements[0]);
	var singleWordCollection = Ext.get("single-word-tags").dom.getElementsByTagName("a");
	var i = 0;
	var len = singleWordCollection.length;
	for(;i<len; i++){
		if(i%2 != 0){
			Ext.get(singleWordCollection[i]).addClass("alt");
		}
	}
	var twoWordCollection = Ext.get("two-word-tags").dom.getElementsByTagName("a");
	i = 0;
	len = twoWordCollection.length;
	for(;i<len; i++){
		if(i%2 != 0){
			Ext.get(twoWordCollection[i]).addClass("alt");
		}
	}
	single.on("click",function(e){
		
		if(!this.hasClass("selected")){
			Ext.get("two-word-tags").setStyle("display","none");
			Ext.get("single-word-tags").setStyle("display","block");
			this.addClass("selected");
			two.removeClass("selected");
		}
		e.stopEvent();
	});
	two.on("click",function(e){
		if(!this.hasClass("selected")){
			Ext.get("single-word-tags").setStyle("display","none");
			Ext.get("two-word-tags").setStyle("display","block");
			this.addClass("selected");
			single.removeClass("selected");
		}
		e.stopEvent();
	});
}

Pittsburgh2050.Mapping = function(){
}

Pittsburgh2050.Mapping = {};

Pittsburgh2050.Mapping.init = function(){
	//console.log("init map");
	Pittsburgh2050.Mapping.isInit = true;
	//get the map
	var map = new GMap2(Ext.get("map").dom);
	Pittsburgh2050.Mapping.MapControles = new GSmallMapControl()
	map.addControl(Pittsburgh2050.Mapping.MapControles);
	
	//add the custome map type
	var copyCollection = new GCopyrightCollection('');
	var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90, -180), new GLatLng(90, 180)), 0, "&copy; Elliance Inc.<span id=\"copy-target\"></span>");
	copyCollection.addCopyright(copyright);

	var tilelayers = [new GTileLayer(copyCollection, 10, 13)];
	tilelayers[0].getTileUrl = CustomGetTileUrl;

	function CustomGetTileUrl(a,b) {
		var z = b;
		var f = "/_images/mapping/Zoom"+z+"Maps/"+a.x+"_"+a.y+"_"+z+".gif";
		return f;
	}

	//var custommap = new GMapType(tilelayers, new GMercatorProjection(14), "Chart", {errorMessage:""});
	//map.addMapType(custommap);

	//geocoder
	var geocoder = new GClientGeocoder();
	
	geocoder.getLatLng("15222",function(p){
		map.setCenter(p, 12);
	});
	//utility
	/*
	GEvent.addListener(map, "click", function(overlay,  point) {
		if(point){
		console.log(point)
		}
	});
	*/
	GEvent.clearListeners(map, "dblclick")/*, function(overlay,  point) {
		console.log(overlay);
		if(point){
		console.log(point)
		}
	});*/
	
	//do stuff when it all loads
	GEvent.addListener(map, "load", function() {
			//make the copy text white;
			/*var ct = Ext.get("copy-target")
			ct.up("div").applyStyles({color:"#fff"});
			ct.up("div").down("a").applyStyles({color:"#fff"});*/
			//apply gradient
			var b = new Pittsburgh2050.Mapping.Blackout()
			map.addOverlay(b);
			Ext.get(b.overlay_).on("mouseover", Pittsburgh2050.Mapping.NumberedMarker.hideDetails);
			//show loading indicator
			var loading = new Pittsburgh2050.Mapping.Loading()
			map.addOverlay(loading);
			//load up markers
			var conn = Pittsburgh2050.Util.connection
			conn.request(
				{
				url:"/service/v1/entriesCount.aspx",
				callback:function(options,success,response){
					if(success){
						var zipcodes = Ext.decode(response.responseText).zipcodes
						
						var placeId = 0
						var placeAMarker = function(){
							var zip = zipcodes[placeId];
							var zipStr = zip.zip + "";
							geocoder.getLatLng(zipStr,function(p){
								if(p != null){
									var pin = new Pittsburgh2050.Mapping.NumberedMarker(p,zip);
									map.addOverlay(pin);
								}
							});
							if(placeId+1 < zipcodes.length){
								placeId++;
								setTimeout(placeAMarker,150);		
							}else{
								map.removeOverlay(loading);
							}
						};
						setTimeout(placeAMarker,150);
				}
			}});			
	});
	
}

//Numbered Marker
Pittsburgh2050.Mapping.NumberedMarker = function(GLatLng,data){
	this.glatlng_ = GLatLng;
	this.pointOffset_ = new GPoint(15,37);
	this.pointOffsetOn_ = new GPoint(18,52);
	this.data_ = data;
}
Pittsburgh2050.Mapping.NumberedMarker.prototype = new GOverlay();
Pittsburgh2050.Mapping.NumberedMarker.prototype.initialize = function(map) {
	var img = Pittsburgh2050.Util.div.cloneNode(false);
	img.style.position = "absolute";
	img.style.display = "block";
	//img.style.paddingTop = "5px";
	
	var pin = img.cloneNode(false);
	var shaddow = img.cloneNode(false);
	
	var zIndex = GOverlay.getZIndex(this.glatlng_.lat());
	
	pin.className = "pin";
	//pin.innerHTML = this.data_.count;
	pin.style.zIndex = zIndex;
	pin.marker = this;
	pin.innerHTML = "<span>Hear "+this.data_.count+ (this.data_.count > 1?" people":" person")+"<br /><span>from "+this.data_.zip+"</span></span>";
	shaddow.className = "pin-shadow";
	shaddow.style.zIndex = zIndex;
	shaddow.marker = this;
	
	
	map.getPane(G_MAP_MARKER_SHADOW_PANE).appendChild(shaddow);
	map.getPane(G_MAP_MARKER_PANE).appendChild(pin);
	
	Ext.get(pin).on("click", function(e) {
		var t = e.target;
		var f = false;
		if(t.marker){
			f = true;
		}
		while(!t.marker && t != document.body && !f){
			if(t.parentNode){
				t = t.parentNode
				if(t.marker){
					f = true;
					break;
				}
			}
		}
		if(f){
		
			Ext.each(Ext.select(".pin-on").elements,function(el){
				if(el.marker){
					el.marker.clicked = null;
				}
			});
			Pittsburgh2050.Mapping.NumberedMarker.resetDetails();
			if(Pittsburgh2050.Mapping.NumberedMarker.activeMarker){
				Pittsburgh2050.Mapping.NumberedMarker.activeMarker.clicked = true;
			}
			var popup = new Pittsburgh2050.Mapping.PopUp(t.marker);
			map.addOverlay(popup);
		}
	});
	Ext.get(pin).on("mouseover",Pittsburgh2050.Mapping.NumberedMarker.showDetails);
	
	this.map_ = map;
	this.pin_ = pin;
	this.shaddow_ = shaddow;
}
Pittsburgh2050.Mapping.NumberedMarker.prototype.remove = function() {
	this.pin_.marker = null;
	this.shaddow_.marker = null;
	this.pin_.parentNode.removeChild(this.pin_);
	this.shaddow_.parentNode.removeChild(this.shaddow_);
}
Pittsburgh2050.Mapping.NumberedMarker.prototype.copy = function() {
  return new Pittsburgh2050.Mapping.NumberedMarker(this.glatlng_,this.data_);
}
Pittsburgh2050.Mapping.NumberedMarker.prototype.redraw = function(force) {
	c1 = this.map_.fromLatLngToDivPixel(this.glatlng_);
	this.pin_.style.top =  (c1.y-this.pointOffset_.y)+"px";
	this.shaddow_.style.top =  (c1.y-this.pointOffset_.y)+"px";
	this.pin_.style.left =  (c1.x-this.pointOffset_.x)+"px";
	this.shaddow_.style.left =  (c1.x-this.pointOffset_.x)+"px";
}
//static proporties
Pittsburgh2050.Mapping.NumberedMarker.activeMarker = null;
//static methods
Pittsburgh2050.Mapping.NumberedMarker.showDetails = function(e) {
	if(e.target.marker){
		Pittsburgh2050.Mapping.NumberedMarker.hideDetails();
		var me = e.target.marker;
		Pittsburgh2050.Mapping.NumberedMarker.activeMarker = me;
		var c1 = me.map_.fromLatLngToDivPixel(me.glatlng_);
		me.pin_.className = "pin-on";
		me.pin_.style.zIndex = "0";
		me.shaddow_.className = "pin-shadow-on";
		me.pin_.style.top =  (c1.y-me.pointOffsetOn_.y)+"px";
		me.shaddow_.style.top =  (c1.y-me.pointOffsetOn_.y)+"px";
		me.pin_.style.left =  (c1.x-me.pointOffsetOn_.x)+"px";
		me.shaddow_.style.left =  (c1.x-me.pointOffsetOn_.x)+"px";
	}
};
Pittsburgh2050.Mapping.NumberedMarker.hideDetails = function(e) {
	var me = Pittsburgh2050.Mapping.NumberedMarker.activeMarker;
	if(me != null && !me.clicked){
		var c1 = me.map_.fromLatLngToDivPixel(me.glatlng_);
		me.pin_.className = "pin";
		me.pin_.style.zIndex = GOverlay.getZIndex(me.glatlng_.lat());;
		me.shaddow_.className = "pin-shadow";
		me.pin_.style.top =  (c1.y-me.pointOffset_.y)+"px";
		me.shaddow_.style.top =  (c1.y-me.pointOffset_.y)+"px";
		me.pin_.style.left =  (c1.x-me.pointOffset_.x)+"px";
		me.shaddow_.style.left =  (c1.x-me.pointOffset_.x)+"px";
		Pittsburgh2050.Mapping.NumberedMarker.activeMarker = null;
	}
};
Pittsburgh2050.Mapping.NumberedMarker.resetDetails = function(e) {
	Ext.each(Ext.select(".pin-on").elements,function(el){
		if(el.marker && el.marker != Pittsburgh2050.Mapping.NumberedMarker.activeMarker){
			var me = el.marker;
			var c1 = me.map_.fromLatLngToDivPixel(me.glatlng_);
			me.pin_.className = "pin";
			me.pin_.style.zIndex = GOverlay.getZIndex(me.glatlng_.lat());;
			me.shaddow_.className = "pin-shadow";
			me.pin_.style.top =  (c1.y-me.pointOffset_.y)+"px";
			me.shaddow_.style.top =  (c1.y-me.pointOffset_.y)+"px";
			me.pin_.style.left =  (c1.x-me.pointOffset_.x)+"px";
			me.shaddow_.style.left =  (c1.x-me.pointOffset_.x)+"px";
		}
	});
};

//Popup
Pittsburgh2050.Mapping.PopUp = function(marker){
	this.marker_ = marker;
	this.panned_ = false;
	this.size_ = new GSize(474,242);
	this.offset_ = new GPoint(76,306)
	this.padding_ = 9;
}
Pittsburgh2050.Mapping.PopUp.prototype = new GOverlay();
Pittsburgh2050.Mapping.PopUp.prototype.initialize = function(map) {
  // Create the DIV representing our rectangle
	if(Pittsburgh2050.Util.mapPopup !== null){
		Pittsburgh2050.Util.mapPopup.remove();
	}
	Pittsburgh2050.Util.mapPopup = this;
	div = Pittsburgh2050.Util.div.cloneNode(false);
	div.className = "map-popup"
	div.style.position = "absolute";
	div.style.width = this.size_.width+"px";
	div.style.height = this.size_.height+"px";
	Ext.get(div).on("mouseover",function(){Pittsburgh2050.Mapping.NumberedMarker.hideDetails()});
	
	closeButton = Pittsburgh2050.Util.a.cloneNode(false);
	closeButton.className = "close-button"	
	div.appendChild(closeButton);
	
	Ext.get(closeButton).on("click",function(){
		if(Pittsburgh2050.Mapping.NumberedMarker.activeMarker){
			Pittsburgh2050.Mapping.NumberedMarker.activeMarker.clicked = null;
		}
		this.map_.addControl(Pittsburgh2050.Mapping.MapControles);
		this.map_.enableDragging();
		Pittsburgh2050.Util.mapPopup.remove();
		
	},this);
	
	var pagger = Pittsburgh2050.Util.div.cloneNode(false);
	pagger.id = "location-viewer";
	div.appendChild(pagger);
   	var conn = Pittsburgh2050.Util.connection;
	var callbackFn = function(options,success,response){			
		me = options.me
		var data = null;
		var message = null
		if(success){
			var baseObj = Ext.decode(response.responseText);
			data = baseObj.entries;
			message = baseObj.message;
		}
		new Pittsburgh2050.SmallPager(Ext.get("location-viewer").dom,data,message);
	}
	me = this
	//console.log(this.marker_.data_.zip)
	conn.request({url:"/service/v1/entriesByZip.aspx",params:"zip="+me.marker_.data_.zip,method:"GET",callback:callbackFn,me:this});
	
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	map.removeControl(Pittsburgh2050.Mapping.MapControles);
	map.disableDragging();
	this.map_ = map;
	this.overlay_ = div;
	this.overlay_.style.top = (this.marker_.pin_.offsetTop-this.overlay_.offsetHeight-10)+"px";
	this.overlay_.style.left = this.marker_.pin_.offsetLeft+"px";
}
Pittsburgh2050.Mapping.PopUp.prototype.remove = function() {
	
  this.overlay_.parentNode.removeChild(this.overlay_);
  this.map_.panTo(this.marker_.glatlng_);
  Pittsburgh2050.Util.mapPopup = null;
}
Pittsburgh2050.Mapping.PopUp.prototype.copy = function() {
  return new Pittsburgh2050.Mapping.Blackout();
}
Pittsburgh2050.Mapping.PopUp.prototype.redraw = function(force) {
	if(force){
		if(!this.panned_){
			size = this.map_.getSize();
			var pointCenter = this.map_.fromLatLngToDivPixel(this.marker_.glatlng_);
			
			this.map_.panTo(this.map_.fromDivPixelToLatLng(new GPoint(pointCenter.x,(pointCenter.y +100))));
			this.panned_ = true;
			this.overlay_.style.top = (pointCenter.y +7)+"px";
			this.overlay_.style.left = (pointCenter.x - (size.width/2) + this.padding_)+"px";
			var me = this;
			Pittsburgh2050.Util.mapMoveEvent = GEvent.addListener(this.map_, "moveend", function() {
				Pittsburgh2050.Mapping.NumberedMarker.showDetails({target:{marker:me.marker_}});	
				GEvent.removeListener(Pittsburgh2050.Util.mapMoveEvent);
				Pittsburgh2050.Util.mapMoveEvent = null;
			});
			
		}
	}
	
}

//Blackout
Pittsburgh2050.Mapping.Blackout = function(){}
Pittsburgh2050.Mapping.Blackout.prototype = new GOverlay();

Pittsburgh2050.Mapping.Blackout.prototype.initialize = function(map) {
  // Create the DIV representing our rectangle
  var div = document.createElement("div");
	div.className = "blackout"
	
	size = map.getSize();
	div.style.width = (size.width)+"px";
	div.style.height = (size.height)+"px";
	
   // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
  // below the marker shadows)
	map.getPane(G_MAP_MAP_PANE).appendChild(div);
	this.map_ = map;
	this.overlay_ = div;
}
Pittsburgh2050.Mapping.Blackout.prototype.remove = function() {
  this.overlay_.parentNode.removeChild(this.overlay_);
}
Pittsburgh2050.Mapping.Blackout.prototype.copy = function() {
  return new Pittsburgh2050.Mapping.Blackout();
}

// Redraw the rectangle based on the current projection and zoom level
Pittsburgh2050.Mapping.Blackout.prototype.redraw = function(force) {
 	var b = this.map_.getBounds();
	var lat = b.getNorthEast().lat();
	var lng = b.getSouthWest().lng();
	var c1 = this.map_.fromLatLngToDivPixel(new GLatLng(lat,lng));
	this.overlay_.style.left = (c1.x)+"px";
	this.overlay_.style.top = (c1.y)+"px";
}

//Loading
Pittsburgh2050.Mapping.Loading = function(){}
Pittsburgh2050.Mapping.Loading.prototype = new GOverlay();

Pittsburgh2050.Mapping.Loading.prototype.initialize = function(map) {
  // Create the DIV representing our rectangle
  var div = document.createElement("div");
	div.className = "loading"
	div.innerHTML = "Loading";
	
	
   // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
  // below the marker shadows)
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	this.map_ = map;
	this.overlay_ = div;
}
Pittsburgh2050.Mapping.Loading.prototype.remove = function() {
  this.overlay_.parentNode.removeChild(this.overlay_);
}
Pittsburgh2050.Mapping.Loading.prototype.copy = function() {
  return new Pittsburgh2050.Mapping.Loading();
}

// Redraw the rectangle based on the current projection and zoom level
Pittsburgh2050.Mapping.Loading.prototype.redraw = function(force) {
 	var c = this.map_.getCenter();
	//console.log(c);
	var c1 = this.map_.fromLatLngToDivPixel(c);
	//console.log(c1);
	var size = this.map_.getSize();	
	this.overlay_.style.left = (c1.x-50)+"px";
	this.overlay_.style.top = (c1.y-15)+"px";
}