var openedMenu = null;
var submenuTimer;
//メニュー画像にポインタがきた時
function menuOvr(id){

// 開いているメニューと違うメニューであれば隠す
	if (openedMenu && openedMenu != id){
		CloseMenu(id);
	}
// サブウィンドウ表示
	OpenMenu(id);
}
//レイヤーメニュー表示
function OpenMenu(id){ 

	if ( document.getElementById ){
		document.getElementById( id ).style.visibility = 'visible';
	}else if ( document.all ){
		document.all( id ).style.visibility = 'visible';
	}else if ( document.layers ){
		document.layers[ id ].visibility = 'show';
	}
	clearTimeout(submenuTimer);
	openedMenu = id;
}
//レイヤーメニュー削除
function CloseMenu(){ 

	if ( document.getElementById ){
		document.getElementById( openedMenu ).style.visibility = 'hidden';
	}else if ( document.all ){
		document.all( openedMenu ).style.visibility = 'hidden';
	}else if ( document.layers ){
		document.layers[ openedMenu ].visibility = 'hide';
	}
	openedMenu = null;
}

//スクロールに合わせたメニューの移動
if ('undefined' == typeof this.pageYOffset) {
	var d = (document.compatMode == 'CSS1Compat') ? 'documentElement' : 'body';
	this.pageXOffset = function () { return document[d].scrollLeft; }
	this.pageYOffset = function () { return document[d].scrollTop ; }
}
if ('undefined' == typeof this.addEventListener) {
	this.addEventListener = new Function ('type', 'handler', 'capture', this.attachEvent ? "return this.attachEvent ('on' + type, handler);" : "this['on' + type] = function (oldHandler) { return function (e) { oldHandler && oldHandler (e); handler (e); } } (this['on' + type]);");
}

addEventListener ('load', function () {
	function Timer (msec, handler) {
	this.handler = handler;
	this.timeOut = msec || 100;
	this.timerID = null;
}

function Scheduler (handler) {
	this.timerID = function (thisObj, callBack) { return setTimeout (function() { thisObj.handler (); callBack.call (thisObj); }, thisObj.timeOut); } (this, arguments.callee);
}

function Wrapper (node) {
	this.target = node;
}

function Coordinater (dx, dy) {
	var curX = parseInt (this.left) + dx;
	var curY = parseInt (this.top) + dy;
	this.left = (curX > 0 ? curX : 0) + 'px';
	this.top = (curY > 0 ? curY : 0) + 'px';
}

function Escalator (delay) { /*@cc_on@*/
	this.scrollDelay = delay;
	this.scrollX = pageXOffset /*@if (@_jscript) () @end@*/;
	this.scrollY = pageYOffset /*@if (@_jscript) () @end@*/;
}

function Synchronizer (output) { /*@cc_on@*/
	var dx = Accelerater.call (this, pageXOffset /*@if (@_jscript) () @end@*/ - this.scrollX);
	var dy = Accelerater.call (this, pageYOffset /*@if (@_jscript) () @end@*/ - this.scrollY);
	this.scrollX += dx;
	this.scrollY += dy;
	output.call (this, dx, dy);
}

function Accelerater (dv) {
	return (dv) ? Math.round (dv / Math.abs (dv) * (Math.abs (dv) / this.scrollDelay)) : 0;
}

function Initializer () {
	this.style.position = 'absolute';
	if (isNaN (parseInt (this.style.left))) this.style.left = this.offsetLeft -81 + 'px';
	if (isNaN (parseInt (this.style.top ))) this.style.top = this.offsetTop -10 + 'px';
}

Escalator.prototype.init = function () {
	return Initializer.apply (this.target, arguments);
}

Escalator.prototype.start = function () {
	return Scheduler.apply (this, arguments);
}

Escalator.prototype.print = function () {
	return Coordinater.apply (this.target.style, arguments);
}

Escalator.prototype.sync = function () {
	return Synchronizer.call (this, function (dx, dy) { this.print (dx, dy); } );
}

Escalator.create = function (node, delay, msec) {
	var e = new this (delay || 10);
	Wrapper.call (e, node);
	Timer.call (e, msec || 10, function () { e.sync (); } );
	e.init ();
	e.print (e.scrollX, e.scrollY);
	e.start ();
	return e;
}

Escalator.createById = function (id, delay, msec) {
	var node = document.getElementById && document.getElementById(id);
	return node ? this.create (node, delay, msec) : node;
}

////////////////////////////////////////////////////////////////////////
// ↓↓↓設定するのはここだけ。フロート化したい要素の id を指定する。

Escalator.createById ('menu');

// ↑↑↑指定はいくつでも可能。とりうる引数についてはソース参照。
// id を持たない場合は Escalator.create (element); で直接要素を与えても良い。
////////////////////////////////////////////////////////////////////////
}, false);