/* -----------------------------------------------------
	ロールオーバー画像変更
----------------------------------------------------- */
imgOn = function() {
	this.setAttribute( 'src', this.getAttribute( 'src' ).replace( '_off.', '_on.' ) );
}
imgOff = function() {
	this.setAttribute( 'src', this.getAttribute( 'src' ).replace( '_on.', '_off.' ) );
}
/* -----------------------------------------------------
	初期設定: ロールオーバー画像変更
----------------------------------------------------- */
function setRollOver(){
	var images = document.getElementsByTagName( 'img' );
	var len = images.length;
	for ( var i=0; i < len; i++ ) {
		var img = images[i];
		img.btnOnMouseOver = imgOn;
		if( img.getAttribute( 'src' ).match( '_off.' ) ) {
			addEvent( img, 'mouseover', 'btnOnMouseOver' );
			addEvent( img, 'mouseout', 'btnOnMouseOut' );
			img.btnOnMouseOut = imgOff;
		}else if ( img.getAttribute( 'src' ).match( '_on.' ) ) {
			addEvent( img, 'mouseover', 'btnOnMouseOver' );
			addEvent( img, 'mouseout', 'btnOnMouseOut' );
			img.btnOnMouseOut = imgOn;
		}
	}
	inputRollOver();
}
addEvent( window, 'load', 'setRollOver' );

/* -----------------------------------------------------
	戻るボタン遷移先セット
----------------------------------------------------- */
function setReturnURL() {
	var url = location.href;
	if (url.match(/[^;\/?:@&=+\$,A-Za-z0-9\-_.!~*\'\(\)%#]/)) return false;
	var r = new RegExp('^https?:\/\/' + window.location.hostname + '\/');
	if (! url.match(r)) return false;
	var d = new Date();
	d.setTime(d.getTime() + 1000*60*60*12);
	var e = d.toGMTString();
	document.cookie = 'return_url=' + encodeURI(url) + '; expires=' + e + '; path=/';
}


/* -----------------------------------------------------
	初期設定: インプットロールオーバー画像変更
----------------------------------------------------- */

function inputRollOver(){
	var inputAll = document.getElementsByTagName( 'input' );
	var inputLen = inputAll.length;
	for ( var i=0; i < inputLen; i++ ) {
		var inputObj = inputAll[i];
		inputObj.inputOnMouseOver = inputOn;
		if (inputObj.className.match('_off')){
			addEvent( inputObj, 'mouseover', 'inputOnMouseOver' );
			addEvent( inputObj, 'mouseout', 'inputOnMouseOut' );
			inputObj.inputOnMouseOut = inputOff;
		} else if (inputObj.className.match('_on')) {
			addEvent( inputObj, 'mouseover', 'inputOnMouseOver' );
			addEvent( inputObj, 'mouseout', 'inputOnMouseOut' );
			inputObj.inputOnMouseOut = inputOn;
		}
	}
}

/* -----------------------------------------------------
	インプット用ロールオーバー画像変更
----------------------------------------------------- */
inputOn = function() {
	var cnOn = this.className;
	this.className = cnOn.replace('_off','_on');
}

inputOff = function() {
	var cnOff = this.className;
	this.className = cnOff.replace('_on','_off');
}

/* -----------------------------------------------------
	イベント追加
----------------------------------------------------- */
function addEvent( target, eventName, handlerName ) {
	if ( target.attachEvent ) {
		target.attachEvent( 'on' + eventName, function(e){ target[handlerName](e); } );
	} else if ( target.addEventListener ) {
		target.addEventListener(eventName, function(e){ target[handlerName](e); }, false );
	} else {
		var originalHandler = target['on' + eventName];
		if ( originalHandler ) {
			target['on' + eventName] = function(e){ originalHandler(e); target[handlerName](e); };
		} else {
			target['on' + eventName] = target[handlerName];
		}
	}
}




/* -----------------------------------------------------
	オートスクロール　v2002
----------------------------------------------------- */
//Pratform Detect Section:
function dtctOS(){
	var ua = navigator.userAgent;
	if (ua.indexOf('Linux')>-1) OS = 'Linux';
	else if (ua.indexOf('Dreamcast')>-1) OS = 'Drmcst';
	else if (ua.indexOf('Mac')>-1) {
		OS = 'Mac';
		if (ua.indexOf('OS X')>-1) OS += 'OSX';
	}
	else if (ua.indexOf('Win')>-1) {
		OS = 'Win';
		if (ua.indexOf('3.1')>-1) OS += '31';
		else if (ua.indexOf('95')>-1) OS += '95';
		else if (ua.indexOf('98')>-1) OS += '98';
		else if (ua.indexOf('ME')>-1) OS += 'ME';
		else if (ua.indexOf('Win 9x 4.90')>-1) OS += 'ME';
		else if (ua.indexOf('NT')>-1){
			if (ua.indexOf('2000')>-1) OS += '2k';
			else if (ua.indexOf('NT 4.0')>-1) OS += '2k'
			else if (ua.indexOf('NT 5.0')>-1) OS += '2k'
			else if (ua.indexOf('XP')>-1) OS += 'XP'
			else if (ua.indexOf('NT 5.1')>-1) OS += 'XP'
		}
	}
	else OS = null;
	return OS
}
//Browser Detect Section:
function dtctBW(){
	var ua = navigator.userAgent;
	if (ua.indexOf('Opera')>-1) BW = 'Opera';
	else if (ua.indexOf('MSIE')>-1){
		BW = 'IE';
		if (ua.indexOf('MSIE 5.')>-1) BW = 'IE5';
		else if (ua.indexOf('MSIE 5.5')>-1) BW = 'IE55';
		else if (ua.indexOf('MSIE 6.')>-1) BW = 'IE6';
		else if (ua.indexOf('MSIE 7.')>-1) BW = 'IE7';
	}
	else if (ua.indexOf('Mozilla/4.0')>-1) BW = NS40;
	else if (ua.indexOf('Mozilla/4.5')>-1) BW = NS45;
	else if (ua.indexOf('Mozilla/4.6')>-1) BW = NS46;
	else if (ua.indexOf('Mozilla/4.7')>-1) BW = NS47;
	else if (ua.indexOf('Mozilla/4.8')>-1) BW = NS48;
	else if (ua.indexOf('Gecko/')>-1){
		BW = 'Mozira';
		if (ua.indexOf('Netscape/6')>-1) BW = 'NS6';
		else if (ua.indexOf('Netscape/7.0')>-1) BW = 'NS70';
		else if (ua.indexOf('Netscape/7.1')>-1) BW = 'NS71';
		else if (ua.indexOf('Netscape/7.2')>-1) BW = 'NS72';
		else if (ua.indexOf('Firefox')>-1) BW = 'FF';
		else if (ua.indexOf('Camino')>-1) BW = 'Camino';
	}
	else if (ua.indexOf('Safari')>-1) BW = 'Safari';
	else if (ua.indexOf('Googlebot')>-1) BW = 'GB';
	else if (ua.indexOf('Yahoo')>-1) BW = 'YB';
	else if (ua.indexOf('msnbot')>-1) BW = 'MSNB';
	else BW = null;
	return BW
}
//ページの高さを取得
function pageHeight(){
	return document.body.offsetHeight;
}
//ウィンドウサイズを取得
function windowHeight(){
	if((dtctBW() == 'NS70') || (dtctBW() == 'NS71') || (dtctBW() == 'NS72') || (dtctBW() == 'FF') || (dtctBW() == 'Mozira') || (dtctBW() == 'Safari') || (dtctBW() == 'Opera') || (dtctBW() == 'Camino')) {return window.innerHeight;}
	else if(((dtctBW() == 'IE5') && (dtctOS() == 'OSX')) || ((dtctBW() == 'IE5') && (dtctOS() == 'Mac'))) {return document.body.clientHeight;}
	else if((dtctBW() == 'IE6') || (dtctBW() == 'IE7') || (dtctBW() == 'IE5') || (dtctBW() == 'IE55')) {return document.documentElement.clientHeight;}
}
//現在のスクロール位置の取得
function nowScl(){
	if((dtctBW() == 'NS70') || (dtctBW() == 'NS71') || (dtctBW() == 'NS72') || (dtctBW() == 'Safari') || (dtctBW() == 'IE5') || (dtctBW() == 'IE55')) {return document.body.scrollTop;}
	else if((dtctBW() == 'IE6') || (dtctBW() == 'IE7') || (dtctBW() == 'FF') || (dtctBW() == 'Camino') || (dtctBW() == 'Mozira') || (dtctBW() == 'Opera') || (dtctBW() == 'IE55')) {return document.documentElement.scrollTop;}
}
//スクロール処理
function scl(elementName){
	var sclSpd = 5;//スピード設定
	if(nowScl() != null) {
		//#削除
		if(elementName.indexOf('#') > 0){
			n = elementName.split('#')
			elementName = n[1];
		}
		//
		ElementY = document.getElementById(elementName).offsetTop;
		//ページの長さが足りないときの処理
		if(((pageHeight() - ElementY) - windowHeight()) < 0) ElementY += (pageHeight() - ElementY) - windowHeight();
		//ふわっと処理
		if((ElementY - nowScl()) >= 0) moveNum = Math.ceil((ElementY - nowScl()) / sclSpd);
		else moveNum = Math.floor((ElementY - nowScl()) / sclSpd);
		nextY = nowScl() + moveNum;
		if(Math.abs(ElementY - nextY) >= 0.05){
			scrollTo(0,nextY);
			setTimeout("scl('"+elementName+"')",20);
		}else{
			scrollTo(0,ElementY);
		}
	}else{
		//alert(dtctBW()+":対応していないブラウザーです。");
	}
}