// --------------------------------------------------------------
// 読み込みチェック
if( ! window['LIB'] ){
// --------------------------------------------------------------

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




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




// --------------------------------------------------------------
// httpリクエストobject
// --------------------------------------------------------------
function LIB_getXMLHttp() {

	var xmlhttp = false;
	if( this.XMLHttpRequest ){
		xmlhttp = new XMLHttpRequest();
	}else{
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
			}
		}
	}

	return xmlhttp;

}




// --------------------------------------------------------------
// htmlspecialchars
// --------------------------------------------------------------
try{
	String.prototype.htmlspecialchars = function() {
		ch = this + "";
		ch = ch.replace(/&/g,"&amp;") ;
		ch = ch.replace(/"/g,"&quot;") ;
		ch = ch.replace(/'/g,"&#039;") ;
		ch = ch.replace(/</g,"&lt;") ;
		ch = ch.replace(/>/g,"&gt;") ;
		return ch;
	}
	String.prototype.htmlspecialchars_decode = function() {
		ch = this + "";
		ch = ch.replace("&gt;", ">") ;
		ch = ch.replace("&lt;", "<") ;
		ch = ch.replace("&#039;", "'") ;
		ch = ch.replace("&quot;", '"') ;
		ch = ch.replace("&amp;", '&') ;
		return ch;
	}
}catch(e){
}




// --------------------------------------------------------------
// cookie操作
// --------------------------------------------------------------
function LIB_setCookie(key, value, days, path) {
	var str = key + "=" + escape(value) + ";";
	if (days != 0) {
		var dt = new Date();
		dt.setDate(dt.getDate() + days);
		str += "expires=" + dt.toGMTString() + ";";
	}
	if( path ){
		str += 'path=' + encodeURI(path) + ';';
	}
	document.cookie = str;
}



/* Cookie の読み込み
	引数 key : 求める値のキー
	戻り値　 : 値（ない時は空文字""）*/
function LIB_getCookie(key) {
	var sCookie = document.cookie;
	var aData = sCookie.split(";");
	var oExp = new RegExp(" ", "g");
	var val = '';
	key = key.replace(oExp, "");

	for(var i = 0; i < aData.length; i++){
		var aWord = aData[i].split("=");
		aWord[0] = aWord[0].replace(oExp, "");
		if (key == aWord[0]){
			val = unescape(aWord[1]);
			break;
		}
	}
	return val;
}


// Cookie の削除 （引数key : キー）
function LIB_removeCookie(key) 
{
	var dt = new Date();
	var str = key + "=;expires=" + dt.toGMTString();
	document.cookie = str;
}




// --------------------------------------------------------------
// イベント関連
// --------------------------------------------------------------
var LIB_scrtop = 0;
var LIB_scrleft = 0;
var LIB_mx = 0;
var LIB_my = 0;
var _LIB_callback = new Array();
_LIB_callback['onScroll'] = new Array();
_LIB_callback['onMouseMove'] = new Array();
_LIB_callback['onKeyPress'] = new Array();

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

function _LIB_windowScroll() {
	try{
		LIB_scrtop = document.body.scrollTop || document.documentElement.scrollTop;
		LIB_scrleft = document.body.scrollLeft || document.documentElement.scrollLeft;
	}catch(e){
	}
	for(var i = 0; i < _LIB_callback['onScroll'].length; i++){
		_LIB_callback['onScroll'][i]();
	}
}

function _LIB_windowResize() {
	LIB_scrtop = document.body.scrollTop || document.documentElement.scrollTop;
	LIB_scrleft = document.body.scrollLeft || document.documentElement.scrollLeft;
	for(var i = 0; i < _LIB_callback['onScroll'].length; i++){
		_LIB_callback['onScroll'][i]();
	}
}

function LIB_setOnMouseMove(callback) {
	if( typeof callback == 'function' ) _LIB_callback['onMouseMove'].push(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;
	for(var i = 0; i < _LIB_callback['onMouseMove'].length; i++){
		_LIB_callback['onMouseMove'][i]();
	}
}

function LIB_setKeyPress(callback) {
	if( typeof callback == 'function' ) _LIB_callback['onKeyPress'].push(callback);
	if( window.addEventListener ){
		window.addEventListener('keydown', _LIB_onKeyPress, false);
	}else if( window.attachEvent ){
		document.body.attachEvent('onkeydown', _LIB_onKeyPress);
	}else{
		//document.onkeypress = _LIB_onKeyPress;
	}
}

function _LIB_onKeyPress(e) {
	var code = false;
	if( document.all ){
		code = event.keyCode;
	}else{
		code = e.keyCode;
	}
	for(var i = 0; i < _LIB_callback['onKeyPress'].length; i++){
		_LIB_callback['onKeyPress'][i](code);
	}
}




// --------------------------------------------------------------
// フェードイン／アウト
// --------------------------------------------------------------
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];
}


// --------------------------------------------------------------
}
// --------------------------------------------------------------

var LIB = true;

