﻿//==========================
//　座標指定のためのクラス
//==========================
function Rect(_x, _y, _width, _height){
	this.x=_x;
	this.y=_y;
	this.width=_width;
	this.height=_height;
}

//====================================
//　画像をスケーリングした座標を返す
//====================================
function ScaleRect(_data, _x, _y, _width, _height, _noimg_w, _noimg_h){
	// 縮尺取得
	var scale_w=(_width!=undefined)?_width/_data.width:1;
	var scale_h=(_height!=undefined)?_height/_data.height:1;

	// 画像サイズを取得
	var img=new Image();
	img.src=_data.img;
//	var img_w=img.width;
//	var img_h=img.height;
	var img_w=(img.width!=0)?img.width:_noimg_w;
	var img_h=(img.height!=0)?img.height:_noimg_h;
	
	// 縮尺によるサイズと開始位置の補正
	this.out_w=Math.floor(img_w*scale_w);
	this.out_h=Math.floor(img_h*scale_h);
	this.left=Math.floor(_data.x*scale_w);
	this.top=Math.floor(_data.y*scale_h);

	// 座標の確定
	this.x=(_x!=undefined)?_x-this.left:-_data.left;
	this.y=(_y!=undefined)?_y-this.top:-_data.top;
	this.right=(_width!=undefined)?this.left+_width:this.left+_data.width;
	this.bottom=(_height!=undefined)?this.top+_height:this.top+_data.height;
}

//================================
//　予報画像を表示するための情報
//================================
function YohoData(_area){
	var before="http://www.jma.go.jp/jp/yoho/images/g0/";
	var after="_telop_today.png";
	var area;
	var rect;
	switch(_area){
		// 稚内
		case 47401:
			area=201;
			rect=new Rect(140, 66, 250, 176);
			break;
		// 旭川
		case 47407:
			area=201;
			rect=new Rect(177, 136, 247, 620);
			break;
		// 網走
		case 47409:
			area=202;
			rect=new Rect(0, 123, 247, 160);
			break;
		// 帯広
		case 47417:
			area=202;
			rect=new Rect(4, 250, 146, 194);
			break;
		// 釧路
		case 47418:
			area=202;
			rect=new Rect(91, 242, 156, 124);
			break;
		// 根室
		case 47420:
			area=202;
			rect=new Rect(161, 168, 169, 157);
			break;
		// 室蘭
		case 47423:
			area=203;
			rect=new Rect(163, 238, 212, 116);
			break;
		// 浦河
		case 47426:
			area=203;
			rect=new Rect(315, 235, 168, 179);
			break;
		// 函館
		case 47430:
			area=203;
			rect=new Rect(96, 289, 156, 201);
			break;
	}
	this.img=before+area+after;
	this.x=rect.x;
	this.y=rect.y;
	this.width=rect.width;
	this.height=rect.height;
}

//======================
//　予報画像を表示する
//======================
function yoho(_area, _x, _y, _width, _height){
	var data=new YohoData(_area);
	var rect=new ScaleRect(data, _x, _y, _width, _height, 550, 455);
	var out='<img src="'+data.img+'" style="position: absolute; clip: rect('+rect.top+'px '+rect.right+'px '+rect.bottom+'px '+rect.left+'px); overflow: hidden; top: '+rect.y+'px; left: '+rect.x+'px;" width="'+rect.out_w+'" height="'+rect.out_h+'">';
	document.write(out);
//alert(out);
}

//======================================
//　予報画像の日時を表示するための情報
//======================================
function YohoTimeData(_area){
	var before="http://www.jma.go.jp/jp/yoho/images/g0/";
	var after="_telop_today.png";
	var area;
	var rect;
	switch(_area){
		// 稚内
		case 47401:
		// 旭川
		case 47407:
			area=201;
			break;
		// 網走
		case 47409:
		// 帯広
		case 47417:
		// 釧路
		case 47418:
		// 根室
		case 47420:
			area=202;
			break;
		// 室蘭
		case 47423:
		// 浦河
		case 47426:
		// 函館
		case 47430:
			area=203;
			break;
	}
	rect=new Rect(3, 2, 197, 20);
	this.img=before+area+after;
	this.x=rect.x;
	this.y=rect.y;
	this.width=rect.width;
	this.height=rect.height;
}

//============================
//　予報画像の日時を表示する
//============================
function yohotime(_area, _x, _y, _width, _height){
	var data=new YohoTimeData(_area);
	var rect=new ScaleRect(data, _x, _y, _width, _height, 550, 455);
	var out='<img src="'+data.img+'" style="position: absolute; clip: rect('+rect.top+'px '+rect.right+'px '+rect.bottom+'px '+rect.left+'px); overflow: hidden; top: '+rect.y+'px; left: '+rect.x+'px;" width="'+rect.out_w+'" height="'+rect.out_h+'">';
	document.write(out);
}

//======================================
//　注意報警報画像を表示するための情報
//======================================
function WarningData(_area){
	var before="http://www.jma.go.jp/jp/warn/imgs/";
	var after="/99.png";
	var area;
	switch(_area){
		// 稚内
		case 47401:
			area=201;
			rect=new Rect(140, 66, 250, 176);
			break;
		// 旭川
		case 47407:
			area=201;
			rect=new Rect(177, 136, 247, 620);
			break;
		// 網走
		case 47409:
			area=202;
			rect=new Rect(0, 123, 247, 160);
			break;
		// 帯広
		case 47417:
			area=202;
			rect=new Rect(4, 250, 146, 194);
			break;
		// 釧路
		case 47418:
			area=202;
			rect=new Rect(91, 242, 156, 124);
			break;
		// 根室
		case 47420:
			area=202;
			rect=new Rect(161, 168, 169, 157);
			break;
		// 室蘭
		case 47423:
			area=203;
			rect=new Rect(163, 238, 212, 116);
			break;
		// 浦河
		case 47426:
			area=203;
			rect=new Rect(315, 235, 168, 179);
			break;
		// 函館
		case 47430:
			area=203;
			rect=new Rect(96, 289, 156, 201);
			break;
	}
	this.img=before+area+after;
	this.x=rect.x;
	this.y=rect.y;
	this.width=rect.width;
	this.height=rect.height;
}

//============================
//　注意報警報画像を表示する
//============================
function warning(_area, _x, _y, _width, _height){
	var data=new WarningData(_area);
	var rect=new ScaleRect(data, _x, _y, _width, _height, 550, 455);
	var out='<img src="'+data.img+'" style="position: absolute; clip: rect('+rect.top+'px '+rect.right+'px '+rect.bottom+'px '+rect.left+'px); overflow: hidden; top: '+rect.y+'px; left: '+rect.x+'px;" width="'+rect.out_w+'" height="'+rect.out_h+'">';
	document.write(out);
}

//============================================
//　注意報警報画像の日時を表示するための情報
//============================================
function WarningTimeData(_area){
	var before="http://www.jma.go.jp/jp/warn/imgs/";
	var after="/99.png";
	var area;
	switch(_area){
		// 稚内
		case 47401:
		// 旭川
		case 47407:
			area=201;
			break;
		// 網走
		case 47409:
		// 帯広
		case 47417:
		// 釧路
		case 47418:
		// 根室
		case 47420:
			area=202;
			break;
		// 室蘭
		case 47423:
		// 浦河
		case 47426:
		// 函館
		case 47430:
			area=203;
			break;
	}
	rect=new Rect(5, 3, 226, 17);
	this.img=before+area+after;
	this.x=rect.x;
	this.y=rect.y;
	this.width=rect.width;
	this.height=rect.height;
}

//==================================
//　注意報警報画像の日時を表示する
//==================================
function warningtime(_area, _x, _y, _width, _height){
	var data=new WarningTimeData(_area);
	var rect=new ScaleRect(data, _x, _y, _width, _height, 550, 455);
	var out='<img src="'+data.img+'" style="position: absolute; clip: rect('+rect.top+'px '+rect.right+'px '+rect.bottom+'px '+rect.left+'px); overflow: hidden; top: '+rect.y+'px; left: '+rect.x+'px;" width="'+rect.out_w+'" height="'+rect.out_h+'">';
	document.write(out);
}

//======================================================
//　レーダー・降水ナウキャスト画像を表示するための情報
//======================================================
function RadnowData(_area){
	// 現在日時から画像ファイル名を取得
	var now=new Date();
	var year=now.getFullYear();
	var month=now.getMonth();
	var date=now.getDate();
	var hour=now.getHours();
	var minute=now.getMinutes();
	// データは1分20秒くらいで入るようなので、2分戻す
	var dataTime=new Date(year, month, date, hour, minute-2,0);
	year=dataTime.getFullYear();
	month=dataTime.getMonth()+1;
	date=dataTime.getDate();
	hour=dataTime.getHours();
	minute=dataTime.getMinutes();
	month=(month<10)?"0"+month:month;
	date=(date<10)?"0"+date:date;
	hour=(hour<10)?"0"+hour:hour;
	minute=minute-(minute%5);
	minute=(minute<10)?"0"+minute:minute;
	var fName=""+year+month+date+hour+minute+"-00.png";

	var before="http://www.jma.go.jp/jp/radnowc/imgs/radar/";
	var after="/"+fName;
	var area;
	switch(_area){
		// 稚内
		case 47401:
			area=201;
			rect=new Rect(124, 27, 288, 219);
			break;
		// 旭川
		case 47407:
			area=201;
			rect=new Rect(130, 90, 288, 242);
			break;
		// 網走
		case 47409:
			area=202;
			rect=new Rect(89, 59, 273, 242);
			break;
		// 帯広
		case 47417:
			area=202;
			rect=new Rect(54, 151, 275, 244);
			break;
		// 釧路
		case 47418:
			area=202;
			rect=new Rect(139, 128, 273, 240);
			break;
		// 根室
		case 47420:
			area=202;
			rect=new Rect(180, 83, 274, 242);
			break;
		// 室蘭
		case 47423:
			area=203;
			rect=new Rect(151, 112, 278, 221);
			break;
		// 浦河
		case 47426:
			area=203;
			rect=new Rect(213, 123, 279, 221);
			break;
		// 函館
		case 47430:
			area=203;
			rect=new Rect(68, 159, 278, 221);
			break;
	}
	this.img=before+area+after;
	this.x=rect.x;
	this.y=rect.y;
	this.width=rect.width;
	this.height=rect.height;
}

//============================================
//　レーダー・降水ナウキャスト画像を表示する
//============================================
function radnow(_area, _x, _y, _width, _height){
	var data=new RadnowData(_area);
	var rect=new ScaleRect(data, _x, _y, _width, _height, 550, 455);
	var out='<img src="'+data.img+'" style="position: absolute; clip: rect('+rect.top+'px '+rect.right+'px '+rect.bottom+'px '+rect.left+'px); overflow: hidden; top: '+rect.y+'px; left: '+rect.x+'px;" width="'+rect.out_w+'" height="'+rect.out_h+'">';
	document.write(out);
}

//============================================================
//　レーダー・降水ナウキャスト画像の日時を表示するための情報
//============================================================
function RadnowTimeData(_area){
	// 現在日時から画像ファイル名を取得
	var now=new Date();
	var year=now.getFullYear();
	var month=now.getMonth();
	var date=now.getDate();
	var hour=now.getHours();
	var minute=now.getMinutes();
	// データは1分20秒くらいで入るようなので、2分戻す
	var dataTime=new Date(year, month, date, hour, minute-2,0);
	year=dataTime.getFullYear();
	month=dataTime.getMonth()+1;
	date=dataTime.getDate();
	hour=dataTime.getHours();
	minute=dataTime.getMinutes();
	month=(month<10)?"0"+month:month;
	date=(date<10)?"0"+date:date;
	hour=(hour<10)?"0"+hour:hour;
	minute=minute-(minute%5);
	minute=(minute<10)?"0"+minute:minute;
	var fName=""+year+month+date+hour+minute+"-00.png";

	var before="http://www.jma.go.jp/jp/radnowc/imgs/radar/";
	var after="/"+fName;
	var area;
	switch(_area){
		// 稚内
		case 47401:
		// 旭川
		case 47407:
			area=201;
			break;
		// 網走
		case 47409:
		// 帯広
		case 47417:
		// 釧路
		case 47418:
		// 根室
		case 47420:
			area=202;
			break;
		// 室蘭
		case 47423:
		// 浦河
		case 47426:
		// 函館
		case 47430:
			area=203;
			break;
	}
	rect=new Rect(3, 3, 181, 19);
	this.img=before+area+after;
	this.x=rect.x;
	this.y=rect.y;
	this.width=rect.width;
	this.height=rect.height;
}

//==================================================
//　レーダー・降水ナウキャスト画像の日時を表示する
//==================================================
function radnowtime(_area, _x, _y, _width, _height){
	var data=new RadnowTimeData(_area);
	var rect=new ScaleRect(data, _x, _y, _width, _height, 550, 455);
	var out='<img src="'+data.img+'" style="position: absolute; clip: rect('+rect.top+'px '+rect.right+'px '+rect.bottom+'px '+rect.left+'px); overflow: hidden; top: '+rect.y+'px; left: '+rect.x+'px;" width="'+rect.out_w+'" height="'+rect.out_h+'">';
	document.write(out);
}

//================================
//　「今日は何の日」の見出し表示
//================================
function jumptoday(_mes){
	// 現在日時からリンク先を取得
	var now=new Date();
	var year=now.getFullYear();
	var month=now.getMonth()+1;
	var date=now.getDate();
	month=(month<10)?"0"+month:month;
	date=(date<10)?"0"+date:date;
	// メッセージ生成
	var mes="今日の「気象カレンダー」へ";
	if(_mes!=undefined){
		mes=_mes.replace("yyyy", year);
		mes=mes.replace("mm", month);
		mes=mes.replace("dd", date);
	}
	var out='<a href="http://www.jma-net.go.jp/sapporo/today/'+month+date+'.html">'+mes+'</a>';
	document.write(out);
}

//================================
//　「北海道の四季」の見出し表示
//================================
function jumptoseason(){
	// 現在日時からリンク先を取得
	var now=new Date();
	var year=now.getFullYear();
	var month=now.getMonth()+1;
	var date=now.getDate();
	// メッセージ生成
	var mes="北海道の四季（"+month+"月）へ";
	var out='<a href="http://www.jma-net.go.jp/sapporo/season/season'+month+'.html">'+mes+'</a>';
	document.write(out);
}

