	if (!Array.prototype.indexOf) {
	  Array.prototype.indexOf = function(elt /*, from*/) {
		var len = this.length >>> 0;

		var from = Number(arguments[1]) || 0;
		from = (from < 0)
			 ? Math.ceil(from)
			 : Math.floor(from);
		if (from < 0)
		  from += len;

		for (; from < len; from++) {
		  if (from in this &&
			  this[from] === elt)
			return from;
		}
		return -1;
	  };
	}

	var counties = ['Cook', 'Lake', 'McHenry', 'Kane', 'DuPage', 'Will'];
	var cities = [
				  ['Arlington Heights,Arlington_Heights', 'Barrington,Barrington', 'Buffalo Grove,Buffalo_Grove', 'Burr Ridge,Willowbrook', 'Des Plaines,Des_Plaines', 'Elk Grove Village,Elk_Grove_Village', 'Evanston,Evanston', 'Forest Park,Forest_Park',
					'Glencoe,Glencoe', 'Glenview,Glenview', 'Hinsdale,Hinsdale', 'Hoffman Estates,Hoffman_Estates', 'Kenilworth,Wilmette_-_Kenilworth', 'LaGrange,La_Grange_&_La_Grange_Park',
					'LaGrange Park,La_Grange_&_La_Grange_Park', 'Lemont,Lemont', 'Morton Grove,Morton_Grove', 'Mt. Prospect,Mt._Prospect', 'Niles,Niles', 'Northbrook,Northbrook', 'Northfield,Winnetka_-_Northfield',
					'Oak Park,Oak_Park_&_River_Forest', 'Orland Hills,Orland_Hills', 'Orland Park,Orland_Park', 'Palatine,Palatine', 'Palos Heights,Palos_Heights',
					'Palos Hills,Palos_Hills', 'Palos Park,Palos_Park', 'Park Ridge,Park_Ridge', 'Prospect Heights,Prospect_Heights', 'River Forest,Oak_Park_&_River_Forest',
					'Rolling Meadows,Rolling_Meadows', 'Schaumburg,Schaumburg', 'Skokie,Skokie', 'Streamwood,Streamwood', 'Tinley Park,Tinley_Park', 'Western Springs,Western_Springs',
					'Wheeling,Wheeling', 'Wilmette,Wilmette_-_Kenilworth', 'Winnetka,Winnetka_-_Northfield', 'Woodridge,Woodridge'],
				  ['Antioch,Antioch_-_Fox_Lake', 'Buffalo Grove,Buffalo_Grove', 'Deerfield,Deerfield', 'Fox Lake,Antioch_-_Fox_Lake', 'Fox River Grove,Cary_-_Fox_River_Grove', 'Grayslake,Grayslake', 'Gurnee,Gurnee', 'Highland Park,Highland_Park_-_Highwood',
					'Highwood,Highland_Park_-_Highwood', 'Lake Bluff,Lake_Bluff', 'Lake Forest,Lake_Forest', 'Lindenhurst/Lake Villa,Lake_Villa', 'Lake Zurich,Lake_Zurich', 'Libertyville,Libertyville', 'Lincolnshire,Lincolnshire', 'Mundelein,Mundelein',
					'Round Lake,Round_Lake', 'Vernon Hills,Vernon_Hills'],
				  ['Algonquin,Algonquin', 'Cary,Cary_-_Fox_River_Grove', 'Crystal Lake,Crystal_Lake', 'Huntley,Huntley', 'Lake in the Hills,Lake_in_the_Hills', 'McHenry,McHenry', 'Woodstock,Woodstock'],
				  ['Aurora,Aurora', 'Batavia,Batavia', 'Elburn,Elburn_&_Maple_Park', 'Elgin,Elgin', 'Geneva,Geneva', 'Hoffman Estates,Hoffman_Estates', 'Maple Park,Elburn_&_Maple_Park',
					'St. Charles,St._Charles'],
				  ['Bolingbrook,Bolingbrook', 'Burr Ridge,Willowbrook', 'Clarendon Hills,Clarendon_Hills', 'Darien,Darien', 'Downers Grove,Downers_Grove', 'Elmhurst,Elmhurst',
					'Glen Ellyn,Glen_Ellyn', 'Hinsdale,Hinsdale', 'Lemont,Lemont', 'Lisle,Lisle', 'Lombard,Lombard', 'Naperville,Naperville', 'Oak Brook,Oak_Brook',
					'Villa Park,Villa_Park', 'Warrenville,Warrenville', 'West Chicago,West_Chicago',
					'Westmont,Westmont', 'Wheaton,Wheaton', 'Willowbrook,Willowbrook', 'Winfield,Winfield', 'Woodridge,Woodridge'],
				  ['Bolingbrook,Bolingbrook', 'Frankfort,Frankfort', 'Homer Glen,Homer_Glen', 'Joliet,Joliet', 'Lemont,Lemont', 'Manhattan,Manhattan', 'Mokena,Mokena',
					'New Lenox,New_Lenox', 'Plainfield,Plainfield', 'Romeoville,Romeoville']
				  ];

	var letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
				   'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ];
	var citiesl = [
					['Algonquin,Algonquin', 'Antioch,Antioch_-_Fox_Lake', 'Arlington Heights,Arlington_Heights', 'Aurora,Aurora'],
					['Barrington,Barrington', 'Batavia,Batavia', 'Bolingbrook,Bolingbrook', 'Buffalo Grove,Buffalo_Grove', 'Burr Ridge,Willowbrook'],
					['Cary,Cary_-_Fox_River_Grove', 'Clarendon Hills,Clarendon_Hills', 'Crystal Lake,Crystal_Lake'],
					['Darien,Darien', 'Deerfield,Deerfield', 'Des Plaines,Des_Plaines', 'Downers Grove,Downers_Grove'],
					['Elburn,Elburn_&_Maple_Park', 'Elgin,Elgin', 'Elk Grove Village,Elk_Grove_Village', 'Elmhurst,Elmhurst', 'Evanston,Evanston'],
					['Forest Park,Forest_Park', 'Fox Lake,Antioch_-_Fox_Lake', 'Fox River Grove,Cary_-_Fox_River_Grove', 'Frankfort,Frankfort'],
					['Geneva,Geneva', 'Glencoe,Glencoe', 'Glen Ellyn,Glen_Ellyn', 'Glenview,Glenview', 'Grayslake,Grayslake', 'Gurnee,Gurnee'],
					['Highland Park,Highland_Park_-_Highwood', 'Highwood,Highland_Park_-_Highwood', 'Hinsdale,Hinsdale', 'Hoffman Estates,Hoffman_Estates', 'Homer Glen,Homer_Glen', 'Huntley,Huntley'],
					[],
					['Joliet,Joliet'],
					['Kenilworth,Wilmette_-_Kenilworth'],
					['LaGrange,La_Grange_&_La_Grange_Park', 'LaGrange Park,La_Grange_&_La_Grange_Park', 'Lake Bluff,Lake_Bluff', 'Lake Forest,Lake_Forest',
						'Lake in the Hills,Lake_in_the_Hills', 'Lindenhurst/Lake Villa,Lake_Villa', 'Lake Zurich,Lake_Zurich', 'Lemont,Lemont', 'Libertyville,Libertyville', 'Lincolnshire,Lincolnshire',
						'Lisle,Lisle', 'Lombard,Lombard'],
					['Manhattan,Manhattan', 'Maple Park,Elburn_&_Maple_Park', 'McHenry,McHenry', 'Mokena,Mokena', 'Morton Grove,Morton_Grove',
						'Mt. Prospect,Mt._Prospect', 'Mundelein,Mundelein'],
					['Naperville,Naperville', 'New Lenox,New_Lenox', 'Niles,Niles', 'Northbrook,Northbrook', 'Northfield,Winnetka_-_Northfield'],
					['Oak Brook,Oak_Brook', 'Oak Park,Oak_Park_&_River_Forest', 'Orland Hills,Orland_Hills', 'Orland Park,Orland_Park'],
					['Palatine,Palatine', 'Palos Heights,Palos_Heights', 'Palos Hills,Palos_Hills', 'Palos Park,Palos_Park', 'Park Ridge,Park_Ridge',
						'Plainfield,Plainfield', 'Prospect Heights,Prospect_Heights'],
					[],
					['River Forest,Oak_Park_&_River_Forest', 'Rolling Meadows,Rolling_Meadows', 'Romeoville,Romeoville', 'Round Lake,Round_Lake'],
					['Schaumburg,Schaumburg', 'Skokie,Skokie', 'St. Charles,St._Charles', 'Streamwood,Streamwood'],
					['Tinley Park,Tinley_Park'],
					[],
					['Vernon Hills,Vernon_Hills', 'Villa Park,Villa_Park'],
					['Warrenville,Warrenville', 'West Chicago,West_Chicago',
						'Western Springs,Western_Springs', 'Westmont,Westmont', 'Wheaton,Wheaton', 'Wheeling,Wheeling', 'Willowbrook,Willowbrook',
						'Wilmette,Wilmette_-_Kenilworth', 'Winfield,Winfield', 'Winnetka,Winnetka_-_Northfield', 'Woodridge,Woodridge',
						'Woodstock,Woodstock'],
					[], [], []
				];
	var stick = 0;
	var townstick = 0;

	function makeTownListMap(num, county) {
		var citytmp = cities[num];
		if (stick == 1) return true;
		div = document.getElementById('map-flyout');
		div.innerHTML = '<div><span style="float: right;"><span id="close" style="cursor: pointer;" onclick="sticky();">[x]</span></span><span class="black_large" style="font-weight: bold;">' + county + ' County</span></div>';
		citylist = document.createElement('ul');
		for (i = 0; i < citytmp.length; i++) {
			tmp = citytmp[i].split(',');
			citylistitem = document.createElement('li');
			if (tmp.length == 1)
				citylistitem.innerHTML = '<b class="black_normal">' + tmp[0] + ' (Coming soon)</b></a>';
			else
				citylistitem.innerHTML = '<a href="/' + tmp[1] + '/"><b class="red_normal">' + tmp[0] + '</b></a>';
			citylist.appendChild(citylistitem);
		}
		div.appendChild(citylist);
		div.style.display = '';
		div.style.border = '3px solid black';
//		document.getElementById('map-container').style.display = '';
	}

	function makeTownListLetter(num, letter) {
		var citytmp = citiesl[num];
		if (stick == 1) return true;
		div = document.getElementById('letter-flyout');
		div.innerHTML = '<div><span style="float: right;"><span id="close" style="cursor: pointer;" onclick="sticky();">[x]</span></span><span class="red_large" style="font-weight: bold;">' + letter + '</span></div>';
		citylist = document.createElement('ul');
		for (i = 0; i < citytmp.length; i++) {
			tmp = citytmp[i].split(',');
			citylistitem = document.createElement('li');
			if (tmp.length == 1)
				citylistitem.innerHTML = '<b class="black_normal">' + tmp[0] + ' (Coming soon)</b></a>';
			else
				citylistitem.innerHTML = '<a href="/' + tmp[1] + '/"><b class="red_normal">' + tmp[0] + '</b></a>';
			citylist.appendChild(citylistitem);
		}
		div.appendChild(citylist);
		div.style.display = '';
	}

	function destroyTownList(type) {
		if (stick == 1) return true;
		div = document.getElementById(type + '-flyout');
		while (div.hasChildNodes()) div.removeChild(div.lastChild);
		div.style.display = 'none';
	}

	function swapInMap(county) {
		document.getElementById('map').src = "/images/pick_town_" + county.toLowerCase() + "_on.gif";
		var i = counties.indexOf(county);
		makeTownListMap(i, county);
	}

	function swapOutMap() {
		document.getElementById('map').src = "/images/pick_town_none_on.gif";
		destroyTownList('letter');
		destroyTownList('map');
	}

	function swapInLetter(letter) {
		var i = letters.indexOf(letter);
		document.getElementById(letter).style.color = '#fff';
		document.getElementById(letter).style.background = '#98012e';
		makeTownListLetter(i, letter);
	}

	function swapOutLetter(letter) {
		destroyTownList('map');
		document.getElementById(letter).style.color = '#98012e';
		document.getElementById(letter).style.background = '#fff';
		destroyTownList('letter');
	}

	function sticky(type, county) {
		if (stick == 0) {
			if (type == 'map') {
				if (document.getElementById('map-flyout').style.display == 'none')
					swapInMap(county);
			} else if (type == 'letter') {
				if (document.getElementById('letter-flyout').style.display == 'none')
					swapInLetter(county);
			} else {
			}
			stick = 1;
			return true;
		}
		if (stick == 1) {
			stick = 0;
			destroyTownList('map');
			destroyTownList('letter');
			return true;
		}
	}

	function isChildOf(parent, child) {
		if( child != null ) {
			while( child.parentNode ) {
				if( (child = child.parentNode) == parent ) {
					return true;
				}
			}
		}
		return false;
	}

	function fixOnMouseOut(element, event) {
		var current_mouse_target = null;
		if( event.toElement ) {
			current_mouse_target = event.toElement;
		} else if( event.relatedTarget ) {
			current_mouse_target = event.relatedTarget;
		}
		if( !isChildOf(element, current_mouse_target) && element != current_mouse_target ) {
			sticky();
		}
	}

	function switchTownClick() {
		if (townstick == 1) {
			//document.getElementById('tabbed_module').style.display = 'none';
			document.getElementById('nav-container').style.display = 'none';
			townstick = 0;
			return true;
		}
		if (townstick == 0) {
			document.getElementById('nav-container').style.display = '';
			//document.getElementById('tabbed_module').style.display = '';
			townstick = 1;
			return true;
		}
	}
