var cnnInstantSearching = false;
var cnnStates = {'AL':'Alabama','AK':'Alaska','AZ':'Arizona','AR':'Arkansas','CA':'California','CO':'Colorado','CT':'Connecticut','DE':'Delaware','DC':'District of Columbia','FL':'Florida','GA':'Georgia','HI':'Hawaii','ID':'Idaho','IL':'Illinois','IN':'Indiana','IA':'Iowa','KS':'Kansas','KY':'Kentucky','LA':'Louisiana','ME':'Maine','MD':'Maryland','MA':'Massachusetts','MI':'Michigan','MN':'Minnesota','MS':'Mississippi','MO':'Missouri','MT':'Montana','NE':'Nebraska','NV':'Nevada','NH':'New Hampshire','NJ':'New Jersey','NM':'New Mexico','NY':'New York','NC':'North Carolina','ND':'North Dakota','OH':'Ohio','OK':'Oklahoma','OR':'Oregon','PA':'Pennsylvania','RI':'Rhode Island','SC':'South Carolina','SD':'South Dakota','TN':'Tennessee','TX':'Texas','UT':'Utah','VT':'Vermont','VA':'Virginia','WA':'Washington','WV':'West Virginia','WI':'Wisconsin','WY':'Wyoming'}
var cnnLastSearchResponse = null;
var cnnOpenOptionId = null;
var cnnBPLOptions = {
	'option_region'		: { in_use: 0 },
	'option_ranking'	: { in_use: 0 },
	'option_population'	: { in_use: 0 },
	'option_homeprices'	: { in_use: 0 },
	'option_schools'	: { in_use: 0 },
	'option_jobs'		: { in_use: 0 },
	'option_weather'	: { in_use: 0 },
	'option_crime'		: { in_use: 0 },
	'option_activities'	: { in_use: 0 },
	'option_neighbors'	: { in_use: 0 }
};

var sliderPopulation		= null,
	population_slider		= null,
	sliderHomePrices		= null,
	homeprices_slider		= null,
	sliderJobs				= null,
	jobs_slider				= null,
	sliderNeighborsMarried	= null,
	neighbors_married_slider= null,
	sliderNeighborsAge		= null,
	neighbors_age_slider	= null,
	sliderWeatherDry		= null,
	weather_dry_slider		= null,
	sliderWeatherSnow		= null,
	weather_snow_slider		= null,
	sliderWeatherWinter		= null,
	weather_winter_slider	= null,
	sliderWeatherSummer		= null,
	weather_summer_slider	= null,
	sliderWeatherJuly		= null,
	weather_july_slider		= null,
	sliderWeatherCloudy		= null,
	weather_cloudy_slider	= null;


var cnnSliderValues = {
	population:[8500, 25000, 30000, 40000, 50000, 75000, 100000, 500000, 1000000, 8274527],
	homeprices:[49000, 100000, 175000, 250000, 400000, 750000, 1000000, 1200000, 1400000, 1695000]
};

function init_all_sliders()
{
	population_slider			= $('population_slider');
	homeprices_slider			= $('homeprices_slider');
	jobs_slider					= $('jobs_slider');
	crime_slider				= $('crime_slider');
	neighbors_married_slider	= $('neighbors_married_slider');
	neighbors_age_slider		= $('neighbors_age_slider');
	weather_dry_slider			= $('weather_dry_slider');
	weather_snow_slider			= $('weather_snow_slider');
	weather_winter_slider		= $('weather_winter_slider');
	weather_summer_slider		= $('weather_summer_slider');
	weather_july_slider			= $('weather_july_slider');
	weather_cloudy_slider		= $('weather_cloudy_slider');
	
	sliderPopulation = new Control.Slider(population_slider.select('.handle'), population_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		low_label: $('option_population_label_0'),
		high_label: $('option_population_label_1'),
		active_handle: null, 
		hotspots:[
			{ low:0,		mid: 0,		high:5,		label:'8,500',	actual:8500 },
			{ low:5.01,		mid: 10.5,	high:16.5,	label:'25,000',	actual:25000 },
			{ low:16.501,	mid: 21.5,	high:27,	label:'30,000',	actual:30000 },
			{ low:27.01,	mid: 32.5,	high:38,	label:'40,000',	actual:40000 },
			{ low:38.01,	mid: 44,	high:49.5,	label:'50,000',	actual:50000 },
			{ low:49.501,	mid: 55,	high:61,	label:'75,000',	actual:75000 },
			{ low:61.01,	mid: 67,	high:72,	label:'100,000',actual:100000 },
			{ low:72.01,	mid: 78,	high:84,	label:'500,000',actual:500000 },
			{ low:84.01,	mid: 89.5,	high:95,	label:'1M',actual:1000000 },
			{ low:95.01,	mid: 100,	high:100,	label:'8.3M',actual:8274527 }
		],
		
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			for(var i = 0; i < this.hotspots.length; i++)
			{
				if($R(this.hotspots[i].low, this.hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					if(this.hotspots[i].low == this.minimum) { new_value = this.hotspots[i].low; }
					else if(this.hotspots[i].high == this.maximum) { new_value = this.hotspots[i].high; }
					else { new_value = this.hotspots[i].mid; }

					//set labels for current active_handle
					if(this.active_handle == 0) { this.low_label.update(this.hotspots[i].label); }
					else { this.high_label.update(this.hotspots[i].label); }
					
					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }	
					
					//set value of active slider
					sliderPopulation.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = this.hotspots[i].mid;
				sliderPopulation.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});

	sliderHomePrices = new Control.Slider(homeprices_slider.select('.handle'), homeprices_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		low_label: $('option_homeprices_label_0'),
		high_label: $('option_homeprices_label_1'),
		active_handle: null,
		hotspots:[
			{ low:0,		mid: 0,		high:5,		label:'$49K',	actual:49260 },
			{ low:5.01,		mid: 10.5,	high:16.5,	label:'$100K',	actual:100000 },
			{ low:16.501,	mid: 21.5,	high:27,	label:'$175K',	actual:175000 },
			{ low:27.01,	mid: 32.5,	high:38,	label:'$250K',	actual:250000 },
			{ low:38.01,	mid: 44,	high:49.5,	label:'$400K',	actual:400000 },
			{ low:49.501,	mid: 55,	high:61,	label:'$750K',	actual:750000 },
			{ low:61.01,	mid: 67,	high:72,	label:'$1M',	actual:1000000 },
			{ low:72.01,	mid: 78,	high:84,	label:'$1.2M',	actual:1200000 },
			{ low:84.01,	mid: 89.5,	high:95,	label:'$1.4M',	actual:1400000 },
			{ low:95.01,	mid: 100,	high:100,	label:'$1.7M',	actual:1695000 }
		],
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }

			for(var i = 0; i < this.hotspots.length; i++)
			{
				if($R(this.hotspots[i].low, this.hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					if(this.hotspots[i].low == this.minimum) { new_value = this.hotspots[i].low; }
					else if(this.hotspots[i].high == this.maximum) { new_value = this.hotspots[i].high; }
					else { new_value = this.hotspots[i].mid; }

					//set labels for current active_handle
					if(this.active_handle == 0) { this.low_label.update(this.hotspots[i].label); }	
					else { this.high_label.update(this.hotspots[i].label); }
					
					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderHomePrices.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = this.hotspots[i].mid;
				sliderHomePrices.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});	
		
	sliderJobs = new Control.Slider(jobs_slider.select('.handle'), jobs_slider, {
		range: $R(0, 100),
		sliderValue: 0,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		onChange: function(value) {

			var hotspots = [
				{ low:0,		mid: 0,		high:12 },
				{ low:12.01,	mid: 25,	high:36 },
				{ low:36.01,	mid: 50,	high:62 },
				{ low:62.01,	mid: 75,	high:88 },
				{ low:88.01,	mid: 100,	high:100 }
			];

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(value))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(value == new_value) { break; }

					//set value of active slider
					sliderJobs.setValue(new_value);
					break;
				}
			}

			this.low_value = value;
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});	

	sliderWeatherDry = new Control.Slider(weather_dry_slider.select('.handle'), weather_dry_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 }
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderWeatherDry.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderWeatherDry.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});

	sliderWeatherSnow = new Control.Slider(weather_snow_slider.select('.handle'), weather_snow_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 } 
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderWeatherSnow.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderWeatherSnow.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});		

	sliderWeatherWinter = new Control.Slider(weather_winter_slider.select('.handle'), weather_winter_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 }
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderWeatherWinter.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];

			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderWeatherWinter.setValue(new_value, this.active_handle);
			}			
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});
	
	sliderWeatherSummer = new Control.Slider(weather_summer_slider.select('.handle'), weather_summer_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 }
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderWeatherSummer.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderWeatherSummer.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});	
	
	sliderWeatherJuly = new Control.Slider(weather_july_slider.select('.handle'), weather_july_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }

			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 }
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderWeatherJuly.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderWeatherJuly.setValue(new_value, this.active_handle);
			}			
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});	
	
	sliderWeatherCloudy = new Control.Slider(weather_cloudy_slider.select('.handle'), weather_cloudy_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
					
			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 }
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderWeatherCloudy.setValue(new_value, this.active_handle);
					break;
				}
			}			

			this.low_value = values[0];
			this.high_value = values[1];	

			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderWeatherCloudy.setValue(new_value, this.active_handle);
			}			
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});	

	sliderNeighborsMarried = new Control.Slider(neighbors_married_slider.select('.handle'), neighbors_married_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 }
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderNeighborsMarried.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];	

			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderNeighborsMarried.setValue(new_value, this.active_handle);
			}			
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});	

	sliderNeighborsAge = new Control.Slider(neighbors_age_slider.select('.handle'), neighbors_age_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		active_handle: null,
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			var hotspots = [
				{ low:0,     mid: 0,   high:13 },
				{ low:13.01, mid: 25,  high:38 },
				{ low:38.01, mid: 50,  high:62 },
				{ low:62.01, mid: 75,  high:88 },
				{ low:88.01, mid: 100, high:100 }
			];
			

			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }

					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }		

					//set value of active slider
					sliderNeighborsAge.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];

			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderNeighborsAge.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});
	
	//toggle options 
	bpl_toggle_option('option_region', 0, true);
	bpl_toggle_option('option_ranking', 0, true);
	bpl_toggle_option('option_population', 0, true);
	bpl_toggle_option('option_homeprices', 0, true);
	bpl_toggle_option('option_schools', 0, true);
	bpl_toggle_option('option_jobs', 0, true);
	bpl_toggle_option('option_weather', 0, true);
	bpl_toggle_option('option_crime', 0, true);
	bpl_toggle_option('option_activities', 0, true);
	bpl_toggle_option('option_neighbors', 0, true);
	
	//now show the section
	//$('cnnBPLsearchTool').style.top = 0;
	setTimeout("$('cnnBPLsearchTool').style.top = 0", 150);	
}


/**
 * Init from Stories. Small 4 options
 */
function init_bpl_starter_sm()
{
	population_slider			= $('population_slider');
	homeprices_slider			= $('homeprices_slider');
	
	sliderPopulation = new Control.Slider(population_slider.select('.handle'), population_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		low_label: $('option_population_label_0'),
		high_label: $('option_population_label_1'),
		active_handle: null, 
		hotspots:[
			{ low:0,		mid: 0,		high:5,		label:'8,500',	actual:8500 },
			{ low:5.01,		mid: 10.5,	high:16.5,	label:'25,000',	actual:25000 },
			{ low:16.501,	mid: 21.5,	high:27,	label:'30,000',	actual:30000 },
			{ low:27.01,	mid: 32.5,	high:38,	label:'40,000',	actual:40000 },
			{ low:38.01,	mid: 44,	high:49.5,	label:'50,000',	actual:50000 },
			{ low:49.501,	mid: 55,	high:61,	label:'75,000',	actual:75000 },
			{ low:61.01,	mid: 67,	high:72,	label:'100,000',actual:100000 },
			{ low:72.01,	mid: 78,	high:84,	label:'500,000',actual:500000 },
			{ low:84.01,	mid: 89.5,	high:95,	label:'1M',actual:1000000 },
			{ low:95.01,	mid: 100,	high:100,	label:'8.3M',actual:8274527 }
		],
		
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
						
			for(var i = 0; i < this.hotspots.length; i++)
			{
				if($R(this.hotspots[i].low, this.hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					if(this.hotspots[i].low == this.minimum) { new_value = this.hotspots[i].low; }
					else if(this.hotspots[i].high == this.maximum) { new_value = this.hotspots[i].high; }
					else { new_value = this.hotspots[i].mid; }

					//set labels for current active_handle
					if(this.active_handle == 0) { this.low_label.update(this.hotspots[i].label); }
					else { this.high_label.update(this.hotspots[i].label); }
					
					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }	
					
					//set value of active slider
					sliderPopulation.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = this.hotspots[i].mid;
				sliderPopulation.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});

	sliderHomePrices = new Control.Slider(homeprices_slider.select('.handle'), homeprices_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		low_label: $('option_homeprices_label_0'),
		high_label: $('option_homeprices_label_1'),
		active_handle: null,
		hotspots:[
			{ low:0,		mid: 0,		high:5,		label:'$49K',	actual:49260 },
			{ low:5.01,		mid: 10.5,	high:16.5,	label:'$100K',	actual:100000 },
			{ low:16.501,	mid: 21.5,	high:27,	label:'$175K',	actual:175000 },
			{ low:27.01,	mid: 32.5,	high:38,	label:'$250K',	actual:250000 },
			{ low:38.01,	mid: 44,	high:49.5,	label:'$400K',	actual:400000 },
			{ low:49.501,	mid: 55,	high:61,	label:'$750K',	actual:750000 },
			{ low:61.01,	mid: 67,	high:72,	label:'$1M',	actual:1000000 },
			{ low:72.01,	mid: 78,	high:84,	label:'$1.2M',	actual:1200000 },
			{ low:84.01,	mid: 89.5,	high:95,	label:'$1.4M',	actual:1400000 },
			{ low:95.01,	mid: 100,	high:100,	label:'$1.7M',	actual:1695000 }
		],
		onChange: function(values) {

			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }

			for(var i = 0; i < this.hotspots.length; i++)
			{
				if($R(this.hotspots[i].low, this.hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					if(this.hotspots[i].low == this.minimum) { new_value = this.hotspots[i].low; }
					else if(this.hotspots[i].high == this.maximum) { new_value = this.hotspots[i].high; }
					else { new_value = this.hotspots[i].mid; }

					//set labels for current active_handle
					if(this.active_handle == 0) { this.low_label.update(this.hotspots[i].label); }
					else { this.high_label.update(this.hotspots[i].label); }
					
					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }

					//set value of active slider
					sliderHomePrices.setValue(new_value, this.active_handle);
					break;
				}
			}

			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = this.hotspots[i].mid;
				sliderHomePrices.setValue(new_value, this.active_handle);
			}
			
			if(cnnInstantSearching) { bpl_search(); }
		}
	});	
	//toggle options 
	bpl_toggle_option('option_region', 0, true);
	bpl_toggle_option('option_ranking', 0, true);
	bpl_toggle_option('option_population', 0, true);
	bpl_toggle_option('option_homeprices', 0, true);

	
	//now show the section
	//$('cnnBPLsearchTool').style.top = 0;
	setTimeout("$('cnnBPLsearchTool').style.top = 0", 150);
	setTimeout('resize_bpl_frame()', 150);
}


/**
 * Init from Stories. All options
 */
function init_bpl_starter()
{
	//init_bpl();
	init_all_sliders();
	setTimeout('resize_bpl_frame()', 150);
}


/**
 * Full BPL Search as in /search/index.html
 */
function init_bpl()
{
	init_all_sliders();
	
	//add state checkboxes
	var html = '';
	for(var key in cnnStates)
	{
		html += '<input type="checkbox" onclick="bpl_select_region_state(this); bpl_select_checkbox_option();" name="region_state" value="'+key+'" /> '+cnnStates[key]+'<br />';
	}
	$('option_region_states').innerHTML = html;
	
	
	//process default search inputs via q
	var _qs = decodeURIComponent(location.search);

	if(_qs.indexOf("?") == 0)
	{
		var qs = _qs.substr(1, _qs.length);
		var vars = qs.split("&");
		var pairs = [];
		
		var last_option = 'option_homeprices';
		
		for(var i = 0; i < vars.length; i++)
		{
			pairs[pairs.length] = vars[i].split("=");
			switch(pairs[i][0])
			{
			
				case 'northeast':
				case 'south':
				case 'midwest':
				case 'west':
					bpl_bpl_toggle_option_use('option_region', true);
					
				case 'rank':
					$(pairs[i][0]).checked = (pairs[i][1] == 1)?1:0;
					bpl_bpl_toggle_option_use('option_ranking', true);
					break;
					
				case 'population_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderPopulation.values[1]) { sliderPopulation.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_population', true);
					break;
					
				case 'population_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderPopulation.values[0]) { sliderPopulation.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_population', true);
					break;
				
				case 'homeprices_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderHomePrices.values[1]) 
					{ 
						sliderHomePrices.setValue(pairs[i][1], 0); 
					}					
					bpl_bpl_toggle_option_use('option_homeprices', true);
					break;

				case 'homeprices_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderHomePrices.values[0]) 
					{ 
						sliderHomePrices.setValue(pairs[i][1], 1); 
					}
					bpl_bpl_toggle_option_use('option_homeprices', true);
					break;
					
				//schools
				case 'good_schools':
					$(pairs[i][0]).checked = (pairs[i][1] == 1)?1:0;
					bpl_bpl_toggle_option_use('option_schools', true);	
					last_option = 'option_schools';
					break;
					
				//job growth
				case 'jobgrowth':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100) { sliderJobs.setValue(pairs[i][1]); }
					bpl_bpl_toggle_option_use('option_jobs', true);
					last_option = 'option_jobs';
					break;

				//weather
				case 'dry_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderWeatherDry.values[1]) { sliderWeatherDry.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
				case 'dry_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderWeatherDry.values[0]) { sliderWeatherDry.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;

					
				case 'snow_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderWeatherSnow.values[1]) { sliderWeatherSnow.setValue(pairs[i][1], 0); }					
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
				case 'snow_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderWeatherSnow.values[0]) { sliderWeatherSnow.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
					
				case 'winter_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderWeatherWinter.values[1]) { sliderWeatherWinter.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
				case 'winter_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderWeatherWinter.values[0]) { sliderWeatherWinter.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
					
				case 'summer_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderWeatherSummer.values[1]) { sliderWeatherSummer.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
				case 'summer_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderWeatherSummer.values[0]) { sliderWeatherSummer.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
				case 'july_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderWeatherJuly.values[1]) { sliderWeatherJuly.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
				case 'july_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderWeatherJuly.values[0]) { sliderWeatherJuly.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
					
				case 'cloudy_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderWeatherCloudy.values[1]) { sliderWeatherCloudy.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
				case 'cloudy_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderWeatherCloudy.values[0]) { sliderWeatherCloudy.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_weather', true);
					last_option = 'option_weather';
					break;
					
					
				//crime
				case 'crime':
					$(pairs[i][0]).checked = (pairs[i][1] == 1)?1:0;
					bpl_bpl_toggle_option_use('option_crime', true);	
					last_option = 'option_crime';
					break;
					
					
				//activities
				case 'activities':
					for(var a = 0; a < document.bplsearch.activities.length; a++)
					{
						var bit = pairs[i][1] - document.bplsearch.activities[a].value;
						var value = pairs[i][1];
						if(test_bit(bit, value)) { document.bplsearch.activities[a].checked = true; }
					}
					bpl_bpl_toggle_option_use('option_activities', true);
					last_option = 'option_activities';
					break;
					
					
				//neighbors
				case 'single_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderNeighborsMarried.values[1]) { sliderNeighborsMarried.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_neighbors', true);
					last_option = 'option_neighbors';
					break;
					
				case 'single_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderNeighborsMarried.values[0]) { sliderNeighborsMarried.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_neighbors', true);
					last_option = 'option_neighbors';
					break;
					
				case 'age_low':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] < sliderNeighborsAge.values[1]) { sliderNeighborsAge.setValue(pairs[i][1], 0); }
					bpl_bpl_toggle_option_use('option_neighbors', true);
					last_option = 'option_neighbors';
					break;
					
				case 'age_high':
					if(pairs[i][1] >= 0 && pairs[i][1] <= 100 && pairs[i][1] > sliderNeighborsAge.values[0]) { sliderNeighborsAge.setValue(pairs[i][1], 1); }
					bpl_bpl_toggle_option_use('option_neighbors', true);
					last_option = 'option_neighbors';
					break;
					
				case 'income':
					$(pairs[i][0]).checked = (pairs[i][1] == 1)?1:0;
					bpl_bpl_toggle_option_use('option_neighbors', true);
					last_option = 'option_neighbors';
					break;
					
				case 'college':
					$(pairs[i][0]).checked = (pairs[i][1] == 1)?1:0;
					bpl_bpl_toggle_option_use('option_neighbors', true);
					last_option = 'option_neighbors';
					break;
					
				case 'diverse':
					$(pairs[i][0]).checked = (pairs[i][1] == 1)?1:0;
					bpl_bpl_toggle_option_use('option_neighbors', true);
					last_option = 'option_neighbors';
					break;
					
					
				default:
					break;
						}
		}

		bpl_search();
		bpl_toggle_option(last_option);
	}
}

/**
 * hack
 */
function get_slider_point(value, num_ticks)
{
	var slider_points = [];
	switch(num_ticks)
	{
		case 5:
			slider_points = [0, 25, 50, 75, 100];
			break;
			
		case 10:
			slider_points = [0, 10.5, 21.5, 32.5, 44, 55, 67, 78, 89.5, 100];
			break;
		
		default:
			break;
	}
	
	for(var i = 0; i < slider_points.length; i++)
	{
		if(value == slider_points[i]) { break; }
	}
	
	return (i + 1);
}

/**
 * hack
 */
function get_slider_point_actual(value, total_ticks, slidername)
{
	var pt = get_slider_point(value, total_ticks);
	if(slidername == 'population')
	{
		var actual = cnnSliderValues['population'][pt-1];
	}
	else
	{
		var actual = cnnSliderValues['homeprices'][pt-1];
	}

	return actual;
}

/*
function alertSize() 
{
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
  	myHeight = window.innerHeight;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {
  	//IE 4 compatible
	myHeight = document.body.clientHeight;
  }

  //window.alert( 'Height = ' + myHeight );
  return myHeight;
}
*/
function autoIframe(frameId)
{
	try
	{
		frame = document.getElementById(frameId);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		objToResize.height = innerDoc.body.scrollHeight + 10;
	}
	catch(err)
	{
		window.status = err.message;
	}
}


function _resize()
{
	try		
	{
		var bplIframe = parent.document.getElementById('bpl_search_frame'); 
		//bplIframe.frameBorder = 1;
		if (bplIframe) 
		{ 
	    	if (bplIframe.contentDocument && bplIframe.contentDocument.body.offsetHeight) 
			{ 
	        	// W3C DOM (and Mozilla) syntax 
				bplIframe.height = bplIframe.contentDocument.body.offsetHeight;
	        } 
	        else if (bplIframe.Document && bplIframe.Document.body.scrollHeight) 
			{ 
				// IE DOM syntax 
				bplIframe.height = bplIframe.Document.body.scrollHeight; 
	        } 
		} 
	}
	catch(e)
	{ 
		//alert("error\n" +e); 
	}
}


function resize_bpl_frame()
{
	setTimeout('_resize()', 350);
}

/**
 *
 */
function bpl_search(page_num)
{
	new Effect.Opacity('result_table', { from: 1.0, to: 0.4, duration: 0 });
	setTimeout("$('searchThrobber').show()", 10);

	try{ if(document.body.scrollTop > 315) { window.scroll(0, 0); } }
	catch(e) {}
	
	//handle paging searches
	if(page_num && cnnLastSearchResponse != null)
	{
		switch(page_num)
		{
			case 'prev':
				page_num = ((cnnLastSearchResponse.currpage - 1) >= 1)?(cnnLastSearchResponse.currpage - 1):1;
				setTimeout('_bpl_search_results('+page_num+')', 200);
				break;

			case 'next':
				page_num = ((cnnLastSearchResponse.currpage + 1) <= cnnLastSearchResponse.maxpage)?(cnnLastSearchResponse.currpage + 1):cnnLastSearchResponse.maxpage;
				setTimeout('_bpl_search_results('+page_num+')', 200);
				break;

			default:
				setTimeout('_bpl_search_results('+page_num+')', 200);
				break;
		}
	}
	// otherwise do a normal search
	else
	{
		setTimeout('_bpl_search('+page_num+')', 100);
	}
	
}

/**
 * gets next page from result set
 */
function _bpl_search_results(page_num)
{
	var post_string = '';
	
	if(cnnLastSearchResponse.query.crime)	{ post_string += 'crime=' +cnnLastSearchResponse.query.crime+'&'; }
	if(cnnLastSearchResponse.query.region)	{ post_string += 'region=' +cnnLastSearchResponse.query.region+'&'; }
	if(cnnLastSearchResponse.query.state)		{ post_string += 'state=' +cnnLastSearchResponse.query.state+'&'; }
	if(cnnLastSearchResponse.query.rank)		{ post_string += 'rank=' +cnnLastSearchResponse.query.rank+'&'; }
	if(cnnLastSearchResponse.query.population){ post_string += 'population=' +cnnLastSearchResponse.query.population+'&'; }
	if(cnnLastSearchResponse.query.homeprice)	{ post_string += 'homeprice=' +cnnLastSearchResponse.query.homeprice+'&'; }
	if(cnnLastSearchResponse.query.schools)	{ post_string += 'schools=' +cnnLastSearchResponse.query.schools+'&'; }
	if(cnnLastSearchResponse.query.jobgrowth)		{ post_string += 'jobgrowth=' +cnnLastSearchResponse.query.jobgrowth+'&'; }
	if(cnnLastSearchResponse.query.weather)	{ post_string += 'weather=' +cnnLastSearchResponse.query.weather+'&'; }
	if(cnnLastSearchResponse.query.activities){ post_string += 'activities=' +cnnLastSearchResponse.query.activities+'&'; }
	if(cnnLastSearchResponse.query.neighbors)	{ post_string += 'neighbors=' +cnnLastSearchResponse.query.neighbors+'&'; }
	
	//run search
	var uri = "http://apps.money.cnn.com/bestplaces_2009/screener.jsp?" +post_string;
	// alert(uri);
	var jo = new jObject(uri, 'bpl_search_callback');
	jo.add('callback', 'bpl_search_callback');
	jo.add('_page', page_num);
	jo.call();
}

/**
 * runs fresh search
 */
function _bpl_search()
{
    	var post_string = '';
	
	for(var option_id in cnnBPLOptions)
	{
		if(cnnBPLOptions[option_id].in_use)
		{
			var option = cnnBPLOptions[option_id];
			
			//region
			if(option_id == 'option_region')
			{
				var region_found = false;
				var str = '';
				var field_count = 0;
				//look for a region
				for(var i = 0; i < document.bplsearch.region.length; i++)
				{
					if(document.bplsearch.region[i].checked)
					{
						(str != '')?str += ',':'';
						str += document.bplsearch.region[i].value;
						region_found = true;
					}
				}
				
				if(region_found)
				{
					post_string += 'region=' +str+ '&';
					//jo.add("region", str);
				}
				
				//if no region found then look for state
				if(!region_found)
				{
					var state_found = false;
					var str = '';
					for(var i = 0; i < document.bplsearch.region_state.length; i++)
					{
						if(document.bplsearch.region_state[i].checked)
						{
							(str != '')?str += ',':'';
							str += document.bplsearch.region_state[i].value;
							state_found = true;
						}
					}

					if(state_found)
					{
						post_string += 'state=' +str + '&';
						//jo.add("state", str);
					}	
				}
			}
			
			
			//ranking
			if(option_id == 'option_ranking')
			{
				if(document.bplsearch.rank.checked)
				{
					post_string += 'rank=1&';
					//jo.add("rank", 1);
				}
			}
			
			//population slider
			if(option_id == 'option_population')
			{
				post_string += 'population=' +get_slider_point_actual(sliderPopulation.values[0], 10, 'population')+ ',' +get_slider_point_actual(sliderPopulation.values[1], 10, 'population')+ '&';
				//jo.add("population", get_slider_point(sliderPopulation.values[0], 10)+ ',' +get_slider_point(sliderPopulation.values[1], 10));
			}
			
			//home prices slider
			if(option_id == 'option_homeprices')
			{
				post_string += 'homeprice=' +get_slider_point_actual(sliderHomePrices.values[0], 10, 'homeprices')+ ',' +get_slider_point_actual(sliderHomePrices.values[1], 10, 'homeprices')+ '&';
				//jo.add("homeprice", get_slider_point(sliderHomePrices.values[0], 10)+ ',' +get_slider_point(sliderHomePrices.values[1], 10));
			}		
			
			//open schools
			if(option_id == 'option_schools')
			{
				if(document.bplsearch.good_schools.checked)
				{
					post_string += 'schools=1&';
					//jo.add("schools", 1);
				}
			}
			
			//job growth slider
			if(option_id == 'option_jobs')
			{
				post_string += 'jobgrowth=' +get_slider_point(sliderJobs.value, 5)+ '&';
				//jo.add("jobs", get_slider_point(sliderJobs.value, 5));
			}
			
			//weather slider
			if(option_id == 'option_weather')
			{
				var str = '';
				str += get_slider_point(sliderWeatherDry.values[0], 5) +''+ get_slider_point(sliderWeatherDry.values[1], 5);
				str += get_slider_point(sliderWeatherSnow.values[0], 5) +''+ get_slider_point(sliderWeatherSnow.values[1], 5);
				str += get_slider_point(sliderWeatherWinter.values[0], 5) +''+ get_slider_point(sliderWeatherWinter.values[1], 5);
				str += get_slider_point(sliderWeatherSummer.values[0], 5) +''+ get_slider_point(sliderWeatherSummer.values[1], 5);
				str += get_slider_point(sliderWeatherJuly.values[0], 5) +''+ get_slider_point(sliderWeatherJuly.values[1], 5);
				str += get_slider_point(sliderWeatherCloudy.values[0], 5) +''+ get_slider_point(sliderWeatherCloudy.values[1], 5);
				
				post_string += 'weather=' +str+ '&';
				//jo.add("weather", str);
			}
			
			//crime
			if(option_id == 'option_crime')
			{
				if(document.bplsearch.crime.checked)
				{
					post_string += 'crime=1&';
					//jo.add("crime", 1);
				}
			}

			//activities
			if(option_id == 'option_activities')
			{
				var total = 0;
				for(var i = 0; i < document.bplsearch.activities.length; i++)
				{
					if(document.bplsearch.activities[i].checked)
					{
						total = total + parseInt(document.bplsearch.activities[i].value);
					}
				}
				
				if(total > 0)
				{
					post_string += 'activities=' +total+ '&';
					//jo.add("activities", total);
				}
			}
			
			//neighbors slider
			if(option_id == 'option_neighbors')
			{
				var str = '';
				str += get_slider_point(sliderNeighborsMarried.values[0], 5) +''+ get_slider_point(sliderNeighborsMarried.values[1], 5);
				str += get_slider_point(sliderNeighborsAge.values[0], 5) +''+ get_slider_point(sliderNeighborsAge.values[1], 5);
				
				for(var i = 0; i < document.bplsearch.neighbor_options.length; i++)
				{
					str += (document.bplsearch.neighbor_options[i].checked)?1:0;
				}
				
				post_string += 'neighbors=' +str+ '&';
				//jo.add("neighbors", str);	
			}
			
		}
	}
	
	
	//run search
	var uri = "http://apps.money.cnn.com/bestplaces_2009/screener.jsp?" +post_string;
	//alert(uri);
	var jo = new jObject(uri, 'bpl_search_callback');
	jo.add('callback', 'bpl_search_callback');
	jo.call();
	
}

/**
 * Callback for searching
 */
function bpl_search_callback(response)
{
	var result_desc = $('results_desc');
	var result_table = $('result_table');
	
	//clear old results
	while(result_table.rows.length > 1)
	{
		result_table.deleteRow(result_table.rows.length-1);
	}

	//create new results
	if(response.results.length > 0)
	{
		result_desc.update('Displaying '+response.results[0].rownum+' - '+response.results[response.results.length-1].rownum+' of '+response.rows);
		result_desc.show();
		
		
		for(var i = 0; i < response.results.length; i++)
		{
			var data_row = response.results[i];
			var row = result_table.insertRow(result_table.rows.length);
			
			//rank
			var cell = row.insertCell(0);
			cell.className = 'cnncol1';
			if(!data_row.rank) { cell.innerHTML = '&nbsp;'; }
			else { cell.innerHTML = data_row.rank;  }
	
			//city
			var cell = row.insertCell(1);
			cell.className = 'cnncol2';
			cell.innerHTML = '<a href="/magazines/moneymag/bplive/2009/snapshots/'+data_row.id+'.html">'+data_row.city+', '+data_row.state+'</a>';
	
			//population
			var cell = row.insertCell(2);
			cell.className = 'cnncol3';
			cell.innerHTML = commify(new String(data_row.population));
	

			//build paging links		
			if(response.maxpage > 1)
			{
				cnnLastSearchResponse = response;
				
				var links_html = '';			
				for(var p = 1; p <= response.maxpage; p++)
				{
					if(response.currpage == p)
					{
						links_html += '<span class="currentPage">'+p+'</span>';
						continue;
					}
				
					links_html += ' <a href="javascript:bpl_search('+p+')">' +p+ '</a> ';
				}
				
				$('moneyBPLSearchLinks').innerHTML = links_html;
				$('moneyBPLSearch').show();	
			}
			else
			{
				$('moneyBPLSearchLinks').innerHTML = '';
				$('moneyBPLSearch').hide();
			}
			/* add total results here */
		}
	}
	else
	{
		result_desc.hide();
		//no results
		cnnLastSearchResponse = null;
		var row = result_table.insertRow(result_table.rows.length);
		var cell = row.insertCell(0);
		cell.colSpan = 3;
		cell.className = 'cnncol2';
		cell.innerHTML = '<div align="center">There are no results</div>';
		
		$('moneyBPLSearch').hide();
	}
	
	new Effect.Opacity('result_table', { from: 0.4, to: 1.0, duration: 0 });
	$('searchThrobber').hide();
	
}

/**
 *
 */
function bpl_select_checkbox_option()
{
	if(cnnInstantSearching) { bpl_search(); }
}

/**
 *
 */
function select_region(checkbox)
{
	for(var i = 0; i < document.bplsearch.region_state.length; i++)
	{
		document.bplsearch.region_state[i].checked = false;
	}
}

/**
 *
 */
function bpl_select_region_state(checkbox)
{
	for(var i = 0; i < document.bplsearch.region.length; i++)
	{
		document.bplsearch.region[i].checked = false;
	}
}


/**
 *
 */
function bpl_toggle_option(option_id, speed, skip_resize)
{
	var validate_safari = false;
	if(typeof(speed) == 'undefined' && typeof(skip_resize) == 'undefined')
	{
		validate_safari = true;
	}

	if(typeof(speed) == 'undefined')
	{
		var speed = .15;
	}
	
	var container =  $(option_id+'_container');
	var option_grp = $(option_id);
	var expander_button = $(option_id + '_expander_button');
	var toggle_use_button = $(option_id + '_toggle_use_button');
	
	if(container.hasClassName('cnnSearchCatOpen'))
	{
//		alert(window.navigator.userAgent);
		if((window.navigator.userAgent.toLowerCase().indexOf('safari') != -1) && validate_safari)
		{
			return;
		}

		expander_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/plus_red.gif';
		Effect.SlideUp(option_id, { duration: speed });
		container.removeClassName('cnnSearchCatOpen');
				
		if(cnnOpenOptionId == option_id)
		{
			cnnOpenOptionId = null;
		}
	}
	else
	{
		cnnBPLOptions[option_id].in_use = 1;
		expander_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/minus_red.gif';
		toggle_use_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/radio_blue.gif';
		Effect.SlideDown(option_id, { duration: speed });
		container.addClassName('cnnSearchCatOpen');
				
		if(cnnOpenOptionId != null)
		{
			bpl_toggle_option(cnnOpenOptionId);
		}
		
		cnnOpenOptionId = option_id;
	}
	
	if(skip_resize != true)
	{
		setTimeout('resize_bpl_frame()', 150);
	}
}

/**
 *
 */
function bpl_bpl_toggle_option_use(option_id, force_use)
{
	if(bpl_bpl_toggle_option_use.caller == null)
	{
		if(cnnInstantSearching) { bpl_search(); }	
	}
	
	if(typeof(force_use) == 'undefined') { var force_use = false; }

	var toggle_use_button = $(option_id + '_toggle_use_button');

	if(cnnBPLOptions[option_id].in_use == 0 || force_use == true)
	{
		cnnBPLOptions[option_id].in_use = 1;
		toggle_use_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/radio_blue.gif';
	}
	else
	{
		cnnBPLOptions[option_id].in_use = 0;
		toggle_use_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/radio_grey.gif';	
	}
}

/**
 *
 */
function bpl_toggle_all_options(open_all)
{
	var speed = .15;
	if(open_all == true)
	{
		for(var option_id in cnnBPLOptions)
		{
			var container =  $(option_id+'_container');
			var option_grp = $(option_id);
			var expander_button = $(option_id + '_expander_button');
			var toggle_use_button = $(option_id + '_toggle_use_button');	
			cnnBPLOptions[option_id].in_use = 1;
			
			if(container.hasClassName('cnnSearchCatOpen'))
			{
				cnnOpenOptionId = option_id;
				continue;
			}
			else
			{
				container.addClassName('cnnSearchCatOpen');
				expander_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/minus_red.gif';
				Effect.SlideDown(option_id, { duration: speed });	
				toggle_use_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/radio_blue.gif';
				cnnOpenOptionId = option_id;
			}
		}
	
		$('toggle_all').update('Click a category to see more ways to filter your results. <a href="javascript:bpl_toggle_all_options()">Close all</a>.');
	}
	else
	{
		for(var option_id in cnnBPLOptions)
		{	
			var container =  $(option_id+'_container');
			var option_grp = $(option_id);
			var expander_button = $(option_id + '_expander_button');
			var toggle_use_button = $(option_id + '_toggle_use_button');
		
			if(container.hasClassName('cnnSearchCatOpen'))
			{
				container.removeClassName('cnnSearchCatOpen');
				expander_button.src = 'http:\/\/i.cdn.turner.com/money/.element/img/2.0/buttons/plus_red.gif';
				Effect.SlideUp(option_id, { duration: speed });
			}
			cnnOpenOptionId = null;
		}
		
		$('toggle_all').update('Click a category to see more ways to filter your results. Or, <a href="javascript:bpl_toggle_all_options(true)">View all</a>.');	
	}
}

/**
 *
 */
function commify(input_value)
{
	var oRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');
	var aStr = input_value.split(".");
	input_value = aStr[0];

	//replace original string with first group match, a comma, then second group match
	while(oRegExp.test(input_value)) { input_value = input_value.replace(oRegExp, '$1,$2'); }
	
	if(aStr.length == 2) input_value = input_value+ "." +aStr[1];	
	return input_value;
}




/**
 *
 */
function bpl_starter_search()
{
	var qs = '';
	if(cnnBPLOptions['option_region'].in_use)
	{
		for(var i = 0; i < document.bplsearch.region.length; i++)
		{
			if(document.bplsearch.region[i].checked) { qs += document.bplsearch.region[i].id+ '=1&'; }
		}
	}
	
	if(cnnBPLOptions['option_ranking'].in_use && document.bplsearch.rank.checked) { qs += 'rank=1&'; }
	
	if(cnnBPLOptions['option_population'].in_use)
	{
		qs += 'population_low=' +sliderPopulation.values[0]+ '&';
		qs += 'population_high=' +sliderPopulation.values[1]+ '&';
	}
	

	if(cnnBPLOptions['option_homeprices'].in_use)
	{
		qs += 'homeprices_low=' +sliderHomePrices.values[0]+ '&';
		qs += 'homeprices_high=' +sliderHomePrices.values[1]+ '&';
	}
	
	if(cnnBPLOptions['option_schools'].in_use && document.bplsearch.good_schools.checked) { qs += 'good_schools=1&'; }
	
	if(cnnBPLOptions['option_jobs'].in_use) { qs += 'jobgrowth=' +sliderJobs.value+ '&'; }
	if(cnnBPLOptions['option_weather'].in_use) 
	{
		qs += 'dry_low=' +sliderWeatherDry.values[0]+ '&';
		qs += 'dry_high=' +sliderWeatherDry.values[1]+ '&';
		
		qs += 'snow_low=' +sliderWeatherSnow.values[0]+ '&';
		qs += 'snow_high=' +sliderWeatherSnow.values[1]+ '&';
		
		qs += 'winter_low=' +sliderWeatherWinter.values[0]+ '&';
		qs += 'winter_high=' +sliderWeatherWinter.values[1]+ '&';
		
		qs += 'summer_low=' +sliderWeatherSummer.values[0]+ '&';
		qs += 'summer_high=' +sliderWeatherSummer.values[1]+ '&';
		
		qs += 'july_low=' +sliderWeatherJuly.values[0]+ '&';
		qs += 'july_high=' +sliderWeatherJuly.values[1]+ '&';
		
		qs += 'cloudy_low=' +sliderWeatherCloudy.values[0]+ '&';
		qs += 'cloudy_high=' +sliderWeatherCloudy.values[1]+ '&';
	}
	
	
	if(cnnBPLOptions['option_crime'].in_use && document.bplsearch.crime.checked) { qs += 'crime=1&'; }	

	if(cnnBPLOptions['option_activities'].in_use) 
	{  
		var total = 0;
		for(var i = 0; i < document.bplsearch.activities.length; i++)
		{
			if(document.bplsearch.activities[i].checked)
			{
				total = total + parseInt(document.bplsearch.activities[i].value);
			}
		}
		
		qs += 'activities=' +total+'&';
	}
	
	if(cnnBPLOptions['option_neighbors'].in_use)
	{
		qs += 'single_low=' +sliderNeighborsMarried.values[0]+ '&';
		qs += 'single_high=' +sliderNeighborsMarried.values[1]+ '&';
		
		qs += 'age_low=' +sliderNeighborsAge.values[0]+ '&';
		qs += 'age_high=' +sliderNeighborsAge.values[1]+ '&';
		
		if($('income').checked) { qs += 'income=1&'; }
		if($('college').checked) { qs += 'college=1&'; }
		if($('diverse').checked) { qs += 'diverse=1&'; }
	}
	
	window.top.location.href = "/magazines/moneymag/bplive/2009/search/?" +qs;	
}


/**
 * Screener Initialization
 */
function init_screener()
{
	//sliders
	population_slider	= $('population_slider');
	homeprices_slider	= $('homeprices_slider');

	sliderPopulation = new Control.Slider(population_slider.select('.handle'), population_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		low_label: $('option_population_label_0'),
		high_label: $('option_population_label_1'),
		active_handle: null,
		onChange: function(values) {
	
			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }

			var hotspots = [
				{ low:0,		mid: 0,		high:5,		label:'8,500',	actual:8500 },
				{ low:5.01,		mid: 10.5,	high:16.5,	label:'25,000',	actual:25000 },
				{ low:16.501,	mid: 21.5,	high:27,	label:'30,000',	actual:30000 },
				{ low:27.01,	mid: 32.5,	high:38,	label:'40,000',	actual:40000 },
				{ low:38.01,	mid: 44,	high:49.5,	label:'50,000',	actual:50000 },
				{ low:49.501,	mid: 55,	high:61,	label:'75,000',	actual:75000 },
				{ low:61.01,	mid: 67,	high:72,	label:'100,000',actual:100000 },
				{ low:72.01,	mid: 78,	high:84,	label:'500,000',	actual:500000 },
				{ low:84.01,	mid: 89.5,	high:95,	label:'1M',actual:1000000 },
				{ low:95.01,	mid: 100,	high:100,	label:'8.3M',actual:8274527 }
			];
			
			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }
	
					//set labels for current active_handle
					if(this.active_handle == 0) { this.low_label.update(hotspots[i].label); }
					else { this.high_label.update(hotspots[i].label); }
					
					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }
					
					//set value of active slider
					sliderPopulation.setValue(new_value, this.active_handle);
					break;
				}
			}			
	
			this.low_value = values[0];
			this.high_value = values[1];
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderPopulation.setValue(new_value, this.active_handle);
			}			
		}
	});
	
	sliderHomePrices = new Control.Slider(homeprices_slider.select('.handle'), homeprices_slider, {
		range: $R(0, 100),
		sliderValue: [0, 100],
		restricted: 1,
		minimum: 0,
		maximum: 100,
		low_value: 0,
		high_value: 100,
		low_label: $('option_homeprices_label_0'),
		high_label: $('option_homeprices_label_1'),
		active_handle: null,
		onChange: function(values) {
	
			if(values[0] == this.low_value) { this.active_handle = 1; }
			else { this.active_handle = 0; }
	
			var hotspots = [
				{ low:0,		mid: 0,		high:5,		label:'$49K' },
				{ low:5.01,		mid: 10.5,	high:16.5,	label:'$100K' },
				{ low:16.501,	mid: 21.5,	high:27,	label:'$175K' },
				{ low:27.01,	mid: 32.5,	high:38,	label:'$250K' },
				{ low:38.01,	mid: 44,	high:49.5,	label:'$400K' },
				{ low:49.501,	mid: 55,	high:61,	label:'$750K' },
				{ low:61.01,	mid: 67,	high:72,	label:'$1M' },
				{ low:72.01,	mid: 78,	high:84,	label:'$1.2M' },
				{ low:84.01,	mid: 89.5,	high:95,	label:'$1.4M' },
				{ low:95.01,	mid: 100,	high:100,	label:'$1.7M' }
			];
			
	
			for(var i = 0; i < hotspots.length; i++)
			{
				if($R(hotspots[i].low, hotspots[i].high).include(values[this.active_handle]))
				{
					var new_value = 0;					
					if(hotspots[i].low == this.minimum) { new_value = hotspots[i].low; }
					else if(hotspots[i].high == this.maximum) { new_value = hotspots[i].high; }
					else { new_value = hotspots[i].mid; }
	
					//set labels for current active_handle
					if(this.active_handle == 0) { this.low_label.update(hotspots[i].label); }
					else { this.high_label.update(hotspots[i].label); }		
					
					//get out if value is same
					if(values[this.active_handle] == new_value) { break; }
	
					//set value of active slider
					sliderHomePrices.setValue(new_value, this.active_handle);
					break;
				}
			}			
	
			this.low_value = values[0];
			this.high_value = values[1];	
			
			//if values are eq then we need to move the active handle back 1 so theres never 2 handles in 1 slot.
			if(this.low_value == this.high_value)
			{
				(this.active_handle == 0)?i--:i++;
				new_value = hotspots[i].mid;
				sliderHomePrices.setValue(new_value, this.active_handle);
			}				
			
			
			get_slider_point(new_value, 10)
		}
	});

}

/**
 * Run a search using the screener
 */
function screener_search()
{
	var qs = '';
	for(var i = 0; i < document.bplsearch.region.length; i++)
	{
		if(document.bplsearch.region[i].checked) { qs += document.bplsearch.region[i].value+ '=1&'; }
	}
	
	if(document.bplsearch.rank.checked) { qs += 'rank=1&'; }
	
	qs += 'population_low=' +sliderPopulation.values[0]+ '&';
	qs += 'population_high=' +sliderPopulation.values[1]+ '&';
	qs += 'homeprices_low=' +sliderHomePrices.values[0]+ '&';
	qs += 'homeprices_high=' +sliderHomePrices.values[1];	
	
	location.href = "/magazines/moneymag/bplive/2009/search/?" +qs;
}

/* STATE TOGGLE */
function goToState(state) {
	var newUrl = "/magazines/moneymag/bplive/2009/states/" + state + ".html";
	window.location = newUrl;
}
/* FOR VIDEO TOUTS */
function writeWidgetBoxVideo(numFrames,currShow,fade, restart_interval) {
	if(typeof(restart_interval) == "undefined")
	{
		var restart_interval = false;
	}
	for (var i=1; i<=numFrames; i++) {
		document.getElementById('tnVideo'+i).style.visibility = "hidden";
		document.getElementById('tnVideo'+i).style.display = "none";
		if (i==currShow) {
			document.getElementById('tnVideo'+i).style.visibility = "visible";
			document.getElementById('tnVideo'+i).style.display = "block";
		}
	}
	//if (fade==true) {shiftOpacity('tncontainerVideo', 500);}
	var sequenceInd = document.getElementById('widgetSeqNumsVideo');
	sequenceInd.innerHTML = '';
	sequenceInd.innerHTML = '\(' + currShow + '&nbsp;of&nbsp;' + numFrames + '\)';
	var fade = true;
	

	if(restart_interval == true)
	{
		cnnRotateWidgetBoxVideo.restart(currShow);
	}
	
}
function rotateMeVideo(total,curr) {
	var newRotate = curr+1;
	if ( newRotate > total ) { newRotate = 1; }
	writeWidgetBoxVideo(total,newRotate,true);
	setTimeout("rotateMeVideo("+total+","+newRotate+")",7000);
}

/**
 * Image rotate object
 * For reuse, make a class, add a callback capability
 */
var cnnRotateWidgetBoxVideo = {
	window_interval:null,
	total_frames:1,
	current_frame:1,
	
	init:function(total_frames, current_frame)
	{
		this.total_frames = total_frames;
		this.current_frame = current_frame;
	},
	restart:function(current_frame)
	{
		this.current_frame = current_frame;
		this.stop();
		this.start();
	},
	rotate:function()
	{
		this.current_frame++;
		if(this.current_frame > this.total_frames)
		{
			this.current_frame = 1;
		}
		writeWidgetBoxVideo(this.total_frames, this.current_frame, true, false);
	},
	start:function(total_frames, current_frame)
	{
		this.window_interval = window.setInterval('cnnRotateWidgetBoxVideo.rotate()', 7000);
	},
	stop:function()
	{
		if(this.window_interval != null)
		{
			window.clearInterval(this.window_interval);
			this.window_interval = null;
		}
	}
};


//----------------------
// TYPEAHEAD
//----------------------

var gTypeAhead = null;
var typeahead_maxrows = 18; //maxdisplay rows
var gData = null;

function init_typeahead()
{
	//typeahead
	var inputs = {
		'target_node'		:'targetdiv',
		'onClick'			:'typeahead_callback_click',
		'onComplete'		:'typeahead_callback_request_complete'
	};	
	gTypeAhead = new TypeaheadField('gTypeAhead', 'http://apps.money.cnn.com/bestplaces_2009/bpl2009.jsp', inputs);
	gTypeAhead.init();
}

/**
 * TypeAhead onclick callback
 */
function typeahead_callback_click(selected_index)
{
	var id = gData[selected_index].id;
	location.href = "/magazines/moneymag/bplive/2009/snapshots/" +id+ ".html";
}

/**
 * TypeAhead request complete callback
 */
function typeahead_callback_request_complete(return_obj)
{
	if(typeof(return_obj) == "undefined")
	{
		$('listdiv').innerHTML = '';
		return;
	}
	
	gData = return_obj;
		
	var html = '<table class="list" cellspacing="0">';

	if(return_obj.length > 0)
	{	
		var len = (return_obj.length > typeahead_maxrows)?typeahead_maxrows:return_obj.length;
		
		for(var i = 0; i < len; i++)
		{
			html += '<tr><td class="list" id="typeahead_row_'+i+'" onmouseover="gTypeAhead.callbacks.onMouseOver.call(this, '+i+');" onclick="location.href = \'/magazines/moneymag/bplive/2009/snapshots/'+return_obj[i].id+'.html\'"><a id="typeahead_link_'+i+'" href="/magazines/moneymag/bplive/2009/snapshots/'+return_obj[i].id+'.html">'+return_obj[i].name+'</a></td></tr>';
		}
	}
	else
	{
		html += '<tr><td width="100%" class="nolist" id="typeahead_row_none">No Cities Found</td></tr>';
	}
	html += '</table>';
	
	$('listdiv').innerHTML = html;
	$('listdiv').show();
}
/* FOR GALLERY TOUTS ON SNAPSHOTS */
function writeWidgetBox(numFrames,currShow,fade) {
	for (var i=1; i<=numFrames; i++) {
		document.getElementById('tn'+i).style.visibility = "hidden";
		document.getElementById('tn'+i).style.display = "none";
		if (i==currShow) {
			document.getElementById('tn'+i).style.visibility = "visible";
			document.getElementById('tn'+i).style.display = "block";
		}
	}
	//if (fade==true) {shiftOpacity('tncontainer', 500);}
	var fade = true;
}
function shiftOpacity(id, millisec) {
	document.getElementById(id).style.opacity = 0
	opacity(id, 0, 100, millisec);
}
function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	for(i = opacStart; i <= opacEnd; i++) {
		setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
		timer++;
	}
}
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
function rotateMe(total,curr) {
	var newRotate = curr+1;
	if ( newRotate > total ) { newRotate = 1; }
	writeWidgetBox(total,newRotate,true);
	setTimeout("rotateMe("+total+","+newRotate+")",7000);
}

function test_bit(bit, value)
{
	if ((bit & value) == bit)  return true;
	else return false;
}

/* FOR EXPAND/COLLAPSE DATA ON SNAPSHOTS */
function revealMoreData() {
	if (navigator.appName=="Microsoft Internet Explorer") {
		document.getElementById('bpliveMoreData').style.display = 'block';
		document.getElementById('bpliveLessData').style.display = 'none';
	} else {
		document.getElementById('bpliveMoreData').style.display = 'table';
		document.getElementById('bpliveLessData').style.display = 'none';
	}
	document.getElementById('expandIndustries').style.display='none';
	document.getElementById('expandIndustries2').innerHTML='<a href="javascript:revealLessData();">See less data</a>';
}
function revealLessData() {
	document.getElementById('bpliveMoreData').style.display = 'none';
	document.getElementById('expandIndustries').style.display='block';
	if (navigator.appName=="Microsoft Internet Explorer") {
		document.getElementById('bpliveLessData').style.display = 'block';
	} else {
		document.getElementById('bpliveLessData').style.display = 'table';
	}
	document.getElementById('expandIndustries2').innerHTML='<a href="javascript:revealMoreData();">See all</a>';
	scrollTo(0, 936);
}
function showNavTab(tabId,tabNo) {
	var tabCollection = document.getElementById(tabId);
	tabCollection.className='Tab'+tabNo+'Visible';
}
