ffPrintCss();

function ffPrintCss(){
	var firefox = (navigator.userAgent.indexOf("Firefox") != -1)? true : false;
	if(firefox) document.write('<link rel="stylesheet" type="text/css" media="print" href="../common/css/print.css" />');
}

function openItemWin(url){
	w = window.open(url,'itemWindow','width=417,height=665,menubar=no,toolbar=no,directories=no,scrollbars=yes,resizable=yes');
	w.focus();
}

Scroller = {
	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	//現在位置の取得
	offsetY: function(){
		if(document.all){
			if(document.compatMode == "CSS1Compat"){
				y = document.documentElement.scrollTop;
			}else{
				y = document.body.scrollTop;
			}
		}else if(window.pageYOffset !== undefined){
			y = window.pageYOffset;
		}else{
			y = window.scrollY;
		}
		return y;
	},

	//スクロールの設定
	scrollSet: function(nowY,targetY){
		var diffY,stepY,moveY;
		diffY = .1 * (targetY - nowY);
		if(diffY > 0){
			stepY = Math.ceil(diffY);
		}else{
			stepY = Math.floor(diffY);
		}
		moveY = nowY + stepY;
		if( stepY > 0 && moveY <= targetY  || stepY < 0 && moveY >= targetY ){
			window.scroll(null,moveY);
			nowY += stepY;
			setTimeout("Scroller.scrollSet( " +nowY+ "," +targetY+ " )",1);
		}else{
			return true;
		}
	},

	//スクロールの実行
	scroll: function(targetY){
		var nowY = this.offsetY();
		this.scrollSet(nowY,targetY);
	},

	//idへのスクロール
	Id: function(IdName){
		var Anchor = document.getElementById(IdName);
		var posY = this.gy(Anchor);
		this.scroll(posY);
	},

	//アンカーへのスクロール
	Anchor: function(Anchor){
		var posY = this.gy(Anchor);
		this.scroll(posY);
	},

	//ページトップへのスクロール（おまけ）
	pageTop: function(){
		this.scroll(0,0);
	},

	//イベントハンドラを埋め込み
	add: function(event, body, d) {
		if (event.addEventListener) return event.addEventListener(body, d,false)
		if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	//イベントを使用不可に
	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			return;
		}
		if (e.preventDefault && e.stopPropagation) {
			e.preventDefault();
			e.stopPropagation();
		}
	},

	//起動時にリンクの置き換え処理を実行
	init: function(){
		Scroller.add(window,'load', Scroller.render);
	},

	//リンクの置き換え処理
	render: function(){
		a = document.getElementsByTagName('a');
		Scroller.end(this);
		window.onscroll;
		for (i=0;i<a.length;i++) {
			l = a[i];
			if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname) || ('/'+l.pathname==location.pathname)) ){
				Scroller.add(l,'click',Scroller.end)
				l.onclick = function(){
					Scroller.end(this);
					l=this.hash.substr(1);

					//リンク末尾が#のみだと無効化
					if(l != ""){
						if(document.getElementById(l)){
							Scroller.Id(l);
						}else{
							a = document.getElementsByTagName('a');
							for (i=0;i<a.length;i++) {
								if(a[i].name == l){
									Scroller.Anchor(a[i]);
								}
							}
						}
					}
				}
			}
		}
	}

}

Scroller.init();

