/* ロールオーバー処理 */

function Btn(elm) {
	var me = this;
	this.elm = elm;
	this.over = function() { me.changeImage(true); };
	this.out = function() {	me.changeImage(false); };
	this.init();
}

var _Btn = Btn.prototype;

_Btn.init = function() {
	var me = this;
	var img_on = new Image();
	var img_str = this.elm.getAttribute("src");
	img_on.src = img_str.replace("_off", "_on");
	this.setEvent();
};


_Btn.doSelect = function() {
	this.deleteEvent();
	this.changeImage(true);
};


_Btn.setEvent = function() {
	try {
		this.elm.addEventListener("mouseover", this.over, false);
		this.elm.addEventListener("mouseout", this.out, false);
	} catch(e) {
		this.elm.attachEvent("onmouseover", this.over);
		this.elm.attachEvent("onmouseout", this.out);
	}
};


_Btn.deleteEvent = function() {
	try {
		this.elm.removeEventListener("mouseover", this.over, false);
		this.elm.removeEventListener("mouseout", this.out, false);
	} catch(e) {
		this.elm.detachEvent("onmouseover", this.over);
		this.elm.detachEvent("onmouseout", this.out);
	}
};


_Btn.changeImage = function(flag) {
	var img = this.elm.getAttribute("src");
	this.elm.setAttribute("src", (flag) ? img.replace("_off", "_on") : img.replace("_on", "_off"));
};


(function(func) {
	try {
		window.addEventListener("load", func, false);
	} catch(e) {
		window.attachEvent("onload", func);
	}
})(function() {
	var btnArray01 = document.getElementsByTagName("img");
	var btnArray02 = document.getElementsByTagName("input");
	for (var i = 0, ln = btnArray01.length; i < ln; i++) {
		if (btnArray01[i].getAttribute("src").indexOf("_off.") >= 0) new Btn(btnArray01[i]);
	}
	for (var i = 0, ln = btnArray02.length; i < ln; i++) {
		try{
			if (btnArray02[i].getAttribute("src").indexOf("_off.") >= 0) new Btn(btnArray02[i]);
		} catch(e){
		}
	}
	
	 if(navigator.userAgent.indexOf("MSIE 6.0")==-1) return;
	  var min_max_width = function(){
	    var w = document.body.clientWidth;
	    document.getElementById("wrapper").style.width = w < 1102? "1100px" : "auto";
	 };
	
	  attachEvent("onload" , min_max_width);
	  attachEvent("onresize", min_max_width);
	  
});



/*
	pageScroll
*/

smooth = 10;

speed = 10;


function scrlWin(){

	if(distYY >= 1 || distYY <= -1){
		if(distYY > 0){
			moveYY = Math.ceil(distYY / smooth);
		}else{
			moveYY = Math.floor(distYY / smooth);
		}
		distYY -= moveYY;
		window.scrollBy(0, -moveYY);

		clearTimeout(timerId);
		timerId = setTimeout("scrlWin()", speed);
	}
}

function smScrl(ET){

	if(document.body.scrollTop){
		winYY = document.body.scrollTop;
	}else{
		winYY = document.documentElement.scrollTop;
	}

	if(window.innerHeight){
		winHH = window.innerHeight;
	}else if(document.all && document.getElementById && (document.compatMode == 'CSS1Compat')){
		winHH = document.documentElement.clientHeight;
	}else{
		winHH = document.body.clientHeight;
	}


	linkVal = "" + ET;
	linkName = linkVal.split("#");

	targetEt = document.getElementById(linkName[1]);
	targetYY = targetEt.offsetTop;
	distYY = winYY - targetYY;
	pageHH = document.body.scrollHeight;

	if(pageHH - targetYY < winHH){
		difVal = winHH - (pageHH - targetYY) - 15;
		distYY += difVal;
	}

	timerId = setTimeout("scrlWin()", speed);
}



