
/* ロールオーバー処理 */

/*
 Btn Class v1.1
 update 2007.12.10
 create K.Kubonaka 
*/

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"));
};


/*
 roSetter v1.1
 update 2007.12.10
 create K.Kubonaka 
*/

(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){
		}
	}
});


/* アンカー処理 */

var speed = 10;
var remain;
var endY;

function Scroll(id){
	
	var d = document.getElementById(id);
	var windowHeight = document.body.offsetHeight;
	var innerHeight = get_browser_height();

	if(navigator.userAgent.indexOf("Safari") != -1){ 
		startY = document.body.scrollTop;
	}else{
		startY = document.documentElement.scrollTop;
	}
		
	endY = d.offsetTop;	
	if (d.offsetParent) while (d = d.offsetParent) endY += d.offsetTop;
	windowY = windowHeight - endY ;
	
	if(windowY > innerHeight){
		setIn = setInterval("ScrollCnt()",10);
	} else{
		endY = windowHeight - innerHeight;
		setIn = setInterval("ScrollCnt()",10);
	}
}

function get_browser_height() {
	if ( window.innerHeight ) { return window.innerHeight; }  
	else if ( document.documentElement && document.documentElement.clientHeight != 0 ) { return document.documentElement.clientHeight; }  
	else if ( document.body ) { return document.body.clientHeight; }
	return 0;
}

function ScrollCnt(){
	startY += ((endY-startY)/speed)+5;
	scrollTo(0,startY);
	
	if(startY > endY){
		clearInterval(setIn);
	}
}

