﻿// 共通タイマー
var timerID;
var timer = 500;

// タイマー待ち
function disp(i, j) {
	timerID = setTimeout('changeImgTxt('+i+', '+j+')', timer);
}

// 画像テキスト書き換え
function changeImgTxt(i, j) {
	target = document.getElementById('img_'+i);
	if (movimg[j]) {
		target.src = movimg[j].src;
		var getimage  = getActualDimension(target);
		target.width  = getimage.width;
		target.height = getimage.height;
	}
	if (document.getElementById){
		if (msg[j]) document.getElementById('txt_'+i).innerHTML = msg[j];
	}
	cnt[i] = j;
}

// タイマー待ち
function clea() {
	clearTimeout(timerID);
}

// 画像サイズの取得
function getActualDimension(image) {
	var run, mem, w, h, key = "actual";
	// for Firefox, Safari, Google Chrome
	if ("naturalWidth" in image) {
		return { width: image.naturalWidth, height: image.naturalHeight };
	}
	if ("src" in image) { // HTMLImageElement
		if (image[key] && image[key].src === image.src) {
			return image[key];
		}
		if (document.uniqueID) { // for IE
			run = image.runtimeStyle;
			mem = { w: run.width, h: run.height }; // keep runtimeStyle
			run.width  = "auto"; // override
			run.height = "auto";
			w = image.width;
			h = image.height;
			run.width  = mem.w; // restore
			run.height = mem.h;
		} else { // for Opera and Other
			mem = { w: image.width, h: image.height }; // keep current style
			image.removeAttribute("width");
			image.removeAttribute("height");
			w = image.width;
			h = image.height;
			image.width  = mem.w; // restore
			image.height = mem.h;
		}
		return image[key] = { width: w, height: h, src: image.src }; // bond
	}
	// HTMLCanvasElement
	return { width: image.width, height: image.height };
}

