var headTop;
var browser = getBrowserName();
var bVer = getBrowserVersion();

function setMainmenu() {
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("header")) return false;
	if(!document.getElementById("contents")) return false;

	var posY = 0;
	var header;

	header = document.getElementById("header");
	header.style.position = "relative";
	headTop = header.style.top;

	contents = document.getElementById("contents");
	contents.style.top = -20 + "px";

	if(document.documentElement.scrollTop) {
		posY = document.documentElement.scrollTop;
	} else if(window.pageYOffset) {
		posY = window.pageYOffset;
	} else if(document.body.scrollTop) {
		posY = document.body.scrollTop;
	}

	if(posY + "px" == headTop) {
		header.style.overflow = "visible";
	}

	if(posY) {
		header.style.top = posY + "px";
	} else {
		header.style.top = 0 + "px";
	}

	setTimeout( function(){setMainmenu()},10 );
}

function moveMaimmenu() {
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("header")) return false;
	if(!document.getElementById("mainmenu")) return false;

	var header, mainmenu, intShow, intHide, overFlow;
	var menuTop = -199, slideSpeed = 11;

	header = document.getElementById("header");
	mainmenu = document.getElementById("mainmenu");

	mainmenu.style.top = -199 + "px";
	mainmenu.onmouseover = function() {
		clearInterval(intHide);
		intShow = setInterval(
			function() {
				if (menuTop < -11) {
					menuTop = menuTop + slideSpeed;
					mainmenu.style.top = menuTop + "px";
				}
			}
		,10);
	};

	mainmenu.onmouseout = function() {
		clearInterval(intShow);
		intHide = setInterval(
			function() {
				if (menuTop > -199) {
					menuTop = menuTop - slideSpeed;
					mainmenu.style.top = menuTop + "px";
				}
			}
		,10);
	};
}

function setBottomImg() {
	if(browser == "Explorer" && bVer < 7) {
	if(!document.getElementById) return false;
	if(!document.getElementById("bottom_img_right")) return false;
	if(!document.getElementById("bottom_img_left")) return false;

	var imgR = document.getElementById("bottom_img_right");
	var imgL = document.getElementById("bottom_img_left");

	imgR.style.position = "absolute";
	imgR.style.top = 0 + "px";
	imgR.style.right = 0 + "px";

	imgL.style.position = "absolute";
	imgL.style.top = 0 + "px";
	imgL.style.left = 0 + "px";
	}
}

function moveBottomImg() {
	if(browser == "Explorer" && bVer < 7) {
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("bottom_img_right")) return false;
	if(!document.getElementById("bottom_img_left")) return false;

	var posY, posX, windowH, windowX, imgR, imgL, footer;

	windowH = getWindowHeight();
	windowX = getWindowWidth();

	imgR = document.getElementById("bottom_img_right");
	imgL = document.getElementById("bottom_img_left");

	if(document.documentElement.scrollTop) {
		posY = document.documentElement.scrollTop;
	} else if(window.pageYOffset) {
		posY = window.pageYOffset;
	} else if(document.body.scrollTop) {
		posY = document.body.scrollTop;
	}

	if(posY) {
		imgR.style.top = posY + windowH - 126 + "px";
		imgL.style.top = posY + windowH - 126 + "px";
	} else {
		imgR.style.top = windowH - 126 + "px";
		imgL.style.top = windowH - 126 + "px";
	}

	if(document.documentElement.scrollLeft) {
		posX = document.documentElement.scrollLeft;
	} else if(window.pageXOffset) {
		posX = window.pageXOffset;
	} else if(document.body.scrollLeft) {
		posX = document.body.scrollLeft;
	}

		if(posX) {
			imgR.style.right = - posX + "px";
			imgL.style.left = - posX + "px";
		} else {
			if(windowX > 920) {
				imgR.style.left = windowX - 690 + "px";
				imgL.style.left = 0 + "px";
			} else {
				imgR.style.left = 220 + "px";
				imgL.style.left = 0 + "px";
			}
		}

	setTimeout(function(){moveBottomImg()},10);
	}
}

	var fallarea, fallsrc, imgType, fallno, hidetime, fallHeight, fallWidth, fallimg, imgN, dx, fallX, fallY, am, moveX, moveY, falltimer;

	fallsrc = "img/fall/sakura";
	imgType = ".png";
	fallno = 20;
	hidetime = 3;
	fallHeight = getWindowHeight();
	fallWidth = getWindowWidth();

	fallimg = new Array();
	imgN = new Array();
	dx = new Array();
	fallX = new Array();
	fallY = new Array();
	am = new Array();
	moveX = new Array();
	moveY = new Array();

function setFall() {
	if(!document.getElementById) return false;
	if(!document.getElementById("all")) return false;

	fallarea = document.getElementById("all");

	for(var i = 0; i < fallno; ++i) {
		imgN[i] = Math.round(Math.random() * 10);

		dx[i] = 0;
		fallX[i] = Math.random() * (fallWidth - 100);
		fallY[i] = Math.random() * fallHeight;
		am[i] = Math.random() * 28;
		moveX[i] = 0.04 + Math.random() / 10;
		moveY[i] = 2 + Math.random();

		fallimg[i] = document.createElement("img");

	if(browser == "Explorer" && bVer < 7) {
		fallimg[i].src = "img/fall/blank.gif";
		fallimg[i].style.filter = 'progid:' + 'DXImageTransform.Microsoft.AlphaImageLoader' + '(src="' + fallsrc + imgN[i] + imgType + '",sizingMethod="image")';
	} else {
		fallimg[i].setAttribute("src", fallsrc + imgN[i] + imgType);
	}
		fallimg[i].setAttribute("id", "fall" + i);
		fallimg[i].setAttribute("class", "fall");
		fallimg[i].style.position = "absolute";
		fallimg[i].style.top = 0 + "px";
		fallimg[i].style.visibility = "visible";
		fallimg[i].style.zIndex = i;
		fallarea.appendChild(fallimg[i]);
	}
}

function moveFall() {
	if(!document.getElementById) return false;

	fallHeight = getWindowHeight();
	fallWidth = getWindowWidth();

	for(var i = 0; i < fallno; ++i) {
		fallY[i] += moveY[i];
		if (fallY[i] > fallHeight - 50) {
			fallX[i] = Math.random() * (fallWidth - am[i] - 56);
			fallY[i] = 0;
			moveX[i] = 0.04 + Math.random() / 10;
			moveY[i] = 2 + Math.random();
		}
			dx[i] += moveX[i];
			document.getElementById("fall" + i).style.top=fallY[i]+"px";
			document.getElementById("fall" + i).style.left=fallX[i] + am[i] * Math.sin(dx[i])+"px";
	}
	setTimeout(function(){moveFall()}, 15);
}

var scrollTimer;
var restScroll= 0;
var scrollTarget;
var scrollY = 0;

function setScroll() {
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("pagenavi")) return false;

	var pagenavi = document.getElementById("pagenavi");
	var naviA = pagenavi.getElementsByTagName("a");

	for(var i = 0; i < naviA.length; i++) {
		var href = naviA[i].getAttribute("href");
		var elem_id = href.split("#");
		naviA[i].removeAttribute("href");
		naviA[i].setAttribute("target",elem_id[1]);

		naviA[i].onclick = function() {
			scrollTarget = this.getAttribute("target");
			pageScroll();
		}
	}

	if(document.getElementById("categorynavi")) {
		if(!document.images) return false;

		var bg01 = new Image();
		var bg02 = new Image();
		bg01.src = "img/bg/menu_bg_01.png";
		bg02.src = "img/bg/menu_bg_02.png";

		var categorynavi = document.getElementById("categorynavi");
		var naviB = categorynavi.getElementsByTagName("a");

		for(var j = 0; j < naviB.length; j++) {
			href = naviB[j].getAttribute("href");
			elem_id = href.split("#");
			naviB[j].removeAttribute("href");
			naviB[j].setAttribute("target",elem_id[1]);

			naviB[j].onclick = function() {
				scrollTarget = this.getAttribute("target");
				pageScroll();
			}

			if(browser == "Explorer" && bVer <= 7) {
				naviB[j].onmouseover = function() {
					this.style.backgroundColor = "#eee";
				}

				naviB[j].onmouseout = function() {
					this.style.backgroundColor = "";
				}
			}
		}
	}
}

function pageScroll() {
	var moveValue = 0;
	var posY = 0;

	if(document.documentElement.scrollTop) {
		posY = document.documentElement.scrollTop;
	} else if(window.pageYOffset) {
		posY = window.pageYOffset;
	} else if(document.body.scrollTop) {
		posY = document.body.scrollTop;
	}

	var elem_move = document.getElementById(scrollTarget);
	var moveY = elem_move.offsetTop;
	restScroll = moveY - posY - 20;

	if(Math.abs(restScroll) > 80){
		moveValue = (restScroll > 0) ? 40 : -40;
	}else{
		moveValue = Math.round(restScroll / 4);
	}

	parent.scrollBy(0,moveValue);

	if(moveValue == 0 || posY == scrollY && posY > 0){
		restScroll = 0;
		scrollY = 0;
	} else {
		scrollY = posY;
		setTimeout(function(){pageScroll()}, 10);
	}

}

function pageNaviLink() {
	if(browser == "Explorer" && bVer <= 7) {
		if(!document.getElementsByTagName) return false;
		if(!document.getElementById) return false;
		if(!document.getElementById("pagenavi")) return false;

		var pagenavi = document.getElementById("pagenavi");
		var naviA = pagenavi.getElementsByTagName("a");

		for(var i = 0; i < naviA.length; i++) {
			naviA[i].onmouseover = function() {
				this.style.color = "yellow";
				this.style.textDecoration = "underline";
			}

			naviA[i].onmouseout = function() {
				this.style.color = "white";
				this.style.textDecoration = "none";
			}
		}
	}
}

function linkNavi() {
	if(browser == "Explorer" && bVer <= 7) {
		if(!document.getElementById) return false;
		if(!document.getElementById("linknavi")) return false;
		if(!document.images) return false;

		var bg01 = new Image();
		var bg02 = new Image();
		bg01.src = "img/bg/menu_bg_01.png";
		bg02.src = "img/bg/menu_bg_02.png";

		var linknavi = document.getElementById("linknavi");
		var links = linknavi.getElementsByTagName("a");

		for(var i = 0; i < links.length; i++) {
			links[i].onmouseover = function() {
				this.style.backgroundColor = "#eee";
			}

			links[i].onmouseout = function() {
				this.style.backgroundColor = "";
			}
		}
	}
}

function preLoad() {
	if(!document.images) return false;

		var menuBg01 = new Image();
		var menuBg02 = new Image();

		menuBg01.src = "img/mainmenu_bg_01.png";
		menuBg02.src = "img/mainmenu_bg_02.png";
}


addLoadEvent(moveMaimmenu);
addLoadEvent(setBottomImg);
addLoadEvent(moveBottomImg);
addLoadEvent(setScroll);
addLoadEvent(pageNaviLink);
addLoadEvent(linkNavi);
addLoadEvent(preLoad);
