window.addEvent('domready', function() {
	if($('weather')) {
		if (location.host == 'www.mtu.edu') {
			var weatherJSON = new Request.JSON({
				url:'http://www.mtu.edu/mtu_resources/php/json/?raw=1&url=http://www.weather.gov/xml/current_obs/KCMX.xml', 
				onSuccess: function(data) {
					insert_weather(data.current_observation.icon_url_name, Math.round(data.current_observation.temp_f), data.current_observation.weather);
				}
			}).get();
		}
		else {
			new Asset.javascript('http://www.mtu.edu/mtu_resources/php/json/?var=weather&url=http://www.weather.gov/xml/current_obs/KCMX.xml', {onload: function() {
				insert_weather(weather.current_observation.icon_url_name, Math.round(weather.current_observation.temp_f), weather.current_observation.weather);
			}});
		}
		
		function insert_weather(icon, temp, condition) {
			switch(icon) {
				case 'skc.jpg': case 'few.jpg':
					icon = 'sunny.jpg';
					break;
					
				case 'bkn.jpg': case 'ovc.jpg': case 'sct.jpg': default:
					icon = 'partlycloudyday.jpg';
					break;	
				 
				case 'nbkn.jpg': case 'nsct.jpg': case 'novc.jpg': case 'nskc.jpg': case 'nfew.jpg': 
					icon = 'mooncloudy.jpg';
					break;			
				
				case 'sn.jpg': case 'fzra.jpg': case 'ip.jpg': case 'mix.jpg': case 'raip.jpg': case 'rasn.jpg': case 'fzrara.jpg':
					icon = 'snowshowers.jpg';
					break;
					
				case 'shra.jpg': case 'ra1.jpg': case 'ra.jpg': case 'nra.jpg': case 'nra1.jpg': case 'hi_shwrs.jpg': case 'hi_nshwrs.jpg':
					icon = 'rainshower.jpg';
					break;
					
				case 'tsra.jpg': case 'hi_tsra.jpg': case 'ntsra.jpg': case 'hi_ntsra.jpg':
					icon = 'thunderstorm.jpg';
					break;
					
				case 'wind.jpg': case 'nwind.jpg':
					icon = 'windy.jpg';
					break;
				
				case 'nsvrtsra.jpg':
					icon = 'twister.jpg';
					break;
				
				case 'mist.jpg':
					icon = 'rainbow.jpg';
					break;
			}
			$('weather').set('html', '<span>weather: <a target="_Blank" href="http://forecast.weather.gov/MapClick.php?CityName=Houghton&state=MI&site=MQT&textField1=47.1136&textField2=-88.5618"><img src="http://www.mtu.edu/mtu_resources/images/news/'+icon+'" alt="'+condition+'" /></a>'+ temp + '&deg;F</span>');
		}
	}
});
			
