var preloadFlag	= false;
var orverimg	= [];

var opacityNum	= 0;
var timer		= 0;


/* Header menu */
var imgroot		= "images/menu/";
var bnames		= ["home","restaurant","cafe","blog","coachandfour"];
var bfimgs		= ["home-f","restaurant-f","cafe-f","blog-f","coachandfour-f"];
var btimgs		= ["home-t","restaurant-t","cafe-t","blog-t","coachandfour-t"];
var now			= bnames.length + 1;
var fext		= ".gif";

function newImage (arg) {
	var rslt;
	if (document.images) {
		rslt		= new Image();
		rslt.src	= arg;
		return rslt;
	} else {
		return false;
	}
}

function preloadImages () {
	if (document.images) {
		var i = 0;
		var j = 0;
		for(i=0; i<btimgs.length; i++) {
			orverimg[i]		= newImage(imgroot + btimgs[i] + fext);
		}
		preloadFlag = true;
	}
}

function changeImages(id, img) {
	if (document.images && (preloadFlag == true)) {
		document.getElementById(id).src = imgroot + img + fext;
	}
}

/* Header menu */
function mover(num) {
	num = eval(num);
	changeImages(bnames[num], btimgs[num]);
	return true;
}

function mout(num) {
	num = eval(num);
	if (num != now) {
		changeImages(bnames[num], bfimgs[num]);
	}
	return true;
}

/*新規ウィンドウ*/
function winopen(url,title,w,h) {
	if ((w == 0) && (h == 0)) {
		window.open(url, title);
	} else {
		window.open(url, title, "width=" + w + ", height=" + h + ", scrollbars=yes, resizable=yes");
	}
}

/* IEを判別 */
function getBrowser () {
	var str	= "";
	if (navigator.userAgent.indexOf("MSIE", 0) != -1) {
		str	= "MSIE";
		if (navigator.userAgent.indexOf("MSIE 5", 0) != -1) {
			str	+= "5";
		} else if (navigator.userAgent.indexOf("MSIE 6", 0) != -1) {
			str	+= "6";
		} else if (navigator.userAgent.indexOf("MSIE 7", 0) != -1) {
			str	+= "7";
		}
	} else if (navigator.userAgent.indexOf("Safari", 0) != -1) {
		str	= "Safari";
	} else {
		str	= "Other";
	}
	return str;
}

/* 透明度を設定 */
function setopacity (id, val) {
	document.getElementById(id).style.filter		= "alpha(opacity=" + val + ")";
	document.getElementById(id).style.Opacity	= val;
	document.getElementById(id).style.opacity	= val;
}

/* フェードイン処理 */
function startscr (id) {
	var add	= 0;
	var max	= 0;
	if (getBrowser().indexOf("MSIE") != -1) {
	//if (getBrowser() == "MSIE") {
		add	= 10;
		max	= 100;
	} else {
		add	= 0.1;
		max	= 1.0;
	}
	opacityNum	+= add;
	setopacity(id, opacityNum);
	if (opacityNum >= max) {
		clearInterval(timer);
	}
}

/* フロートウィンドウ */
function showFloatWin (id) {
	var sLeft	= 0;
	var sTop	= 0;
	var wWidth	= 0;
	var wHeight	= 0;
	var wLeft	= 0;
	var wTop	= 0;
	var dWidth	= 652;
	var dHeight	= 553;
	if ((document.getElementById(id)) && (fWinExist == 0)) {
		if ((getBrowser().indexOf("MSIE5") != -1) || (getBrowser().indexOf("MSIE6") != -1) || (getBrowser().indexOf("Safari") != -1)) {
			sLeft	= document.body.scrollLeft;
			sTop	= document.body.scrollTop;
		} else {
			sLeft	= document.documentElement.scrollLeft;
			sTop	= document.documentElement.scrollTop;
		}
		wWidth	= window.innerWidth || document.body.clientWidth;
		wHeight	= window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
		wLeft	= Math.floor(((wWidth - dWidth) / 2) + sLeft);
		wTop	= Math.floor(((wHeight - dHeight) / 2) + sTop);
		fWinExist	= 1;
		document.getElementById(id).style.display	= "block";
		document.getElementById(id).style.left		= wLeft + "px";
		document.getElementById(id).style.top		= wTop + "px";
		if (getBrowser().indexOf("MSIE") == -1) {
			opacityNum	= 0;
			setopacity(id, opacityNum);
			timer	= setInterval("startscr('" + id + "')", 30);
		}
	}
}
function hideFloatWin (id) {
	if (document.getElementById(id)) {
		document.getElementById(id).style.left		= "0px";
		document.getElementById(id).style.top		= "0px";
		document.getElementById(id).style.display	= "none";
		fWinExist	= 0;
	}
}

