// JavaScript Document

var city ='28'; // 地域ID　今は米沢市を指定している
var day = 'today'; // 予報日
var name = 'lwws1';
var proxy = 'http://app.drk7.jp/xml2json/';

var lwws1 = {};
lwws1.init = function() {
 var script = document.createElement('script');
 script.charset = 'UTF-8';
 script.src = proxy + 'var=' + this.name + '&url=' + 
 escape('http://weather.livedoor.com/forecast/webservice/rest/v1?city=' + city + '&day=' + this.day);
 document.body.appendChild(script);
}

lwws1.onload = function(data){
 var weather = data["telop"];
  
  var weatherFine = weather.match("晴");
  var weatherCloudy = weather.match("曇");
  var weatherRain = weather.match("雨");
  var weatherSnow = weather.match("雪");
 
  if (weatherFine && weatherCloudy) // 晴時々曇 or 晴のち曇　とその逆
		display = "common/css/fine_cloudy.css";
  else if (weatherFine && weatherRain) // 晴時々雨 or 晴のち雨　とその逆
		display = "common/css/fine_rain.css";
  else if (weatherFine && weatherSnow) // 晴時々雪 or 晴のち雪　とその逆
		display = "none";
  else if (weatherCloudy && weatherRain) // 曇時々雨 or 曇のち雨　とその逆
		display = "common/css/cloudy_rain.css";
  else if (weatherCloudy && weatherSnow) // 曇時々雪 or 曇のち雪　とその逆
		display = "none";
  else if (weatherRain && weatherSnow) // 雨時々雪 or 雨のち雪　とその逆
		display = "none";
  else if (weatherFine) // 晴
		display = "common/css/fine.css";
  else if (weatherCloudy) // 曇
		display = "common/css/cloudy.css";
  else if (weatherRain) // 雨
		display = "common/css/rain.css";
  else if (weatherSnow) // 雪
		display = "none";		
 
  var link = document.getElementById("style");
  link.href = display;
  
}

var old = window.onload;
window.onload = (typeof old != 'function') ?
 lwws1.init : function(e) { old(e); return lwws1.init(e); };
