//=========================================================
//    ひまわり画像アニメーション
//=========================================================

var	number	= 24;		// 画像数
var	delay	= 500;		// 表示間隔 msec
var	frame	= 0;		// ファーストフレーム
var timer	= null;
var images	= new Array(number);
var dir		= "/imagefiles/himawari/";
for (var i = 0; i < number; i++) {
	images[i] = new Image();
	images[i].src = dir + "GMS-5-H-" + i + ".jpg";
}

function animate() {
  if (frame == 0) frame = number -1;
	timer = setInterval("nextFrame()", delay);
}

function nextFrame() {
	if (frame > 0)
		--frame
	else {
		frame = number - 1;
		if (timer != null) {
			clearInterval(timer);
			timer=null;
		}
	}
	document.himawari.src = dir + "GMS-5-H-" + frame + ".jpg";
}

function preFrame() {
	if (frame < number - 1)
		++frame
	else
		frame = 0;
	if (timer != null) {
		clearInterval(timer);
		timer=null;
	}
	document.himawari.src = dir + "GMS-5-H-" + frame + ".jpg";
}

//=========================================================

function movie(alt) {

	if (alt == "pre") {
		if (timer != null) clearInterval(timer); 
		timer = null;
		preFrame();
	} else if (alt == "stop") {
		if (timer != null) clearInterval(timer); 
		timer = null;
	} else if (alt == "next") {
		if (timer != null) clearInterval(timer); 
		timer = null;
		nextFrame();
	} else if (alt == "play") {
		if (timer == null) animate();
	}
}

//=========================================================

function cimg (id, f) {
	
	elm = document.getElementById(id);
	elm.src = f;

}

//=========================================================
// タブメニュー

var Item = ['00','01','02','03','04','05'];
var CloudsItem = "00";

function SelectItem(a) {

	if (a == "")	a = CloudsItem;

	for (var i = 0; i < Item.length; i ++) {
		var elm = document.getElementById("Item"+Item[i]);
		if (elm) elm.style.display = (Item[i] == a)?"block":"none";
	}

	CloudsItem = a;
	setTab("ItemTabGroup", a);
	movie("stop"); 

	if(typeof selectKind == "function")
	{
		selectKind(active.kind['w'],'w');
		selectKind(active.kind['h'],'h');
	}
	if(typeof $.cookie == "function")
	{
		$.cookie('cloud_item',CloudsItem,{expires: 365, path: '/' });
	}
}

$(document).ready(function(){

	var argv = getUrlVars(); 

	if (argv['menu']) {
		var a = argv['menu'];
		SelectItem(a);
	} else {
		var a = $.cookie('cloud_item');
		if(a != null)
		{
			SelectItem(a);
		}
	}
});

//=========================================================

function printAll()

{

	var	number2 = number;
	var	nowUrl = location.href;

	window.document.open();
	window.document.writeln("<HTML lang=\"ja-JP\">");
	window.document.writeln("<HEAD>");
	window.document.writeln("<SCRIPT Laguage=\"JavaScript\">");
	window.document.writeln("var count = 0;");
	window.document.writeln("if (navigator.appName.charAt(0) == \"N\")");
	window.document.writeln("	++count;");
	window.document.writeln("function backUrl()");
	window.document.writeln("{");
	window.document.writeln("if (count)");
//	window.document.writeln("	history.back();");	// 親Windowからcloseできない

	window.document.writeln("location.href = \"" + nowUrl + "\";");
	window.document.writeln("++count;");
	window.document.writeln("}");
	window.document.writeln("var spead = 300;")
	window.document.writeln("var msg = '印刷中です. しばらくお待ちください. ★★★印刷終了後自動的にアニメーションに戻ります.★★★  ';");
	window.document.writeln("function statusMsg()")
	window.document.writeln("{")
	window.document.writeln("setTimeout(\"statusMsg()\", spead);");
	window.document.writeln("msg = msg.substring(2, msg.length) + msg.substring(0, 2);");
	window.document.writeln("window.status = msg;");
	window.document.writeln("}");
	window.document.writeln("</SCRIPT></HEAD><BODY onFocus=\"backUrl()\" bgcolor=\"gray\">");
	window.document.writeln("");
	window.document.writeln("");
	window.document.writeln("");
	window.document.writeln("<CENTER>");

	var j = 0;

	for (var i = number2 - 1; i >= 0; i--) {
		var src = "<IMG SRC='/imagefiles/himawari/GMS-5-H-" + i + ".jpg' WIDTH=300 HEIGHT=300>";
		window.document.writeln(src);
		if (j++ % 2)
			window.document.writeln("<BR>");
	}
	window.document.writeln("</CENTER>");
	window.document.writeln("");
	window.document.writeln("");
	window.document.writeln("</BODY>");
	window.document.writeln("</HTML>");
	window.document.close();
	window.print();
	statusMsg();

}
