﻿/*******************************************************************************
 * LayerPopup library
 * 2008.06.09 KiHyun Kim
 * IE 5.01/5.5/6/7/8,  FF 2/3, Safari, Opera, Chrome Supported
 ******************************************************************************/

var LPlib = {};

// this js file's path ----------------------------------------
LPlib.jsPath		= '/common/js/layer_popup';

// load style sheet -------------------------------------------
document.write('<link type="text/css" rel="stylesheet" href="'+ LPlib.jsPath +'/layer_popup.css" media="all" />\n');



LPlib.agent_name	= navigator.userAgent.toLowerCase();
LPlib.is_ie			= ((LPlib.agent_name.indexOf("msie") != -1) && (LPlib.agent_name.indexOf("opera") == -1));
LPlib.is_ie7		= (LPlib.is_ie && (parseFloat(navigator.appVersion.split('MSIE')[1])>=7));
LPlib.is_ie7_2		= (LPlib.is_ie7 && (document.all[0].nodeType==8));
LPlib.is_ie8		= (LPlib.is_ie && (parseFloat(navigator.appVersion.split('MSIE')[1])>=8));
LPlib.is_gecko		= navigator.product;
LPlib.is_strict		= (document.compatMode == 'CSS1Compat');
LPlib.z_index		= 50000;
LPlib.css_files		= [];
LPlib.objects		= [];
LPlib.body			= function() { return ( ((!LPlib.is_ie) || (LPlib.is_ie && LPlib.is_strict)) ? self.document.documentElement : self.document.body ) };
LPlib.bodySize		= function() { return { width:LPlib.body().scrollWidth, height:LPlib.body().scrollHeight }; };
LPlib.screenSize	= function() { return { width:screen.availWidth, height:screen.availHeight }; };
LPlib.browserSize	= function() { return { width:LPlib.body().clientWidth, height:LPlib.body().clientHeight }; };
LPlib.iframeBodySize	= function() {
	var obj = LPlib.getCurrentObject();
	if (obj) {
		var id	= obj.ifm.getAttribute('id');
		var win = ((LPlib.is_ie) ? self.document.getElementById(id).contentWindow : window.frames[id]);
		if (LPlib.is_ie && win.LPlib) {
			var testObj = self.document.createElement('DIV');
			testObj.style.visibility = 'hidden';
			testObj.innerHTML = win.document.body.innerHTML;
			self.document.body.appendChild( testObj );
			var docHeight = testObj.scrollHeight;
			self.document.body.removeChild( testObj );
			return { width:win.LPlib.body().scrollWidth, height:docHeight };
		}
		return win.LPlib.bodySize();
	}
	return  { width:0, height:0 };
};

// API function
LPlib.getCurrentObject	= function() {
	for (var i=LPlib.objects.length;i>0;i--) {
		if (LPlib.objects[i-1].isOpen) return LPlib.objects[i-1];
	}
	return null;
}
LPlib.close				= function() {
	var obj = LPlib.getCurrentObject();
	if (obj) obj.close();
}
LPlib.closeLoadingMask	= function() {
	var obj = LPlib.getCurrentObject();
	if (obj) obj.closeLoadingMask();
}
LPlib.showLoadingMask	= function() {
	var obj = LPlib.getCurrentObject();
	if (obj) obj.showLoadingMask();
}
LPlib.setSize			= function(width, height) {
	var obj = LPlib.getCurrentObject();
	if (obj) obj.setSize(width, height);
}
LPlib.setCloseFunction	= function(func) {
	var obj = LPlib.getCurrentObject();
	if ((obj)&&(func)&&(typeof(func)=='function')) {
		obj.closeFunction = func;
	}else{
		obj.closeFunction = null;
	}
}
LPlib.goURL	= function(url, width, height) {
	var obj = LPlib.getCurrentObject();
	if (obj && url) {
		obj.showLoadingMask();
		if (width && height) obj.show(url, width, height);
		else obj.loadURL(url);
	}
}

// Get background Size
LPlib.getBgSize			= function() {
	if(!LPlib.bodySize().width)	LPlib.bodySize().width=LPlib.body().scrollWidth;
	if(!LPlib.bodySize().height)	LPlib.bodySize().height=LPlib.body().scrollHeight;
	var width = ((LPlib.body().clientWidth>LPlib.bodySize().width) ? LPlib.body().clientWidth : LPlib.bodySize().width);
	var height = ((LPlib.body().clientHeight>LPlib.bodySize().height) ? LPlib.body().clientHeight : LPlib.bodySize().height);
	return { width:width, height:height };
};

// Hide/Show trouble elements
LPlib.hideObjs = [];
LPlib.toggleTroubleElements = function (on) {
	if (on) {
		for (var i=0; i<LPlib.hideObjs.length; i++){
			LPlib.hideObjs[i].style.visibility = 'visible';
		}
		LPlib.hideObjs = [];
	}else{
		LPlib.hideObjs = [];
		var objs = document.getElementsByTagName('select');
		for (var i=0; i<objs.length; i++){
			if (objs[i].style.visibility != 'hidden') { objs[i].style.visibility = 'hidden'; LPlib.hideObjs.push(objs[i]); }
		}
		var objs = document.getElementsByTagName('object');
		for (var i=0; i<objs.length; i++){
			if (objs[i].style.visibility != 'hidden') {
				if ((!objs[i].wmode) || ((objs[i].wmode.toLowerCase()!='opaque') && (objs[i].wmode.toLowerCase()!='transparent')))
					{ objs[i].style.visibility = 'hidden'; LPlib.hideObjs.push(objs[i]); }
			}
		}
		var objs = document.getElementsByTagName('embed');
		for (var i=0; i<objs.length; i++){
			if (objs[i].style.visibility != 'hidden') {
				if ((!objs[i].getAttribute("wmode")) || ((objs[i].getAttribute("wmode").toLowerCase()!='opaque') && (objs[i].getAttribute("wmode").toLowerCase()!='transparent')))
					{ objs[i].style.visibility = 'hidden'; LPlib.hideObjs.push(objs[i]); }
			}
		}
	}
};

// Protect mouse dragging
LPlib.removeSelection = function (obj) {
	if (obj) {
		obj.style.cursor	= 'default';
		obj.ondblclick		= LPlib.clearSelection;
		obj.onmousedown		= LPlib.clearSelection;
		obj.oncontextmenu	= LPlib.clearSelection;
		obj.onselectstart	= LPlib.clearSelection;
	}
};

// Add event callback
LPlib.addEvent = function (obj, evt, func, capture) {
	if (!obj) return;
	if (obj.attachEvent) { obj.attachEvent(evt, func); }
	else if (obj.addEventListener) {
		if (!capture) capture=false;
		evt = evt.replace(/^on/i,'');
		obj.addEventListener(evt, func, capture);
	}else{ obj[evt] = fnc; }
	return;
};

// Remove event callback
LPlib.removeEvent = function (obj, evt, func, capture) {
	if (!obj) return;
	if (obj.attachEvent) { obj.detachEvent(evt, func); }
	if (obj.addEventListener) {
		if (!capture) capture=false;
		evt = evt.replace(/^on/i,'');
		obj.removeEventListener(evt, func, capture);
	}else{ obj[evt] = null; }
	return;
};

// Protect mouse dragging callback
LPlib.clearSelection = function (e) {
	try {
		var obj = ( (window.event) ? window.event.srcElement : e.target );
		if ((obj.type=='text')||(obj.type=='textarea')||(obj.type=='file')||(obj.type=='password')) return true;
		if(document.selection && document.selection.empty){
			document.selection.empty() ;
		} else if(window.getSelection) {
			var sel=window.getSelection();
			if(sel && sel.removeAllRanges) sel.removeAllRanges() ;
			if(sel && sel.collapse) sel.collapse() ;
		}
	}catch(e){}
	if (LPlib.is_gecko) {
		var objInputs = document.getElementsByTagName('input');
		for (var i=0; i<objInputs.length; i++) {
			if ((objInputs[i].type=='text')||(objInputs[i].type=='textarea')||(objInputs[i].type=='file')||(objInputs[i].type=='password'))
				objInputs[i].blur();
		}
	}
	return false;
};

// [private] Get current applyed style
LPlib.getStyle = function (obj, style) {
	var value = '';
	if (obj) {
		if (document.defaultView)
			value = document.defaultView.getComputedStyle(obj,'').getPropertyValue(style);
		else if (obj.currentStyle) {
			style = style.replace(/\-(\w)/g, function (strMatch,p1){return p1.toUpperCase();});
			value = obj.currentStyle[style];
		}
	}
	return value;
};

// [private] Get css class value
LPlib.getClassStyle = function(className, style) {
	className = "."+className;
	var sheets = document.styleSheets;
	var rules, styleObj;
	for (i=0;i< sheets.length; i++) {
		rules = (sheets[i].rules) ? sheets[i].rules : sheets[i].cssRules;
		for (var j=0; j<rules.length; j++) {
			if (rules[j].selectorText && rules[j].selectorText == className) {
				styleObj = rules[j].style;
				return styleObj[style];
			}
		}
	}
	return null;
}
     
// [private] Preload Images
LPlib.preloadImages = function() {
	var images = new Array;
	for (var i=0; i<arguments.length; i++) {
		images[i] = new Image();
		images[i].src = arguments[i];
	}
	return(images);
};


/*******************************************************************************
 * LayerPopup object ( loading another page in iframe )
 ******************************************************************************/

var LayerPopup = function (id) {

	this.dlg			= null;				// Dialog element
	this.dlgBg			= null;				// Background overlay element
	this.ifm			= null;				// Iframe element
	this.loading		= null;				// Loading Mask
	this.document		= self.document;
	this.id				= id;
	this.width			= 0;
	this.height			= 0;
	this.isOpen			= false;
	this.fade			= { speed:30, step:0.2, run:false };
	this.closeFunction	= null;
	this.init			= false;
	this.create			= false;

	// [public] Open dialog
    this.open = function (url, width, height, autoClose, fadeSpeed) {
    	if (!this.init) {
    		if ( (!this.create) || (LPlib.getStyle(this.dlgBg,'background-color')=='')
    			|| (LPlib.getStyle(this.dlgBg,'background-color') == 'transparent') || (parseFloat(LPlib.getStyle(this.dlgBg,'opacity')) == 1) ) {
    			window.setTimeout( (function(){this.open.bind(this)(url, width, height, autoClose, fadeSpeed)}).bind(this), 50 );
    			return;
    		}
    		this.init = true;
    	}
		this.isOpen				= true;
		this.fade.opacity		= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
		this.fade.speed			= ( (!fadeSpeed && (fadeSpeed!==0)) ? this.fade.speed	 : parseInt(fadeSpeed) );
		this.fade.arguments		= {url:url, width:width, height:height, autoClose:autoClose};
		this.toggleBackground(true);
		if (this.fade.speed == 0) this.show(url, width, height);
	}

	// [public] Resize for opened dialog
	this.setSize = function (width, height) {
		this.width		= parseInt(width);
		this.height		= parseInt(height);

		this.dlg.style.width		= this.width.toString() + 'px';
		this.dlg.style.height		= this.height.toString() + 'px';

		if ((LPlib.browserSize().width < this.width) || (LPlib.browserSize().height < this.height)) {
			this.dlg.style.position		= 'absolute';
			this.dlg.style.marginLeft	= '0px';
			this.dlg.style.marginTop	= '5px';
			this.dlg.style.height		= (this.height+5).toString() + 'px';
			if (LPlib.browserSize().width < this.width) {
				this.dlg.style.left	= '0px';
			}else{
				this.dlg.style.left	= ((LPlib.browserSize().width-this.width)/2).toString() + 'px';
			}
			if (LPlib.is_ie && (!LPlib.is_ie7_2)) this.dlg.style.removeExpression('top');
			if (LPlib.browserSize().height < this.height) {
				this.dlg.style.top	= '0px';
			}else{
				this.dlg.style.top	= ((LPlib.browserSize().height-this.height)/2).toString() + 'px';
			}
			window.scrollTo(0,0);
		}else{
			this.dlg.style.position		= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
			this.dlg.style.left			= '50%';
			this.dlg.style.marginLeft	= (0-(this.width/2)).toString() + 'px';
			this.dlg.style.marginTop	= '0px';
			if (LPlib.is_ie && (!LPlib.is_ie7_2)) {
				this.dlg.style.setExpression('top', 'LPlib.body().scrollTop + Math.round((LPlib.body().clientHeight-this.style.pixelHeight)/2)' );
			}else{
				this.dlg.style.top			= '50%';
				this.dlg.style.marginTop	= (0-(this.height/2)).toString() + 'px';
			}
		}

		this.loading.style.width	= this.width.toString() + 'px';
		this.loading.style.height	= this.height.toString() + 'px';
		this.ifm.style.width		= this.width.toString() + 'px';
		this.ifm.style.height		= this.height.toString() + 'px';
	}

	// [public] Close for opened dialog
    this.close = function() {
    	if (!this.isOpen) return;
		if (this.ifm) this.ifm.style.visibility	= 'hidden';
		if (this.loading) this.loading.style.display = 'block';
		if (this.dlg) this.dlg.style.visibility	= 'hidden';
		this.closeURL();
		this.toggleBackground(false);
    }

	// [public] Show loading mask
    this.showLoadingMask = function() {
    	if (!this.isOpen) return;
		if (this.ifm) this.ifm.style.visibility	= 'hidden';
		if (this.loading) this.loading.style.display = 'block';
    }

	// [public] Close loading mask
    this.closeLoadingMask = function() {
    	if (!this.isOpen) return;
		if (this.loading) this.loading.style.display = 'none';
		if (this.ifm) this.ifm.style.visibility	= 'visible';
    }

	// [public] Adjust Scrolling
    this.adjustScrolling = function() {
		var id	= this.ifm.getAttribute('id');
		var win = ((LPlib.is_ie) ? this.document.getElementById(id).contentWindow : window.frames[id]);
		if (win.LPlib) {
			if (win.LPlib.bodySize().height > this.height) {
				this.setSize(this.width+20, this.height);
				this.ifm.setAttribute('scrolling','auto');
			}else{
				this.ifm.setAttribute('scrolling','no');
			}
		}
	}
	
	// [private] Create DOM element on window.onload
	this.createObject = function () {

		LPlib.objects.push(this);

		this.dlgBg					= this.document.createElement('DIV');
		this.dlgBg.setAttribute('id', this.id + '_bg');
		this.dlgBg.style.visibility	= 'hidden';
		this.dlgBg.style.position	= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
		this.dlgBg.style.zIndex		= LPlib.z_index++;
		this.dlgBg.style.left		= '0px';
		this.dlgBg.style.top		= '0px';
		this.dlgBg.className		= 'LayerPopupBackground';
		this.document.body.appendChild( this.dlgBg );

		this.dlg					= this.document.createElement('DIV');
		this.dlg.setAttribute('id', this.id);
		this.dlg.style.visibility	= 'hidden';
		this.dlg.style.position		= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
		this.dlg.style.zIndex		= LPlib.z_index++;
		this.dlg.style.left			= '0px';
		this.dlg.style.top			= '0px';
		this.dlg.className			= 'LayerPopupWindow';
		this.dlg.style.overflow		= 'hidden';

		this.loading				= this.document.createElement('DIV');
		this.loading.setAttribute('id', this.id + '_loading');
		this.loading.style.overflow	= 'hidden';
		this.loading.className		= 'LayerPopupLoadingMask';
		LPlib.removeSelection(this.loading);
		this.loading.innerHTML		= '<table><tr><td><img src="'+ LPlib.jsPath + '/img/loading_w.gif" /></td></tr></table>'
		this.dlg.appendChild( this.loading );

		this.ifm					= this.document.createElement('IFRAME');
		this.ifm.setAttribute('id', this.id + '_iframe');
		this.ifm.setAttribute('name', this.id + '_iframe');
		this.ifm.setAttribute('src', 'about:blank');
		this.ifm.setAttribute('frameBorder','0');
		this.ifm.setAttribute('marginwidth','0');
		this.ifm.setAttribute('marginheight','0');
		this.ifm.setAttribute('scrolling','auto');
		this.ifm.setAttribute('allowtransparent','true');
		this.ifm.style.visibility	= 'hidden';
		this.ifm.style.border		= 'none';
		this.ifm.onbeforeunload		= null;
		this.dlg.appendChild( this.ifm );

		LPlib.addEvent( window, 'onresize', this.onResize.bind(this), false );
		this.document.body.appendChild( this.dlg );
		this.create 				= true;
	}

	// [private] Browser Resize
	this.onResize = function () {
		if (this.isOpen) {
			this.setSize(this.width, this.height);
		}
	}

	// [private] Display on
	this.show = function (url, width, height) {
		this.setSize(width, height);
		this.loadURL(url);
		this.dlg.style.visibility			= 'visible';
	}

	// [private] Load document for iframe
    this.loadURL = function(url) {
		var id	= this.ifm.getAttribute('id');
		var win = ((LPlib.is_ie) ? this.document.getElementById(id).contentWindow : window.frames[id]);
		win.location.replace(url);
		//this.ifm.setAttribute('src', url);
    }

	// [private] Close document for iframe
    this.closeURL = function() {
    	try {
			var id		= this.ifm.getAttribute('id');
    		var oDoc	= this.ifm.contentWindow || this.ifm.contentDocument || window.frames[id];
    		if (oDoc.document) oDoc = oDoc.document;
			oDoc.body.innerHTML = '';
		}catch(e){}
    }

	// [private] Toggle background overlay
    this.toggleBackground = function (on) {
		this.dlgBg.style.width	= '100%';
		if (LPlib.is_ie && (!LPlib.is_ie7_2)) {
			this.dlgBg.style.setExpression('height', 'LPlib.getBgSize().height' );
		}else{
			this.dlgBg.style.height	= '100%';
		}
		if (on) {
			this.fadeInBackground();
		}else{
			this.fadeOutBackground();
		}
    }

	// [private] Fade out effect of background overlay
    this.fadeOutBackground = function () {
		if (this.fade.speed > 0) {
			if (!this.fade.run) {
				this.fade.run	= true;
				this.fade.target = 0;
			}
			var opacity	= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
			if (opacity > this.fade.target) {
				var step = ((opacity-this.fade.target)<this.fade.step) ? (opacity-this.fade.target) : this.fade.step;
				this.dlgBg.style.opacity	= (opacity - step).toString();
				this.dlgBg.style.filter		= 'alpha(Opacity=' + ((opacity-step)*100).toString() + ')';
				this.fade.handle = window.setTimeout( this.fadeOutBackground.bind(this), this.fade.speed/2 );
				return;
			}
			window.clearTimeout(this.fade.handle);
			this.fade.run	= false;
		}
		this.dlgBg.style.visibility	= 'hidden';
		this.dlgBg.style.opacity	= this.fade.opacity.toString();
		this.dlgBg.style.filter		= 'alpha(Opacity=' + (this.fade.opacity*100).toString() + ')';
		//this.dlgBg.style.height	= '10px';
		//this.dlg.style.height		= '10px';
		LPlib.toggleTroubleElements(true);
		this.dlgBg.onclick = null;
		this.isOpen	= false;
		if ((this.closeFunction)&&(typeof(this.closeFunction)=='function')) {
			this.closeFunction();
		}
	}

    // [private] Fade in effect of background overlay
	this.fadeInBackground = function () {
		if (this.fade.speed > 0) {
			if (!this.fade.run) {
				LPlib.toggleTroubleElements(false);
				this.fade.run	= true;
				this.fade.target = this.fade.opacity;
				this.dlgBg.style.visibility	= 'visible';
				this.dlgBg.style.opacity	= '0';
				this.dlgBg.style.filter		= 'alpha(Opacity=0)';
				this.fade.handle = window.setTimeout( this.fadeInBackground.bind(this), this.fade.speed );
				return;
			}
			var opacity	= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
			if (opacity < this.fade.target) {
				var step = ((this.fade.target-opacity)<this.fade.step) ? (this.fade.target-opacity) : this.fade.step;
				this.dlgBg.style.opacity	= (opacity + step).toString();
				this.dlgBg.style.filter		= 'alpha(Opacity=' + ((opacity+step)*100).toString() + ')';
				this.fade.handle = window.setTimeout( this.fadeInBackground.bind(this), this.fade.speed );
				return;
			}
			window.clearTimeout(this.fade.handle);
			this.fade.run	= false;
		}else{
			LPlib.toggleTroubleElements(false);
			this.dlgBg.style.visibility	= 'visible';
		}
		this.dlgBg.onclick = ( this.fade.arguments.autoClose ? this.close.bind(this) : null );
		this.show(this.fade.arguments.url, this.fade.arguments.width, this.fade.arguments.height);
	}

	// run this object
	LPlib.addEvent( window, 'onload', this.createObject.bind(this), false );

}



/*******************************************************************************
 * LayerAlert object ( JS alert/confirm implements )
 ******************************************************************************/

var LayerAlert = function (id) {

	this.dlg			= null;				// Dialog element
	this.dlgBg			= null;				// Background overlay element
	this.document		= self.document;
	this.id				= id;
	this.buttons		= ['OK','キャンセル'];
	this.selectButton	= 0;
	this.width			= 0;
	this.height			= 0;
	this.isOpen			= false;
	this.fade			= { speed:20, step:0.15, run:false };
	this.closeFunction	= null;
	this.init			= false;
	this.create			= false;

	// Preload Images
	LPlib.preloadImages( LPlib.jsPath+'/img/box_lt.gif', LPlib.jsPath+'/img/box_rt.gif', LPlib.jsPath+'/img/box_lb.gif', LPlib.jsPath+'/img/box_rb.gif',
		LPlib.jsPath+'/img/btn_x.gif', LPlib.jsPath+'/img/btn_left.gif', LPlib.jsPath+'/img/btn_right.gif', LPlib.jsPath+'/img/btn_bg.gif' );

	// [public] Open dialog
    this.open = function (width, height, title, msg, buttons, showCloseBtn, closeFunction, autoClose, fadeSpeed) {
    	if (!this.init) {
    		if ( (!this.create) || (LPlib.getStyle(this.dlgBg,'background-color')=='')
    			|| (LPlib.getStyle(this.dlgBg,'background-color') == 'transparent') || (parseFloat(LPlib.getStyle(this.dlgBg,'opacity')) == 1) ) {
    			window.setTimeout( (function(){this.open.bind(this)(title, msg, buttons, closeFunction, autoClose, fadeSpeed)}).bind(this), 50 );
    			return;
    		}
    		this.init = true;
    	}

		this.isOpen				= true;
		this.fade.opacity		= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
		this.fade.speed			= ( (!fadeSpeed && (fadeSpeed!==0)) ? this.fade.speed	 : parseInt(fadeSpeed) );
		this.fade.arguments		= { width:width, height:height, title:title, msg:msg, showCloseBtn:showCloseBtn, autoClose:autoClose };
		this.buttons			= buttons;
		if ((closeFunction)&&(typeof(closeFunction)=='function')) {
			this.closeFunction = closeFunction;
		}else{
			this.closeFunction = null;
		}

		this.toggleBackground(true);
		if (this.fade.speed == 0) this.show(width, height, title, msg, showCloseBtn);
	}

	// [public] Resize for opened dialog
	this.setSize = function (width, height) {
		this.width		= parseInt(width);
		this.height		= parseInt(height);

		this.dlg.style.width		= this.width.toString() + 'px';
		this.dlg.style.height		= this.height.toString() + 'px';

		if ((LPlib.browserSize().width < this.width) || (LPlib.browserSize().height < this.height)) {
			this.dlg.style.position		= 'absolute';
			this.dlg.style.marginLeft	= '0px';
			this.dlg.style.marginTop	= '5px';
			this.dlg.style.height		= (this.height+5).toString() + 'px';
			if (LPlib.browserSize().width < this.width) {
				this.dlg.style.left	= '0px';
			}else{
				this.dlg.style.left	= ((LPlib.browserSize().width-this.width)/2).toString() + 'px';
			}
			if (LPlib.is_ie && (!LPlib.is_ie7_2)) this.dlg.style.removeExpression('top');
			if (LPlib.browserSize().height < this.height) {
				this.dlg.style.top	= '0px';
			}else{
				this.dlg.style.top	= ((LPlib.browserSize().height-this.height)/2).toString() + 'px';
			}
			window.scrollTo(0,0);
		}else{
			this.dlg.style.position		= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
			this.dlg.style.left			= '50%';
			this.dlg.style.marginLeft	= (0-(this.width/2)).toString() + 'px';
			this.dlg.style.marginTop	= '0px';
			if (LPlib.is_ie && (!LPlib.is_ie7_2)) {
				this.dlg.style.setExpression('top', 'LPlib.body().scrollTop + Math.round((LPlib.body().clientHeight-this.style.pixelHeight)/2)' );
			}else{
				this.dlg.style.top			= '50%';
				this.dlg.style.marginTop	= (0-(this.height/2)).toString() + 'px';
			}
		}
	}

	// [public] Close for opened dialog
    this.close = function() {
    	if (!this.isOpen) return;
		if (this.dlg) this.dlg.style.visibility	= 'hidden';
		this.toggleBackground(false);
    }

	// [public] Change Message
	this.changeMsg = function (title, msg, buttons, closeFunction, buttonsClose) {
		this.dlg.style.visibility	= 'hidden';
		this.buttons		= buttons;
		if ((!buttonsClose) || (buttons.length!=buttonsClose.length)) {
			this.buttonsClose = [];
			for (var i=0; i<buttons.length; i++) this.buttonsClose.push(false);
		}else{
			this.buttonsClose = buttonsClose;
		}
		if ((closeFunction)&&(typeof(closeFunction)=='function')) {
			this.closeFunction = closeFunction;
		}else{
			this.closeFunction = null;
		}
		this.show(title, msg);
	}

	// [private] Create DOM element on window.onload
	this.createObject = function () {
		LPlib.objects.push(this);

		this.dlgBg					= this.document.createElement('DIV');
		this.dlgBg.setAttribute('id', this.id + '_bg');
		this.dlgBg.style.visibility	= 'hidden';
		this.dlgBg.style.position	= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
		this.dlgBg.style.zIndex		= LPlib.z_index++;
		this.dlgBg.style.left		= '0px';
		this.dlgBg.style.top		= '0px';
		this.dlgBg.className		= 'LayerPopupBackground';
		this.document.body.appendChild( this.dlgBg );

		this.dlg					= this.document.createElement('DIV');
		this.dlg.setAttribute('id', this.id);
		this.dlg.style.visibility	= 'hidden';
		this.dlg.style.position		= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
		this.dlg.style.zIndex		= LPlib.z_index++;
		this.dlg.style.left			= '0px';
		this.dlg.style.top			= '0px';
		this.dlg.className			= 'LayerPopupAlert';
		this.dlg.style.overflow		= 'hidden';
		LPlib.removeSelection(this.dlg);

		LPlib.addEvent( window, 'onresize', this.onResize.bind(this), false );
		this.document.body.appendChild( this.dlg );
		this.create					= true;
	}

	// [private] Browser Resize
	this.onResize = function () {
		if (this.isOpen) {
			this.setSize(this.width, this.height);
		}
	}

	// [private] Display on
	this.show = function (width, height, title, msg, showCloseBtn) {
		this.dlg.style.visibility	= 'hidden';
		this.setSize(width, height);
		this.selectButton = 0;

		var w = width.toString();
		var h = height.toString();
		var html = '';
		html	+= '<div class="LPlayerAlert" style="position:relative;width:'+w+'px;height:'+h+'px;">\n';
		html	+= '	<div style="position:absolute;top:0px;left:0px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_lt.gif);"></div>\n';
		html	+= '	<div style="position:absolute;top:0px;left:'+(width-10).toString()+'px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_rt.gif);"></div>\n';
		html	+= '	<div style="position:absolute;top:'+(height-10).toString()+'px;left:0px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_lb.gif);"></div>\n';
		html	+= '	<div style="position:absolute;top:'+(height-10).toString()+'px;left:'+(width-10).toString()+'px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_rb.gif);"></div>\n';
		html	+= '	<div class="LPalertBg" style="position:absolute;top:0px;left:10px;width:'+(width-20).toString()+'px;height:10px;"></div>\n';
		html	+= '	<div class="LPalertBg" style="position:absolute;top:'+(height-10).toString()+'px;left:10px;width:'+(width-20).toString()+'px;height:10px;"></div>\n';
		html	+= '	<div class="LPalertBg" style="position:absolute;top:10px;left:0px;width:'+w+'px;height:'+(height-20).toString()+'px;"></div>\n';
		var contHeight	= ( ((this.buttons) && (this.buttons.length)) ? (height-18-20-35) : (height-18-20) );
		html	+= '	<div class="LPalertContent" style="position:absolute;top:28px;left:10px;width:'+(width-20).toString()+'px;height:'+ contHeight.toString() +'px;"><table><tr><td>'+ ((msg)?msg:'') +'</td></tr></table></div>\n';
		if (title) {
			html	+= '	<div class="LPalertTitle" style="position:absolute;top:10px;left:10px;width:'+(width-20).toString()+'px;height:18px;">'+ title +'</div>\n';
		}
		if ((this.buttons) && (this.buttons.length)) {
			html	+= '	<div class="LPalertBtns" style="position:absolute;top:'+(height-45).toString()+'px;left:10px;width:'+(width-20).toString()+'px;height:35px;text-align:center;vertical-align:middle;">\n';
			for (var i=0; i<this.buttons.length; i++) {
				if ((!LPlib.is_ie) || (LPlib.is_ie8)) {
					html+= '<div class="LPalertButton" onclick="LPlib.getCurrentObject().selectButton='+ (i+1).toString() +';LPlib.close();"><img src="'+ LPlib.jsPath +'/img/btn_left.gif" alt=""/><div style="background-image:url('+ LPlib.jsPath +'/img/btn_bg.gif);">'+this.buttons[i]+'</div><img src="'+ LPlib.jsPath +'/img/btn_right.gif" alt=""/></div>';
				}else{
					html+= '<input type="button" value="'+this.buttons[i]+'" onclick="LPlib.getCurrentObject().selectButton='+ (i+1).toString() +';LPlib.close();"/>';
				}
			}
			html	+= '	</div>\n';
		}
		if (showCloseBtn==true) {
			html	+= '	<img src="'+ LPlib.jsPath +'/img/btn_x.gif" onclick="LPlib.close();" alt="閉じる" style="position:absolute;top:10px;left:'+(width-25).toString()+'px;display:block;width:15px;height:15px;cursor:pointer;"/>\n';
		}
		html	+= '</div>\n';
		this.dlg.innerHTML = html;
		this.dlg.style.visibility	= 'visible';
	}

	// [private] Toggle background overlay
    this.toggleBackground = function (on) {
		this.dlgBg.style.width	= '100%';
		if (LPlib.is_ie && (!LPlib.is_ie7_2)) {
			this.dlgBg.style.setExpression('height', 'LPlib.getBgSize().height' );
		}else{
			this.dlgBg.style.height	= '100%';
		}
		if (on) {
			this.fadeInBackground();
		}else{
			this.fadeOutBackground();
		}
    }

	// [private] Fade out effect of background overlay
    this.fadeOutBackground = function () {
		if (this.fade.speed > 0) {
			if (!this.fade.run) {
				this.fade.run		= true;
				this.fade.target	= 0;
			}
			var opacity	= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
			if (opacity > this.fade.target) {
				var step = ((opacity-this.fade.target)<this.fade.step) ? (opacity-this.fade.target) : this.fade.step;
				this.dlgBg.style.opacity	= (opacity - step).toString();
				this.dlgBg.style.filter		= 'alpha(Opacity=' + ((opacity-step)*100).toString() + ')';
				this.fade.handle = window.setTimeout( this.fadeOutBackground.bind(this), this.fade.speed/2 );
				return;
			}
			window.clearTimeout(this.fade.handle);
			this.fade.run	= false;
		}
		this.dlgBg.style.visibility	= 'hidden';
		this.dlgBg.style.opacity	= this.fade.opacity.toString();
		this.dlgBg.style.filter		= 'alpha(Opacity=' + (this.fade.opacity*100).toString() + ')';
		//this.dlgBg.style.height	= '10px';
		//this.dlg.style.height		= '10px';
		LPlib.toggleTroubleElements(true);
		this.dlgBg.onclick = null;
		this.isOpen	= false;
		if ((this.closeFunction)&&(typeof(this.closeFunction)=='function')) {
			this.closeFunction(this.selectButton);
		}
	}

    // [private] Fade in effect of background overlay
	this.fadeInBackground = function () {
		if (this.fade.speed > 0) {
			if (!this.fade.run) {
				LPlib.toggleTroubleElements(false);
				this.fade.run		= true;
				this.fade.target	= this.fade.opacity;
				this.dlgBg.style.visibility	= 'visible';
				this.dlgBg.style.opacity	= '0';
				this.dlgBg.style.filter		= 'alpha(Opacity=0)';
				this.fade.handle = window.setTimeout( this.fadeInBackground.bind(this), this.fade.speed );
				return;
			}
			var opacity	= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
			if (opacity < this.fade.target) {
				var step = ((this.fade.target-opacity)<this.fade.step) ? (this.fade.target-opacity) : this.fade.step;
				this.dlgBg.style.opacity	= (opacity + step).toString();
				this.dlgBg.style.filter		= 'alpha(Opacity=' + ((opacity+step)*100).toString() + ')';
				this.fade.handle = window.setTimeout( this.fadeInBackground.bind(this), this.fade.speed );
				return;
			}
			window.clearTimeout(this.fade.handle);
			this.fade.run	= false;
		}else{
			LPlib.toggleTroubleElements(false);
			this.dlgBg.style.visibility	= 'visible';
		}
		this.dlgBg.onclick = ( this.fade.arguments.autoClose ? this.close.bind(this) : null );
		this.show(this.fade.arguments.width, this.fade.arguments.height, this.fade.arguments.title, this.fade.arguments.msg, this.fade.arguments.showCloseBtn);
	}

	// run this object
	LPlib.addEvent( window, 'onload', this.createObject.bind(this), false );

}



/*******************************************************************************
 * LayerImage object ( Message display )
 ******************************************************************************/

var LayerImage = function (id) {

	this.dlg			= null;				// Dialog element
	this.dlgBg			= null;				// Background overlay element
	this.document		= self.document;
	this.id				= id;
	this.width			= 0;
	this.height			= 0;
	this.autoClose		= true;
	this.isOpen			= false;
	this.fade			= { speed:20, step:0.15, run:false };
	this.closeFunction	= null;
	this.init			= false;
	this.create			= false;

	// Preload Images
	LPlib.preloadImages( LPlib.jsPath+'/img/box_lt.gif', LPlib.jsPath+'/img/box_rt.gif', LPlib.jsPath+'/img/box_lb.gif', LPlib.jsPath+'/img/box_rb.gif',
		LPlib.jsPath+'/img/btn_x.gif', LPlib.jsPath+'/img/btn_left.gif', LPlib.jsPath+'/img/btn_right.gif', LPlib.jsPath+'/img/btn_bg.gif' );

	// [public] Open dialog
    this.open = function (imgWidth, imgHeight, title, img, alt, autoClose, fadeSpeed) {
    	if (!this.init) {
    		if ( (!this.create) || (LPlib.getStyle(this.dlgBg,'background-color')=='')
    			|| (LPlib.getStyle(this.dlgBg,'background-color') == 'transparent') || (parseFloat(LPlib.getStyle(this.dlgBg,'opacity')) == 1) ) {
    			window.setTimeout( (function(){this.open.bind(this)(imgWidth, imgHeight, title, img, alt, autoClose, fadeSpeed)}).bind(this), 50 );
    			return;
    		}
    		this.init = true;
    	}
    	
		// Calculate Popup size form image size
		imgWidth = parseInt(imgWidth); imgHeight = parseInt(imgHeight);
		var maxSize = { width : (LPlib.browserSize().width-20-20), height : (LPlib.browserSize().height-20-38) };
		if ((imgWidth/imgHeight) > (maxSize.width/maxSize.height)) {
			var resizeWidth		= (imgWidth>maxSize.width) ? maxSize.width : imgWidth;
			var resizeHeight	= parseInt(imgHeight*resizeWidth/imgWidth);
		}else{
			var resizeHeight	= (imgHeight>maxSize.height) ? maxSize.height : imgHeight;
			var resizeWidth		= parseInt(imgWidth*resizeHeight/imgHeight);
		}
		var width	= resizeWidth + 20;
		var height	= resizeHeight + 38;
    	
		this.isOpen				= true;
		this.autoClose			= autoClose;
		this.fade.opacity		= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
		this.fade.speed			= ( (!fadeSpeed && (fadeSpeed!==0)) ? this.fade.speed	 : parseInt(fadeSpeed) );
		this.fade.arguments		= {width:width, height:height, title:title, img:img, alt:alt, autoClose:autoClose};

		this.toggleBackground(true);
		if (this.fade.speed == 0) this.show(width, height, title, img, alt);
	}

	// [public] Resize for opened dialog
	this.setSize = function (width, height) {
		this.width		= parseInt(width);
		this.height		= parseInt(height);

		this.dlg.style.width		= this.width.toString() + 'px';
		this.dlg.style.height		= this.height.toString() + 'px';

		if ((LPlib.browserSize().width < this.width) || (LPlib.browserSize().height < this.height)) {
			this.dlg.style.position		= 'absolute';
			this.dlg.style.marginLeft	= '0px';
			this.dlg.style.marginTop	= '5px';
			this.dlg.style.height		= (height+5).toString() + 'px';
			if (LPlib.browserSize().width < this.width) {
				this.dlg.style.left	= '0px';
			}else{
				this.dlg.style.left	= ((LPlib.browserSize().width-this.width)/2).toString() + 'px';
			}
			if (LPlib.is_ie && (!LPlib.is_ie7_2)) {
				this.dlg.style.removeExpression('left');
				this.dlg.style.removeExpression('top');
			}
			if (LPlib.browserSize().height < this.height) {
				this.dlg.style.top	= '0px';
			}else{
				this.dlg.style.top	= ((LPlib.browserSize().height-this.height)/2).toString() + 'px';
			}
			window.scrollTo(0,0);
		}else{
			this.dlg.style.position		= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
			this.dlg.style.left			= '50%';
			this.dlg.style.marginLeft	= (0-(this.width/2)).toString() + 'px';
			this.dlg.style.marginTop	= '0px';
			if (LPlib.is_ie && (!LPlib.is_ie7_2)) {
				this.dlg.style.setExpression('top', 'LPlib.body().scrollTop + Math.round((LPlib.body().clientHeight-this.style.pixelHeight)/2)' );
			}else{
				this.dlg.style.top			= '50%';
				this.dlg.style.marginTop	= (0-(this.height/2)).toString() + 'px';
			}
		}

	}

	// [public] Close for opened dialog
    this.close = function() {
    	if (!this.isOpen) return;
		if ((this.closeFunction)&&(typeof(this.closeFunction)=='function')) {
			if (!this.closeFunction()) return;
		}
		if (this.dlg) this.dlg.style.visibility	= 'hidden';
		this.toggleBackground(false);
    }

	// [private] Create DOM element on window.onload
	this.createObject = function () {
		LPlib.objects.push(this);

		this.dlgBg					= this.document.createElement('DIV');
		this.dlgBg.setAttribute('id', this.id + '_bg');
		this.dlgBg.style.visibility	= 'hidden';
		this.dlgBg.style.position	= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
		this.dlgBg.style.zIndex		= LPlib.z_index++;
		this.dlgBg.style.left		= '0px';
		this.dlgBg.style.top		= '0px';
		this.dlgBg.className		= 'LayerPopupBackground';
		this.document.body.appendChild( this.dlgBg );

		this.dlg					= this.document.createElement('DIV');
		this.dlg.setAttribute('id', this.id);
		this.dlg.style.visibility	= 'hidden';
		this.dlg.style.position		= (LPlib.is_ie && !LPlib.is_ie7_2) ? 'absolute' : 'fixed';
		this.dlg.style.zIndex		= LPlib.z_index++;
		this.dlg.style.left			= '0px';
		this.dlg.style.top			= '0px';
		this.dlg.style.overflow		= 'hidden';
		this.dlg.className			= 'LayerPopupAlert';
		LPlib.removeSelection(this.dlg);

		LPlib.addEvent( window, 'onresize', this.onResize.bind(this), false );
		this.document.body.appendChild( this.dlg );

		this.create					= true;
	}

	// [private] Browser Resize
	this.onResize = function () {
		if (this.isOpen) {
			this.setSize(this.width, this.height);
		}
	}

	// [private] Display on
	this.show = function (width, height, title, img, alt) {
		this.dlg.style.visibility	= 'hidden';
		this.setSize(width, height);

		var w = width.toString();
		var h = height.toString();
		var html = '';
		html	+= '<div class="LPlayerImage" style="position:relative;width:'+w+'px;height:'+h+'px;">\n';
		html	+= '	<div style="position:absolute;top:0px;left:0px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_lt.gif);"></div>\n';
		html	+= '	<div style="position:absolute;top:0px;left:'+(width-10).toString()+'px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_rt.gif);"></div>\n';
		html	+= '	<div style="position:absolute;top:'+(height-10).toString()+'px;left:0px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_lb.gif);"></div>\n';
		html	+= '	<div style="position:absolute;top:'+(height-10).toString()+'px;left:'+(width-10).toString()+'px;width:10px;height:10px;background-image:url('+ LPlib.jsPath +'/img/box_rb.gif);"></div>\n';
		html	+= '	<div class="LPalertBg" style="position:absolute;top:0px;left:10px;width:'+(width-20).toString()+'px;height:10px;"></div>\n';
		html	+= '	<div class="LPalertBg" style="position:absolute;top:'+(height-10).toString()+'px;left:10px;width:'+(width-20).toString()+'px;height:10px;"></div>\n';
		html	+= '	<div class="LPalertBg" style="position:absolute;top:10px;left:0px;width:'+w+'px;height:'+(height-20).toString()+'px;"></div>\n';
		html	+= '	<div style="position:absolute;top:28px;left:10px;width:'+(width-20).toString()+'px;height:'+ (height-38).toString() +'px;">';
			if (this.autoClose) {
				html += '<img src="'+ img +'" width="'+ (width-20).toString() +'" height="'+ (height-38).toString() +'" alt="'+ alt +'" onclick="LPlib.close();" style="cursor:pointer;" />';
			}else{
				html += '<img src="'+ img +'" width="'+ (width-20).toString() +'" height="'+ (height-38).toString() +'" alt="'+ alt +'" />';
			}
		html	+= '	</div>\n';
		if (title) {
			html	+= '	<div class="LPalertTitle" style="position:absolute;top:10px;left:10px;width:'+(width-20).toString()+'px;height:18px;">'+ title +'</div>\n';
		}
		html	+= '	<img src="'+ LPlib.jsPath +'/img/btn_x.gif" onclick="LPlib.close();" alt="閉じる" style="position:absolute;top:10px;left:'+(width-25).toString()+'px;display:block;width:15px;height:15px;cursor:pointer;"/>\n';
		html	+= '</div>\n';
		
		this.dlg.innerHTML = html;
		this.dlg.style.visibility	= 'visible';
	}

	// [private] Toggle background overlay
    this.toggleBackground = function (on) {
		this.dlgBg.style.width	= '100%';
		if (LPlib.is_ie && (!LPlib.is_ie7_2)) {
			this.dlgBg.style.setExpression('height', 'LPlib.getBgSize().height' );
		}else{
			this.dlgBg.style.height	= '100%';
		}
		if (on) {
			this.fadeInBackground();
		}else{
			this.fadeOutBackground();
		}
    }

	// [private] Fade out effect of background overlay
    this.fadeOutBackground = function () {
		if (this.fade.speed > 0) {
			if (!this.fade.run) {
				this.fade.run		= true;
				this.fade.target	= 0;
			}
			var opacity	= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
			if (opacity > this.fade.target) {
				var step = ((opacity-this.fade.target)<this.fade.step) ? (opacity-this.fade.target) : this.fade.step;
				this.dlgBg.style.opacity	= (opacity - step).toString();
				this.dlgBg.style.filter		= 'alpha(Opacity=' + ((opacity-step)*100).toString() + ')';
				this.fade.handle = window.setTimeout( this.fadeOutBackground.bind(this), this.fade.speed/2 );
				return;
			}
			window.clearTimeout(this.fade.handle);
			this.fade.run	= false;
		}
		this.dlgBg.style.visibility	= 'hidden';
		this.dlgBg.style.opacity	= this.fade.opacity.toString();
		this.dlgBg.style.filter		= 'alpha(Opacity=' + (this.fade.opacity*100).toString() + ')';
		//this.dlgBg.style.height	= '10px';
		//this.dlg.style.height		= '10px';
		LPlib.toggleTroubleElements(true);
		this.dlgBg.onclick = null;
		this.isOpen	= false;
	}

    // [private] Fade in effect of background overlay
	this.fadeInBackground = function () {
		if (this.fade.speed > 0) {
			if (!this.fade.run) {
				LPlib.toggleTroubleElements(false);
				this.fade.run		= true;
				this.fade.target	= this.fade.opacity;
				this.dlgBg.style.visibility	= 'visible';
				this.dlgBg.style.opacity	= '0';
				this.dlgBg.style.filter		= 'alpha(Opacity=0)';
				this.fade.handle = window.setTimeout( this.fadeInBackground.bind(this), this.fade.speed );
				return;
			}
			var opacity	= parseFloat(LPlib.getStyle(this.dlgBg,'opacity'));
			if (opacity < this.fade.target) {
				var step = ((this.fade.target-opacity)<this.fade.step) ? (this.fade.target-opacity) : this.fade.step;
				this.dlgBg.style.opacity	= (opacity + step).toString();
				this.dlgBg.style.filter		= 'alpha(Opacity=' + ((opacity+step)*100).toString() + ')';
				this.fade.handle = window.setTimeout( this.fadeInBackground.bind(this), this.fade.speed );
				return;
			}
			window.clearTimeout(this.fade.handle);
			this.fade.run	= false;
		}else{
			LPlib.toggleTroubleElements(false);
			this.dlgBg.style.visibility	= 'visible';
		}
		this.dlgBg.onclick = ( this.fade.arguments.autoClose ? this.close.bind(this) : null );
		this.show(this.fade.arguments.width, this.fade.arguments.height, this.fade.arguments.title, this.fade.arguments.img, this.fade.arguments.alt );
	}

	// run this object
	LPlib.addEvent( window, 'onload', this.createObject.bind(this), false );

}


// Replace 'this' prototype  for functions
Function.prototype.bind = function( thisObj ) {
	var method = this;
	return function() {
		method.apply(thisObj, arguments);
	}
}


//var layerPopup	= new LayerPopup('LayerPopup');
var layerAlert		= new LayerAlert('LayerAlert');
var LayerImage		= new LayerImage('LayerImage');
