var LIB = true;


// DOM定義
var DOM = false;
if( document.getElementById ) DOM = true;


// --------------------------------------------------------------
// object関連
// --------------------------------------------------------------
function LIB_getElement(name) {
	return document.getElementById(name);
}


// --------------------------------------------------------------
// イベント関連
// --------------------------------------------------------------
var LIB_scrtop = 0;
var LIB_scrleft = 0;
var LIB_mx = 0;
var LIB_my = 0;
var _LIB_callback = new Array();

function LIB_setOnScroll(callback) {
	if( typeof callback == 'function' ) _LIB_callback['onScroll'] = callback;
	window.onscroll = _LIB_windowScroll;
	window.onresize = _LIB_windowResize;
	_LIB_windowScroll();
}

function _LIB_windowScroll() {
	LIB_scrtop = document.body.scrollTop || document.documentElement.scrollTop;
	LIB_scrleft = document.body.scrollLeft || document.documentElement.scrollLeft;
	if( typeof(_LIB_callback['onScroll']) == 'function' ) _LIB_callback['onScroll']();
}

function _LIB_windowResize() {
	LIB_scrtop = document.body.scrollTop || document.documentElement.scrollTop;
	LIB_scrleft = document.body.scrollLeft || document.documentElement.scrollLeft;
	if( typeof(_LIB_callback['onScroll']) == 'function' ) _LIB_callback['onScroll']();
}

function LIB_setOnMouseMove(callback) {
	if( typeof callback == 'function' ) _LIB_callback['onMouseMove'] = callback;
	document.onmousemove = _LIB_mouseMove;
	//_LIB_mouseMove(window.event);
	//moveBy(0,0);
}

function _LIB_mouseMove(e) {
	LIB_mx = e ? e.clientX : event.clientX;
	LIB_my = e ? e.clientY : event.clientY;
	if( typeof(_LIB_callback['onMouseMove']) == 'function' ) _LIB_callback['onMouseMove']();
}




// --------------------------------------------------------------
// フェードイン／アウト
// --------------------------------------------------------------
var LIB_fadestep = 10;
var _LIB_fadetime = 10;
var _LIB_fadecnt = new Array();
var _LIB_faderun = new Array();
var _LIB_fadelive = new Array();
function LIB_execFadeIn(name, id){
	if( _LIB_faderun[name] ) return false;
	_LIB_faderun[name] = true;
	_LIB_fadecnt[name] = 0;
	_LIB_fadelive[id] = 1;
	_LIB_execFade(name, id, false);
	return true;
}
function LIB_execFadeOut(name, id) {
	if( _LIB_faderun[name] ) return false;
	_LIB_faderun[name] = true;
	_LIB_fadecnt[name] = 100;
	_LIB_fadelive[id] = 2;
	_LIB_execFade(name, id, true);
	return true;
}
function _LIB_execFade(name, id, out) {
	elem = LIB_getElement(name);
	if( ! elem ) return false;
	if( ! _LIB_fadelive[id] ) return false;
	if( _LIB_fadelive[id] == 1 && out ) return false;
	if( _LIB_fadelive[id] == 2 && ! out ) return false;
	_LIB_faderun[name] = true;
	if( ! elem.filters 
		|| ( out && _LIB_fadecnt[name] <= 0 )
		|| ( ! out && _LIB_fadecnt[name] >= 100)
		){
		if( out ){
			elem.style.display = 'none';
		}
		_LIB_faderun[name] = false;
		_LIB_fadelive[id] = false;
		return;
	}
	elem.style.filter = 'Alpha(style=0)';
	if( out ){
		_LIB_fadecnt[name] -= LIB_fadestep;
		if( _LIB_fadecnt[name] < 0 ) _LIB_fadecnt[name] = 0;
	}else{
		_LIB_fadecnt[name] += LIB_fadestep;
		if( _LIB_fadecnt[name] > 100 ) _LIB_fadecnt[name] = 100;
	}
	elem.filters(0).Opacity = _LIB_fadecnt[name];
	elem.filters(0).FinishOpacity = _LIB_fadecnt[name];
	setTimeout("_LIB_execFade('" + name + "', '" + id + "', " + out + ");", _LIB_fadetime);
}
function LIB_abortFade(name, id, cnt) {
	_LIB_setFadeCount(name, 0);
	_LIB_fadelive[id] = false;
	_LIB_faderun[name] = false;
}
function _LIB_setFadeCount(name, cnt) {
	elem = LIB_getElement(name);
	if( ! elem || ! elem.filters ) return false;
	elem.style.filter = 'Alpha(style=0)';
	_LIB_fadecnt[name] = cnt;
	elem.filters(0).Opacity = _LIB_fadecnt[name];
	elem.filters(0).FinishOpacity = _LIB_fadecnt[name];
}
