/* City Names Util */
Manager.addMethods({
	'CityNameUtil': new Module('CityNameUtil', 'this module handles global JS odds-and-ends for best colleges.')
});

NameSearchLoaded = false;
refCount = 0;
USN.load('citynames');
USN.load('scriptaculous', {'type': 'external'});
USN.CityNameUtil.NameSearch = {
	itemURL: "",
	
	initialize: function() {
		if (!NameSearchLoaded) {
			refCount++;
			NameSearchLoaded = true;
			this.searchField = $$('div#school-search #cityname')[0];
			if (!this.searchField) {
				return;
			}
			this.searchObj =  $H(USNCityData);
			
			this.dropDown = new Element("div", {"class": "autocomplete", "id": "schoool-name-matches", "style": "display: none; background: #fff; text-align: left; padding: 5px; border:1px solid #666666; width: 600px "})
			this.searchField.insert({"after": this.dropDown})
			new Autocompleter.Local(this.searchField, this.dropDown, this.searchObj.keys(), {"choices": 10, "fullSearch": true, "partialChars": 4, "afterUpdateElement": this.endSearch.bind(this)});
			this.flashPromoContainer = $$(".right .promo .text-only").find(function(promo) { return promo.getElementsByTagName("object").length > 0});
			this.searchField.observe("keypress", this.startSearch.bindAsEventListener(this));
		}
	},
	startSearch: function(event) {
		if (this.flashPromoContainer){
		this.flashPromoContainer.hide();
		}
	
	},
	endSearch: function(event) {
		
	}
	
}

Event.observe(window, 'load', USN.CityNameUtil.NameSearch.initialize.bind(USN.CityNameUtil.NameSearch));













