var dftWidth = 50;
var clx = cly = count = okver = 0;
var scrly = 0;
var aw = ah = dftWidth;
var ax = ay = bx = by = bw = bh = cx = cy = cw = ch = 0;
var blnk = 25;
var bpht = new Array();
bpht[0] = new Image();
bpht[0].src = "../img/nasi.gif";
bpht[1] = new Image();
var putdiv,ititle,notice,pmoji;

if(navigator.platform.substr(0,3) == "Mac"){
	if(ops.indexOf("Mac OS X") == -1){ okver++; }
	if(ops.indexOf("MSIE") != -1){ okver++; }
}
if(ops.indexOf("Opera") != -1){ okver++; }
if(ops.indexOf("MSIE") == -1){
	if(ops.indexOf("Netscape") == -1 && ops.indexOf("Firefox") == -1 && ops.indexOf("Safari") == -1){ okver++; }
	if(ops.indexOf("Netscape") != -1){
		if(ops.indexOf("Netscape/7") == -1){ okver++; }
	}
}else{
	if(navigator.appVersion.charAt(0) < 4){
		okver++;
	}else{
		var appv = navigator.appVersion;
		if(appv.indexOf("MSIE")){
			if(appv.charAt(appv.indexOf("MSIE") + 5) < 6){
				okver++;
			}
		}
	}
}

function sizChg(){
	if(bw >= aw){ putdiv.style.width = aw + "px"; }else{ putdiv.style.width = bw + "px"; }
	if(bx <= ax){ putdiv.style.left = ax + "px"; }else{ putdiv.style.left = bx + "px"; }
	if(bh >= ah){ putdiv.style.height = ah + "px"; }else{ putdiv.style.height = bh + "px"; }
	if(by <= ay){ putdiv.style.top = ay + "px"; }else{ putdiv.style.top = by + "px"; }
	aw += cw; ax -= cx; ah += ch; ay -= cy;
	if(bw < aw && bx > ax && bh < ah && by > ay){
		putdiv.style.width = bw + "px";
		putdiv.style.left = bx + "px";
		putdiv.style.height = bh + "px";
		putdiv.style.top = by + "px";
		ititle.style.width = (bw - 25) + "px";
		document.getElementById("imenu").style.display = "block";
		clearInterval(IntervarID);
		document.getElementById("picts").src = bpht[1].src;
		var text = document.createTextNode(pmoji);
		notice.appendChild(text);
		var brElem = document.createElement('br');
		notice.appendChild(brElem);
		var text = document.createTextNode("※元の表示に戻す場合は「×」ボタンをクリックして下さい。");
		notice.appendChild(text);
		notice.style.top = (by + bh + 2) + "px";
		notice.style.display = "block";
	}
}

function loads(){
	if(bpht[1].complete){
		clearInterval(IntervarID);
		loadok();
	}
	if(count == 25){
		clearInterval(IntervarID);
		alert("画像の読み込みに失敗しました。");
		return;
	}
	count++;
}

function hyouji(nmb,pname){
	if(okver != 0){
		location.href = "./img/m" + nmb + ".jpg"; return;
	}
	count = 0;
	bpht[1] = new Image();
	bpht[1].src = "./img/m" + nmb + ".jpg";
	pmoji = pname;
	IntervarID = setInterval('loads()',100);
}

function loadok(){
	if(!document.all){ scrly = pageYOffset; }
	ax = Math.floor((clx - aw)/2);
	bw = bpht[1].width + 30;
	bx = Math.floor((clx - bw)/2);
	cx = Math.ceil((ax - bx)/blnk);
	cw = Math.ceil((bw - aw)/blnk);

	bh = bpht[1].height + 50;
	by = scrly + 100;
	ay = Math.floor((bh - ah)/2) + by;
	cy = Math.ceil((ay - by)/blnk);
	ch = Math.ceil((bh - ah)/blnk);

	document.getElementById("blck").style.visibility = 'visible';
	putdiv.style.left = ax + "px";
	putdiv.style.top = ay + "px";
	putdiv.style.width = aw + "px";
	putdiv.style.height = ah + "px";
	putdiv.style.display = "block";
	IntervarID = setInterval('sizChg()',10);
}

function del(){
	aw = ah = dftWidth;
	document.getElementById("imenu").style.display = "none";
	document.getElementById("picts").src = bpht[0].src;
	del_child(notice);
	ititle.style.width = "1px";
	putdiv.style.display = "none";
	notice.style.display = "none";
	document.getElementById("blck").style.visibility = 'hidden';
	return;
}

function vewchg(){
	clx = window.innerWidth || document.body.clientWidth;
	cly = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	return;
}

function scr(){
	if(document.all){ scrly = document.documentElement.scrollTop || document.body.scrollTop; }
	else{ scrly = pageYOffset; }
	if(!scrly){ scrly = 0; }
}

function init(){
	vewchg();
	notice = document.getElementById('notice');
	putdiv = document.getElementById('phtdisp');
	ititle = document.getElementById('ititle');
	return;
}
function resiz(){
	vewchg();
	return;
}

function del_child(pObj){
	var child = pObj.childNodes;
	var length = child.length;
	for(var i = 0; i < length; i++) {
		pObj.removeChild(child[0]);
	}
	return;
}

window.onload = init;
window.onresize = resiz;
