/* **************************************************************************************
__________________________________________________________________________________________
      __                                               __                                 
    /    )                                /          /    )                         /    /
----\--------_--_-----__-----__---_/_----/__---------\---------__----)__-----__----/----/-
     \      / /  )  /   )  /   )  /     /   )         \      /   '  /   )  /   )  /    /  
_(____/____/_/__/__(___/__(___/__(_ ___/___/______(____/____(___ __/______(___/__/____/___

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Copyright(C) NetGRiD Co. Ltd. All Rights Reserved.
*************************************************************************************** */


//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()+":対応していないブラウザーです。");
	}
}

//event attacher
function autoAttuchScrollEvent(){
	var aTags = document.getElementsByTagName('a');
	for(var i=0; i<aTags.length; i++){
		if(aTags.item(i).hash != ''){
			aTags.item(i).onclick = function(){ scl(this.href); this.blur(); return false; };
		}
	}
}
addEvent(window, 'load', 'autoAttuchScrollEvent')

