//var selectedRadar = getCookie('radar');
//var selectedLocation = getCookie('location');
var weather_timer = 0;
var detail = new Array('Humidity','Heat Index','Wind Chill','Wind Speed','Pressure','Dew Point','Daily Rain');
var data = new Array();
var d = new Date();
if (!selectedRadar) {setCookie('radar', '1'); selectedRadar = '1';}
if (!selectedLocation) {setCookie('location', '6'); selectedLocation = '6';}
changeRadarImage(selectedRadar); changeLocation(selectedLocation);

function changeRadarImage(x) {
	if (weather_timer) clearTimeout(weather_timer);
	var imageId = '', urlId = '';
	switch (parseInt(x)) {
		case 1: imageId='155'; urlId='16'; $('#radar_sf').attr("checked",true); break;
		case 2: imageId='160'; urlId='5'; $('#radar_huron').attr("checked",true); break;
		case 3: imageId='159'; urlId='15'; $('#radar_wall').attr("checked",true); break;
		default: imageId='155'; urlId='16'; $('#radar_sf').attr("checked",true); break;
	}
	setCookie('radar', x);
	$('#radarimage').attr("src","/weather/radarimages/"+imageId+"_resized184x138.jpg");
	$('#radarlink').attr("href","/weather/?w="+urlId+"&P=0");
	rotateweather(0);
}

function changeLocation(x) {
	if (weather_timer) clearTimeout(weather_timer);
	switch (parseInt(x)) {
		case 1: case 5: case 6:
			thisLocation = 'Sioux Falls'; $('#location_sf').attr("checked",true); break;
		case 3: case 9:
			thisLocation = 'Aberdeen'; $('#location_aberdeen').attr("checked",true); break;
		case 2: case 8:
			thisLocation = 'Pierre'; $('#location_pierre').attr("checked",true); break;
		case 4: case 7:
			thisLocation = 'Rapid City'; $('#location_rapid').attr("checked",true); break;
		default:
			thisLocation = 'Sioux Falls'; $('#location_sf').attr("checked",true); break;
	}
	thisTemp = wxdata.DATA.CURRENTTEMPERATURE[x-1];
	data = new Array(wxdata.DATA.HUMIDITY[x-1],wxdata.DATA.HEATINDEX[x-1]+'&deg;',wxdata.DATA.WINDCHILL[x-1]+'&deg;',wxdata.DATA.WIND[x-1]+' mph',wxdata.DATA.PRESSURE[x-1]+'&quot;',wxdata.DATA.DEWPOINT[x-1]+'&deg;',wxdata.DATA.DAILYRAIN[x-1]);

	setCookie('location', x);
	$('#weather_location').html(thisLocation);
	$('#weather_temp').html(thisTemp);
	rotateweather(0);
}

function rotateweather(x) {
	$('#weather_detail').html(detail[x]);
	$('#weather_data').html(data[x]);
	x = x + 1;
	if (d.getMonth() >= 3 && d.getMonth() <= 8) {
		if (x == 2) x = 3; //skip wind chill
	} else {
		if (x == 1) x = 2; //skip head index
	}
	if (x >= detail.length) {x = 0;}
	weather_timer = setTimeout("rotateweather("+x+")",3500);
}

