/* jQuery Eco-Dome Tutorial */
/* Zach Dunn (www.buildinternet.com) */

var climate;
var climate_fact;
var climate_banner;

function analyze_temperature(current_temp){
			
	//Determine current temperature range
	if (current_temp >= 0 && current_temp <= 32){
			
		//Arctic climate
		climate = "Arctic";
		
		//Get current banner
		climate_banner = $("#arctic-image").attr("src");
		
		$("#eco-dome").css({
			'background' : '#000 url("' + climate_banner + '") no-repeat top left'
		});
		
		$("body").css({
			'background' : '#285988 url("images/arctic-bg.jpg") no-repeat top left'
		});
		
		//Update displayed fact
		climate_fact = $("#arctic-fact").html();
		$(".fact").html(climate_fact);
			
	}else if (current_temp > 32 && current_temp < 75){
			
		//Moderate climate
		climate = "Moderate";
		
		//Get current banner
		climate_banner = $("#moderate-image").attr("src");
		
		$("#eco-dome").css({
			'background' : '#000 url("' + climate_banner + '") no-repeat top left'
		});
		
		$("body").css({
			'background' : '#5D7E2F url("images/moderate-bg.jpg") no-repeat top left'
		});
		
		//Update displayed fact
		climate_fact = $("#moderate-fact").html();
		$(".fact").html(climate_fact);
			
	}else{
		
		//Tropical climate
		climate = "Rainforest";
		
		//Get current banner
		climate_banner = $("#rainforest-image").attr("src");
		
		$("#eco-dome").css({
			'background' : '#000 url("' + climate_banner + '") no-repeat top left'
		});
		
		$("body").css({
			'background' : '#11170d url("images/rainforest-bg.jpg") no-repeat top left'
		});
		
		//Update displayed fact
		climate_fact = $("#rainforest-fact").html();
		$(".fact").html(climate_fact);
		
	}
		
}

function changeTemperature() {

	var current_temp = $("#temp-controller").slider("value");
	$(".current-temp").html(current_temp);
	
	//Determine climate from temperature
	analyze_temperature(current_temp);
	
	//Display climate title
	$(".current-climate").html(climate);
	
}

$(document).ready(function(){
	
	$("#temp-controller").slider({
		orientation: "vertical",
		range: "min",
		max: 100,
		min: 0,
		value: 50,
		slide: changeTemperature,
		change: changeTemperature
	});
	
});
