//================================================================
//【2011.08.04変更】
//・各データの参照ディレクトリを変更（[/wnd]→[/weather/wnd]）
//・予報データを変更（[YOHO.csv]→[WNWK.csv]）
//・予報データのフォーマット変更に伴う参照を変更
//・エリア選択の参照を変更（[area_code]→[amedas_code]）
//
//http://www.ytv.co.jp/weather/wnd/WNWK.csv
//================================================================

(function ($) {
	$(document).ready(function () {
		$("#weather_area").hide();
		$("body").weather();
	});
	var name_space = 'weather';
	$.fn[name_space] = function (options) {
		var settings = $.extend({
			cookie_name: "area",
			default_area: 6200,
			default_amedas: 62078,
			default_cdr: 6200,
//----------------------------------------------------------------
//【2011.08.04変更】
//----------------------------------------------------------------
			//url: "/wnd/YOHO.csv",
			//arealist_url: "csv/arealist.csv",
			//wsh_url: "/wnd/WSH3.csv",
			//hda_url: "/wnd/HDA3.csv",
			//uv_url: "/wnd/UV03.csv",
			//cdr_url: "/wnd/CDR6.csv",
			
			url: "/weather/wnd/WNWK.csv",
			arealist_url: "csv/arealist.csv",
			wsh_url: "/weather/wnd/WSH3.csv",
			hda_url: "/weather/wnd/HDA3.csv",
			uv_url: "/weather/wnd/UV03.csv",
			cdr_url: "/weather/wnd/CDR6.csv",
//----------------------------------------------------------------
			nine_hour_miliseconds: 32400000,
			weeks: ["(日)", "(月)", "(火)", "(水)", "(木)", "(金)", "(土)"]
		}, options);
		var elements = this;
		var yoho_list = [];
		var area_list = [];
		var wsh_list = [];
		var hda_list = [];
		var uv_list = [];
		var cdr_list = [];
		var Datas = [yoho_list, area_list, wsh_list, hda_list, uv_list, cdr_list];
		var SeasonDatas = [wsh_list, hda_list, uv_list, cdr_list];
		var csvs = [settings.url, settings.arealist_url, settings.wsh_url, settings.hda_url, settings.uv_url, settings.cdr_url];
		var hda_comment = ["湿度が高く、お肌の潤いは十分に保てそうです", "空気が乾燥してきました。お出かけ前にクリームを塗っておきましょう", "カラカラ空気がお肌の潤いを奪います。保湿はたっぷりしましょう", "出かける時はもちろん、外出先でもこまめな潤い補給を心がけましょう"]
		var uv_comment = ["日差しは厚い雲に遮（さえぎ）られ、紫外線の量は少ないでしょう", "肌の弱い方や長い時間の外出にはケアが必要です", "日焼け止めクリームや日傘などでしっかりブロックしましょう", "紫外線が容赦なく降り注ぎます。万全な対策を取ってください"]
		var wsh_comment = ["部屋干しするか、乾燥機を使うしかなさそうです", "薄手の物や小物を中心に、時間をかけて乾かしましょう", "朝から干せば十分に乾きそうです", "絶好の洗濯日和。どんなものでも気持ちよく仕上がるでしょう"]
		var cdr_comment = ["花粉の飛ぶ量は少なく、対策なしでもお出かけできるでしょう", "やや多く飛びそうです。マスクやメガネがあると良いでしょう", "飛散量は多く、辛い一日となりそうです。万全な対策を心がけて下さい", "大量に飛ぶでしょう。洗濯物は部屋に干すなど、厳重な警戒が必要です"]
		var comments = [wsh_comment, hda_comment, uv_comment, cdr_comment];
		var seasons = ["洗濯情報", "肌荒れ情報", "紫外線情報", "花粉情報"];
		var load_count = 0;
		var area_code;
		var amedas_code;
		var cdr_code;

		function main() {
			getCookie();
			LoadData();
		}
		this.test = test;
		var isdebug = false;

		function test() {
			isdebug = true;
			area_code = settings.default_area;
			amedas_code = settings.default_amedas;
			cdr_code = settings.default_cdr;
			var tests = [{
				num: 0,
				yoho: "6200,20090928020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090927021500,50,20",
				expect_y: 100,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20100125020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20100124081500,50,20",
				expect_y: 100,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20090928080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090927081500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 0,
				yoho: "6200,20090928020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090927081500,50,20",
				expect_y: 100,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090901145900,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 0,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090901155900,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090901154000,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20091129080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091129150000,50,20",
				expect_y: 10,
				expect_s: 50
			}, {
				num: 0,
				yoho: "6200,20091129080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091129080000,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20091129080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091129080000,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20091129080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091128081500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 0,
				yoho: "6200,20091129020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091128021500,50,20",
				expect_y: 100,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20091129200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091128201500,50,20",
				expect_y: 100,
				expect_s: 20
			}, {
				num: 0,
				yoho: "6200,20091129190000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091128191500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 0,
				yoho: "6200,20091129190000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091128151500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 0,
				yoho: "6200,20090902021500,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 100,
				expect_s: 50
			}, {
				num: 1,
				yoho: "6200,20090902145900,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 1,
				yoho: "6200,20090902150000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 1,
				yoho: "6200,20090902160000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 1,
				yoho: "6200,20090902170000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 1,
				yoho: "6200,20090902180000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 1,
				yoho: "6200,20090902190000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 1,
				yoho: "6200,20090902200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 100,
				expect_s: 20
			}, {
				num: 1,
				yoho: "6200,20090902210000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902171500,50,20",
				expect_y: 100,
				expect_s: 50
			}, {
				num: 2,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902171500,50,20",
				expect_y: 10,
				expect_s: 50
			}, {
				num: 2,
				yoho: "6200,20090902090000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 2,
				yoho: "6200,20090902100000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 2,
				yoho: "6200,20090902110000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 2,
				yoho: "6200,20090902120000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 2,
				yoho: "6200,20090902130000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 2,
				yoho: "6200,20090902140000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 3,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 4,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090904081500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 4,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090904081500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 5,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902081500,999,999",
				expect_y: 10,
				expect_s: 999
			}, {
				num: 6,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902161500,50,20",
				expect_y: 10,
				expect_s: 50
			}, {
				num: 7,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902142359,50,20",
				expect_y: 10,
				expect_s: 20
			}, {
				num: 8,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902154000,50,20",
				expect_y: 10,
				expect_s: 50
			}, {
				num: 9,
				yoho: "6200,20090902200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902154000,50,20",
				expect_y: 100,
				expect_s: 50
			}, {
				num: 10,
				yoho: "6200,20090902200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902201500,50,20",
				expect_y: 100,
				expect_s: 50
			}, {
				num: 11,
				yoho: "6200,20090902020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090901201500,50,20",
				expect_y: 100,
				expect_s: 50
			}, {
				num: 12,
				yoho: "6200,20090902020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902021500,50,20",
				expect_y: 100,
				expect_s: 50
			}, {
				num: 13,
				yoho: "6200,20090902080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090901081500,50,20",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 14,
				yoho: "6200,20090320080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090320190000,3,2",
				expect_y: 10,
				expect_s: 3
			}, {
				num: 15,
				yoho: "6200,20090320200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090320190000,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 16,
				yoho: "6200,20090320020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090319190000,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 17,
				yoho: "6200,20090320020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090320040000,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 18,
				yoho: "6200,20090320020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090320070000,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 19,
				yoho: "6200,20090320080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090320070000,3,2",
				expect_y: 10,
				expect_s: 2
			}, {
				num: 20,
				yoho: "6200,20090320080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090318190000,3,2",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 20,
				yoho: "6200,20090320080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "6200,20090320040000,3,2",
				expect_y: 10,
				expect_s: 2
			}, {
				num: 22,
				yoho: "6200,20090120080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090120145900,3,2",
				expect_y: 10,
				expect_s: 2
			}, {
				num: 23,
				yoho: "6200,20090120080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090120150040,3,2",
				expect_y: 10,
				expect_s: 3
			}, {
				num: 24,
				yoho: "6200,20090120200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090120150040,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 25,
				yoho: "6200,20090119200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090119201500,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 26,
				yoho: "6200,20090119020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090118201500,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 27,
				yoho: "6200,20090119020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090119021500,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 29,
				yoho: "6200,20090219080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090219091500,3,2",
				expect_y: 10,
				expect_s: 2
			}, {
				num: 30,
				yoho: "6200,20091219020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20091218011500,3,2",
				expect_y: 100,
				expect_s: 888
			}, {
				num: 31,
				yoho: "6200,20090119020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090119021500,999,2",
				expect_y: 100,
				expect_s: 999
			}, {
				num: 31,
				yoho: "6200,20090219080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090219091500,3,999",
				expect_y: 10,
				expect_s: 999
			}, {
				num: 32,
				yoho: "6200,20090219080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090218081500,3,2",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 33,
				yoho: "6200,20090520080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090520145900,3,2",
				expect_y: 10,
				expect_s: 2
			}, {
				num: 34,
				yoho: "6200,20090620080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090620150040,3,2",
				expect_y: 10,
				expect_s: 3
			}, {
				num: 35,
				yoho: "6200,20090720200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090720150040,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 36,
				yoho: "6200,20090819200000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090819201500,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 37,
				yoho: "6200,20090519020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090518201500,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 38,
				yoho: "6200,20090619020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090619021500,3,2",
				expect_y: 100,
				expect_s: 3
			}, {
				num: 39,
				yoho: "6200,20090719080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090719091500,3,2",
				expect_y: 10,
				expect_s: 2
			}, {
				num: 40,
				yoho: "6200,20090819020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090818011500,3,2",
				expect_y: 100,
				expect_s: 888
			}, {
				num: 41,
				yoho: "6200,20090519020000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090519021500,999,2",
				expect_y: 100,
				expect_s: 999
			}, {
				num: 41,
				yoho: "6200,20090619080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090619091500,3,999",
				expect_y: 10,
				expect_s: 999
			}, {
				num: 42,
				yoho: "6200,20090719080000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090718081500,3,2",
				expect_y: 10,
				expect_s: 888
			}, {
				num: 1,
				yoho: "6200,20090902210000,100,10,999,999,0010,0000,0000,0010,0010,18,999,29",
				season: "62078,20090902171500,50,20",
				expect_y: 100,
				expect_s: 50
			}];
			var info = false;
			var count = 1;
			var prev = 0;
			for (var i = 0; tests.length > i; i++) {
				var item = tests[i].yoho.split(",");
				var season_data = [tests[i].season.split(",")];
				var expect_y = tests[i].expect_y;
				var expect_s = tests[i].expect_s;
				var num = tests[i].num;
				yohodt = parseDate(item[1]);
				yoho_date = parseDate3(item[1]);
				yoho_milidt = parseDate2(item[1]);
				var weather;
				var state;
				if (yoho_date.getHours() > 16 || yoho_date.getHours() < 5) {
					weather = item[3];
					state = "tomorrow";
				} else {
					weather = item[2];
					state = "today";
				}
				var mon = yohodt.getMonth();
				if (mon < 2) index = 1;
				if (mon > 1 && mon < 4) index = 3;
				if (mon > 3 && mon < 8) index = 2;
				if (mon > 7 && mon < 11) index = 0;
				if (mon == 11) index = 1;
				SeasonDatas[index] = season_data;
				var result = getSeasonInfo(yohodt);
				if ((mon > 1 && mon < 4) && (cdr_code == 9999 || cdr_code == "9999")) {
					result.comment = "情報はありません";
					result.rank = "999";
				} else {
					var seasonTime = parseDate2(result.time);
					var saiTime = yoho_milidt - seasonTime;
					if (86400000 <= saiTime || -86400000 >= saiTime) {
						result.comment = "情報を取得中です";
						result.rank = "888";
					} else {
						if ((mon > 1 && mon < 4) && (cdr_code == 9999 || cdr_code == "9999") || result.comment == null || result.rank == null) {
							result.comment = "情報はありません";
							result.rank = "999";
						} else {}
					}
				}
				if (prev != num) {
					prev = num;
					count = 1;
				} else {
					count++;
				}
				if (expect_y == weather && expect_s == result.rank) {
					trace("test " + num + "(" + count + ")" + " : " + item[1] + "/" + season_data[0][1] + " .. ok");
					if (info) {
						trace("  yoho   :\n" + "    yohodt     :" + yohodt + "\n" + "    weather    :" + weather + "\n" + "    time       :" + yoho_date + "\n" + "    state      :" + state + "\n" + "  season :\n" + "    title      :" + result.title + "\n" + "    rank       :" + result.rank + "\n" + "    comment    :" + result.comment + "\n" + "    time       :" + result.date + "\n" + "    state      :" + result.state + "\n");
					}
				} else {
					trace("test " + num + "(" + count + ")" + " : " + item[1] + "/" + season_data[0][1] + " .. no !!!!!!!!!!!!!!!");
					trace("  yoho   :\n" + "    yohodt     :" + yohodt + "\n" + "    weather    :" + weather + "\n" + "    time       :" + yoho_date + "\n" + "    state      :" + state + "\n" + "  season :\n" + "    title      :" + result.title + "\n" + "    rank       :" + result.rank + "\n" + "    comment    :" + result.comment + "\n" + "    time       :" + result.date + "\n" + "    state      :" + result.state + "\n");
				}
			}
		}
		var load_index = 0;

		function getCookie() {
			var data = jQuery.cookie(settings.cookie_name);
			if (data == null || data == "") {
				data = settings.default_area + "?" + settings.default_amedas + "?" + settings.default_cdr;
			}
			data = data.split("?");
			area_code = data[0] || settings.default_area;
			amedas_code = data[1] || settings.default_amedas;
			cdr_code = data[2] || settings.default_cdr;
		}

		function LoadData() {
			var index;
			var mon = new Date().getMonth();
			if (mon < 2) index = 1;
			if (mon > 1 && mon < 4) index = 3;
			if (mon > 3 && mon < 8) index = 2;
			if (mon > 7 && mon < 11) index = 0;
			if (mon == 11) index = 1;
			if (load_count < 2) {
				var url = csvs[load_count];
				load_index = load_count;
				load(url);
			} else {
				onLoadComplete();
			}
		}

		function load(url) {
			try {
				$.ajax({
					url: url,
					type: 'GET',
					dataType: 'text',
					error: onErrorCSV,
					success: onLoadCSV
				});
			} catch (e) {
				onErrorCSV(e);
			}
		}

		function onLoadCSV(csv) {
			var temp_datas = csv.split("\r\n");
			var len = temp_datas.length - 1;
			if (temp_datas[len].length < 1) temp_datas.pop();
			var temp_items = [];
			var item = "";
			var data = Datas[load_index];
			for (var i = 0; len > i; i++) {
				item = temp_datas[i];
				temp_items = item.split(",");
				data.push(temp_items);
			}
			load_count++;
			LoadData();
		}

		function onLoadComplete() {
			var area = getArea();
			var code = area.code;
			var name = area.name;
			if (name == "東京都東京") {
				name = "東京都";
			} else if (name == "大阪府大阪") {
				name = "大阪府";
			}
			var yoho = getYoho();
			var date = yoho.date;
			var today_weather = yoho.today_weather;
			var tomorrow_weather = yoho.tomorrow_weather;
			var tomorrow_temp_min = yoho.tomorrow_temp_min;
			var today_temp_max = yoho.today_temp_max;
			var tomorrow_temp_max = yoho.tomorrow_temp_max;
			yoho.code = code;
			yoho.name = name;
			draw(yoho);
		}
		var yohodt;
		var yoho_date;
		var yoho_milidt;

		function draw(options) {
			$("#weather_title").text(options.name);
			var dt = parseDate(options.date);
			yoho_date = parseDate3(options.date);
			yoho_milidt = parseDate2(options.date);
			yohodt = dt;
			var month = dt.getMonth() + 1;
			var date = dt.getDate();
			var day = dt.getDay();
			day = settings.weeks[day];
			var dateStr = month + "月" + date + "日" + " " + day + "";
			$("#weather_date").text(dateStr);
			var temp = getTemp(options, dt);
			$("#temp_max").text(temp.max);
			$("#temp_min").text(temp.min);
			var weather;
			if (yoho_date.getHours() > 16 || yoho_date.getHours() < 5) {
				weather = options.tomorrow_weather;
			} else {
				weather = options.today_weather;
			}
			var comment = getWeatherComment(parseInt(weather));
			var anopic = getAnnouncer(weather, dt.getDay());
			$("#announcer img").attr("src", anopic);
			var temp_icon = getTempIcon(parseInt(weather));
			$("#weather_icon img").attr("src", temp_icon);
			var mon = month - 1;
			if (mon < 2) index = 1;
			if (mon > 1 && mon < 4) index = 3;
			if (mon > 3 && mon < 8) index = 2;
			if (mon > 7 && mon < 11) index = 0;
			if (mon == 11) index = 1;
			load_index = index + 2;
			getSeasonCSV(csvs[load_index]);
		}

		function getSeasonCSV(url) {
			try {
				$.ajax({
					url: url,
					type: 'GET',
					dataType: 'text',
					error: onErrorSeasonCSV,
					success: onLoadSeasonCSV
				});
			} catch (e) {
				onErrorSeasonCSV(e);
			}
		}

		function onErrorSeasonCSV(e) {
			var mon = yohodt.getMonth();
			if (mon < 2) index = 1;
			if (mon > 1 && mon < 4) index = 3;
			if (mon > 3 && mon < 8) index = 2;
			if (mon > 7 && mon < 11) index = 0;
			if (mon == 11) index = 1;
			var title = seasons[index];
			$("#weather_today").text(title);
			$("#weather_value").text("情報を取得中です");
			$("#weather_area").show();
		}

		function onLoadSeasonCSV(csv) {
			var temp_datas = csv.split("\r\n");
			var len = temp_datas.length - 1;
			if (temp_datas[len].length < 1) temp_datas.pop();
			var temp_items = [];
			var item = "";
			var data = Datas[load_index];
			for (var i = 0; len > i; i++) {
				item = temp_datas[i];
				temp_items = item.split(",");
				data.push(temp_items);
			}
			onLoadSeason();
		}

		function onLoadSeason() {
			var mon = yohodt.getMonth();
			if ((mon > 1 && mon < 4) && (cdr_code == 9999 || cdr_code == "9999")) {
				if (mon < 2) index = 1;
				if (mon > 1 && mon < 4) index = 3;
				if (mon > 3 && mon < 8) index = 2;
				if (mon > 7 && mon < 11) index = 0;
				if (mon == 11) index = 1;
				var title = seasons[index];
				$("#weather_today").text(title);
				$("#weather_value").text("情報はありません");
			} else {
				var season = getSeasonInfo(yohodt);
				$("#weather_today").text(season.title);
				var seasonTime = parseDate2(season.time);
				var saiTime = yoho_milidt - seasonTime;
				if (86400000 <= saiTime || -86400000 >= saiTime) {
					$("#weather_value").text("情報を取得中です");
				} else {
					if ((mon > 1 && mon < 4) && (cdr_code == 9999 || cdr_code == "9999") || season.comment == null || season.rank == null) {
						$("#weather_value").text("情報はありません");
					} else {
						$("#weather_value").text(season.comment);
					}
				}
			}
			$("#weather_icon img").attr("onload", function () {
				$("#weather_area").show();
			});
		}

		function getWeatherComment(code) {
			var comment = "";
			if (code < 199) {
				comment = "予報は晴れね";
			} else if (code > 199 && code < 300) {
				comment = "予報は曇りね";
			} else if (code > 299 && code < 400) {
				comment = "予報では雨かぁ・・";
			} else if (code > 399) {
				comment = "予報は雪ね";
			}
			return comment;
		}

		function getSeasonInfo(date) {
			var code;
			var today;
			var tomorrow;
			var index;
			var time;
			var mon = date.getMonth();
			if (mon < 2) index = 1;
			if (mon > 1 && mon < 4) index = 3;
			if (mon > 3 && mon < 8) index = 2;
			if (mon > 7 && mon < 11) index = 0;
			if (mon == 11) index = 1;
			var list = SeasonDatas[index];
			for (var i = 0; list.length > i; i++) {
				item = list[i];
				code = parseInt(item[0]);
				if (mon == 2 || mon == 3) {
					if (code == cdr_code) {
						time = item[1];
						today = item[2];
						tomorrow = item[3];
						break;
					}
				} else if (code == amedas_code) {
					time = item[1];
					today = item[2];
					tomorrow = item[3];
					break;
				}
			}
			var title = seasons[index];
			var rank;
			var dt = parseDate(time);
			if (dt == null) {
				onErrorSeasonCSV();
				return false;
			}
			var dt2 = parseDate3(time);
			var yohoTime = yoho_date.getTime();
			yohoTime = yohoTime + settings.nine_hour_miliseconds;
			var dat = new Date(yohoTime);
			var yohoTime2 = dt2.getTime();
			yohoTime2 = yohoTime2 + settings.nine_hour_miliseconds;
			var dat2 = new Date(yohoTime2);
			var orgyohoTime = yoho_date.getTime();
			orgyohoTime = orgyohoTime - settings.nine_hour_miliseconds;
			var orgdat = new Date(orgyohoTime);
			var orgyohoTime2 = dt2.getTime();
			orgyohoTime2 = orgyohoTime2 - settings.nine_hour_miliseconds;
			var orgdat2 = new Date(orgyohoTime2);
			var prevtime = orgdat.getTime();
			prevtime = prevtime - settings.nine_hour_miliseconds;
			var prevdate = new Date(prevtime);
			var istomorrow = true;
			var season_state;
			if (yoho_date.getHours() > 16 || yoho_date.getHours() < 5) {
				if (date.getDate() == dt2.getDate()) {
					istomorrow = false;
					rank = today;
					season_state = "today";
					if (date.getDate() != dat2.getDate()) {
						rank = "888";
						if (prevdate.getDate() == dt2.getDate()) {
							rank = tomorrow;
							season_state = "tomorrow";
							istomorrow = true;
						}
					}
				} else {
					rank = tomorrow;
					season_state = "tomorrow";
					if (yoho_date.getDate() != dt2.getDate()) {
						rank = "888";
					}
				}
				if (yoho_date.getDate() != dt2.getDate()) {}
			} else {
				istomorrow = false;
				rank = today;
				season_state = "today";
				var yohoTime = yoho_date.getTime();
				var dat = new Date(yohoTime);
				var yohoTime2 = dt2.getTime();
				var dat2 = new Date(yohoTime2);
				if (date.getDate() != dat2.getDate()) {
					rank = "888";
					if (prevdate.getDate() == dt2.getDate()) {
						rank = tomorrow;
						season_state = "tomorrow";
						istomorrow = true;
					}
				}
			}
			var yohoTime = yoho_date.getTime();
			var seasonTime = dt2.getTime();
			var saiTime = yohoTime - seasonTime;
			var t1 = new Date(yohoTime);
			var t2 = new Date(seasonTime);
			if (86400000 <= saiTime || -86400000 >= saiTime) {
				rank = "888";
			}
			var comment = getComments(index, parseInt(rank));
			var item = {
				title: title,
				rank: rank,
				comment: comment,
				time: time,
				state: season_state,
				date: dt2
			};
			return item;
		}

		function getComments(index, rank) {
			if (rank == 999 || rank == "999") {
				return "情報はありません";
			}
			if (rank == 888 || rank == "888") {
				return "情報を取得中です";
			}
			var comment_list = comments[index];
			var i = null;
			if (index == 0) {
				if (rank < 39) i = 0;
				else if (rank > 39 && rank < 60) i = 1;
				else if (rank > 59 && rank < 80) i = 2;
				else if (rank > 79) i = 3;
			} else if (index == 1) {
				if (rank < 19) i = 0;
				else if (rank > 19 && rank < 60) i = 1;
				else if (rank > 59 && rank < 80) i = 2;
				else if (rank > 79) i = 3;
			} else if (index == 2) {
				if (rank < 39) i = 0;
				else if (rank > 39 && rank < 60) i = 1;
				else if (rank > 59 && rank < 80) i = 2;
				else if (rank > 79) i = 3;
			} else if (index == 3) {
				switch (rank) {
				case 2:
					i = 0;
					break;
				case 3:
					i = 1;
					break;
				case 4:
					i = 2;
					break;
				case 5:
					i = 3;
					break;
				}
			}
			var comment = null;
			if (i != null) {
				comment = comment_list[i];
			}
			return comment;
		}

		function getTempIcon(code) {
			var icon = "images/wicon_";
			var icon_code;
			switch (code) {
			case 100:
			case 123:
			case 124:
			case 130:
			case 131:
				icon_code = 100;
				break;
			case 101:
			case 132:
				icon_code = 101;
				break;
			case 102:
			case 103:
			case 106:
			case 107:
			case 120:
			case 121:
			case 140:
				icon_code = 102;
				break;
			case 108:
				icon_code = 108;
				break;
			case 104:
			case 105:
			case 160:
			case 170:
				icon_code = 104;
				break;
			case 110:
			case 111:
				icon_code = 110;
				break;
			case 112:
			case 113:
			case 114:
			case 118:
			case 122:
			case 126:
			case 127:
			case 128:
			case 129:
				icon_code = 112;
				break;
			case 119:
			case 125:
				icon_code = 119;
				break;
			case 115:
			case 116:
			case 117:
			case 181:
				icon_code = 115;
				break;
			case 200:
			case 209:
			case 231:
				icon_code = 200;
				break;
			case 201:
			case 223:
				icon_code = 201;
				break;
			case 202:
			case 203:
			case 206:
			case 207:
			case 220:
			case 221:
			case 240:
				icon_code = 202;
				break;
			case 208:
				icon_code = 208;
				break;
			case 204:
			case 205:
			case 250:
			case 260:
			case 270:
				icon_code = 204;
				break;
			case 210:
			case 211:
				icon_code = 210;
				break;
			case 212:
			case 213:
			case 214:
			case 218:
			case 222:
			case 224:
			case 225:
			case 226:
			case 227:
				icon_code = 212;
				break;
			case 219:
				icon_code = 219;
				break;
			case 215:
			case 216:
			case 217:
			case 228:
			case 229:
			case 230:
			case 281:
				icon_code = 215;
				break;
			case 300:
			case 304:
			case 306:
			case 328:
			case 329:
			case 350:
			case 308:
				icon_code = 300;
				break;
			case 301:
				icon_code = 301;
				break;
			case 302:
				icon_code = 302;
				break;
			case 303:
			case 309:
			case 322:
				icon_code = 303;
				break;
			case 311:
			case 316:
			case 320:
			case 323:
			case 324:
			case 325:
				icon_code = 311;
				break;
			case 313:
			case 317:
			case 321:
				icon_code = 313;
				break;
			case 314:
			case 315:
			case 326:
			case 327:
				icon_code = 314;
				break;
			case 400:
			case 405:
			case 425:
			case 426:
			case 427:
			case 450:
			case 340:
			case 406:
			case 407:
				icon_code = 400;
				break;
			case 401:
				icon_code = 401;
				break;
			case 402:
				icon_code = 402;
				break;
			case 403:
			case 409:
				icon_code = 403;
				break;
			case 411:
			case 420:
			case 361:
				icon_code = 411;
				break;
			case 413:
			case 421:
			case 371:
				icon_code = 413;
				break;
			case 414:
			case 422:
			case 423:
			case 424:
				icon_code = 414;
				break;
			default:
				icon_code = 100;
				break;
			}
			icon += icon_code + ".jpg";
			return icon;
		}

		function getAnnouncer(code, day) {
			var anon = "";
			var weather = "hare";
			switch ((day + "")) {
			case "1":
			case "2":
				anon = "kawada";
				break;
			case "3":
			case "4":
				anon = "yoshida";
				break;
			case "5":
				anon = "hayashi";
				break;
			case "0":
			case "6":
				anon = "kotani";
				break;
			default:
				anon = "kawada";
				break;
			}
			if (code > 99 && code < 200) weather = "hare";
			if (code > 199 && code < 300) weather = "kumori";
			if (code > 299 && code < 400) weather = "ame";
			if (code > 399 && code < 500) weather = "yuki";
			return "images/" + anon + "_" + weather + ".jpg";
		}

		function getTemp(options, date) {
			var h = date.getHours();
			var temp_max;
			var temp_min;
			var tdmax = options.today_temp_max;
			var tmmax = options.tomorrow_temp_max;
			var tmmin = options.tomorrow_temp_min;
			var d = "";
			if (tdmax == 999) tdmax = "-";
			if (tmmax == 999) tmmax = "-";
			if (tmmin == 999) tmmin = "-";
//----------------------------------------------------------------
//不要？
			if (h > 4 && h < 11) {
				temp_max = tdmax;
				temp_min = "-";
			} else if (h > 10 && h < 17) {
				temp_max = tdmax;
				temp_min = tmmin;
			} else {
				temp_max = tmmax;
				temp_min = tmmin;
			}
//----------------------------------------------------------------
			if (date.getHours() > 16 || date.getHours() < 5) {
				temp_max = tmmax;
				temp_min = tmmin;
			} else {
				temp_max = tdmax;
				temp_min = "-";
			}
			return {
				max: temp_max,
				min: temp_min
			};
		}

		function parseDate(value) {
			try {
				var y = value.substring(0, 4);
				var m = value.substring(4, 6) - 1;
				var d = value.substring(6, 8);
				var h = value.substring(8, 10);
				var mi = value.substring(10, 12);
				var s = value.substring(12, 14);
				var date = new Date(y, m, d, h, mi, s);
				var cdate = new Date();
				var dat = new Date((date.getTime() + settings.nine_hour_miliseconds));
				if (dat.getHours() > 16 || dat.getHours() < 5) {
					var dat = new Date((date.getTime() + (settings.nine_hour_miliseconds * 2)));
				} else {
					var dat = new Date((date.getTime() + settings.nine_hour_miliseconds));
				}
				return dat;
			} catch (e) {
				return null;
			}
		}

		function parseDate3(value) {
			try {
				var y = value.substring(0, 4);
				var m = value.substring(4, 6) - 1;
				var d = value.substring(6, 8);
				var h = value.substring(8, 10);
				var mi = value.substring(10, 12);
				var s = value.substring(12, 14);
				var date = new Date(y, m, d, h, mi, s);
				var cdate = new Date();
				var dat = new Date((date.getTime() + settings.nine_hour_miliseconds));
				return dat;
			} catch (e) {
				return null;
			}
		}

		function parseDate2(value) {
			try {
				var y = value.substring(0, 4);
				var m = value.substring(4, 6) - 1;
				var d = value.substring(6, 8);
				var h = value.substring(8, 10);
				var mi = value.substring(10, 12);
				var s = value.substring(12, 14);
				var date = new Date(y, m, d, h, mi, s);
				return date;
			} catch (e) {
				return null;
			}
		}

		function getArea() {
			var item;
			var code;
			var name;
			for (var i = 0; area_list.length > i; i++) {
				item = area_list[i];
//----------------------------------------------------------------
//【2011.08.04変更】
//----------------------------------------------------------------
				//code = item[3];
				//if (code == area_code) {
				code = item[5];							//アメダス地点番号を取得
				if (code == amedas_code) {	//amedas_codeと判定
//----------------------------------------------------------------
					name = item[1] + item[2];
					break;
				}
			}
			return {
				code: code,
				name: name
			};
		}

		function getYoho() {
			var item;
			var code;
			var date;
			var today_weather;
			var tomorrow_weather;
			var tomorrow_temp_min;
			var today_temp_max;
			var tomorrow_temp_max;
			for (var i = 0; yoho_list.length > i; i++) {
				item = yoho_list[i];
				code = item[0];
//----------------------------------------------------------------
//【2011.08.04変更】
//----------------------------------------------------------------
				//if (code == area_code) {
				
				if (code == amedas_code) {	//amedas_codeと判定
//----------------------------------------------------------------
					date = item[1];
					today_weather = item[2];
					tomorrow_weather = item[3];
//----------------------------------------------------------------
//【2011.08.04変更】
//----------------------------------------------------------------
					//tomorrow_temp_min = item[11];
					//today_temp_max = item[12];
					//tomorrow_temp_max = item[13];
					
					tomorrow_temp_min = item[19];		//明日の最低気温(新)
					today_temp_max = item[26];			//今日の最高気温(新)
					tomorrow_temp_max = item[27];		//明日の最高気温(新)
//----------------------------------------------------------------
				}
			}
			var result = {
				date: date,
				today_weather: today_weather,
				tomorrow_weather: tomorrow_weather,
				tomorrow_temp_min: tomorrow_temp_min,
				today_temp_max: today_temp_max,
				tomorrow_temp_max: tomorrow_temp_max
			}
			return result;
		}

		function onErrorCSV(error) {}

		function trace(value) {
			if (!isdebug) return;
			console.log(value)
		};
		main();
		return this
	};
})(jQuery);
