// Iowa.gov Global Javascript

function setTempColor() {
	var temp = jQuery('#weather .weather_status .weather_temp').text();
	var tempNum = temp.replace(/\D/g, '');
	var background = "#fff";
	var color = "#666";
	
	if (tempNum < 0) {
		// negative temps
		background = "#1cc6ea";
		color = "#fff";
	} else if (tempNum < 15) {
		// 1 - 14
		background = "#d2f3fb";
		color = "#666";
	} else if (tempNum < 30) {
		// 15 - 29
		background = "#1cc6ea";
		color = "#fff";
	} else if (tempNum < 45) {
		// 30 - 44
		background = "#398fee";
		color = "#fff";
	} else if (tempNum < 60) {
		// 45 - 59
		background = "#13c68c";
		color = "#fff";
	} else if (tempNum < 68) {
		// 60 - 67
		background = "#72ca22";
		color = "#fff";
	} else if (tempNum < 75) {
		// 68 - 74
		background = "#cef10a";
		color = "#666";
	} else if (tempNum < 83) {
		// 75 - 82
		background = "#f0df0b";
		color = "#666";
	} else if (tempNum < 90) {
		// 83 - 89
		background = "#f1bd0a";
		color = "#666";
	} else if (tempNum < 95) {
		// 90 - 94
		background = "#f08e0b";
		color = "#fff";
	} else {
		// 95+
		background = "#a82b24";
		color = "#fff";
	}
	
	$('#weather .weather_status').animate({
		borderColor: background
	}, 1500);
	$('#weather .weather_status .weather_temp').animate({
		backgroundColor: background
	}, 1500).css('color', color);
}

function tabNavInit() {
	var hash=window.location.hash;
	var currentTarget=hash.replace('/','');
	jQuery('ul.tabnav a').each(function(index){
		var target=$(this).attr('href').replace('/','');
		if (hash!="") {
			if (target==currentTarget) {
				$(this).addClass('current');
				$(target).addClass('open');
			} else {
				$(target).hide();
			}
		} else if (index==0) {
			$(this).addClass('current');
			$(target).addClass('open');
		} else {
			$(target).hide();
		}
		$(this).click(function(){
			$(target).show().siblings('.tabContentArea').hide();
			$(this).addClass('current').parent().siblings().find('a.current').removeClass('current');
		});
	}); 
}

jQuery(function(){
	setTempColor();
	tabNavInit();
});
