var Layerpop =
{
	docSize : function ()
	{
		var b=document.body, e=document.documentElement;
		var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
		if (e)
		{
			esw = e.scrollWidth;
			eow = e.offsetWidth;
			esh = e.scrollHeight;
			eoh = e.offsetHeight;
		}
		if (b)
		{
			bsw = b.scrollWidth;
			bow = b.offsetWidth;
			bsh = b.scrollHeight;
			boh = b.offsetHeight;
		}
		//  alert('compatMode: ' + document.compatMode + '\n\ndocumentElement.scrollHeight: ' + esh + '\ndocumentElement.offsetHeight: ' + eoh + '\nbody.scrollHeight: ' + bsh + '\nbody.offsetHeight: ' + boh + '\n\ndocumentElement.scrollWidth: ' + esw + '\ndocumentElement.offsetWidth: ' + eow + '\nbody.scrollWidth: ' + bsw + '\nbody.offsetWidth: ' + bow);
		return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
	},

	insertDiv : function ()
	{
		var page_size	= this.docSize();
		var page_width	= page_size.w;
		//var page_height = page_size.h + 118 ;
		var page_height = page_size.h ;


/*
		document.write ('<div id="lp_film" style="z-index: 99997; display:none; position: absolute; top:0px; left:0px; width:'+page_width+'px; height:'+page_height+'px; background-color: black ; filter:alpha(opacity=30);-moz-opacity:.30;opacity:.30;" ></div>');

		document.write ('<div id="lp_body" style="z-index: 99999; display:none; position: absolute; top:0px; left:0px; background-color: white ;" ></div>');
*/


		var div_film = new Element ('div' , { id : 'lp_film' });

		div_film.setStyle({
			zIndex : '99995',
			display : 'none',
			position : 'absolute',
			top : '0px',
			left : '0px',
			width : page_width,
			height : page_height,
			backgroundColor : 'black',
			//backgroundColor : 'silver',
			//backgroundColor : 'white',
			opacity : 0.3
		});


		var div_body = new Element ('div' , { id : 'lp_body' });

		div_body.setStyle({
			zIndex : '99997',
			display : 'none',
			position : 'absolute',
			top : '0px',
			left : '0px',
			backgroundColor : ''
		});

		if ( ! $('lp_film') ) $(document.body).insert(div_film);
		if ( ! $('lp_body') ) $(document.body).insert(div_body);


	},


	//-- for ie6
	insertIframe : function ()
	{
		var dimensions = $('lp_body').getDimensions();
		var positions = $('lp_body').positionedOffset();

		var iframe_bg = new Element ('iframe' , { id : 'iframe_bg' });

		iframe_bg.setStyle({
			zIndex : '99993',
			display : 'block',
			position : 'absolute',
			top : positions.top+'px',
			left : positions.left+'px',
			width : dimensions.width+'px',
			height : dimensions.height+'px',
			backgroundColor : '',
			border: 0
		})

		window.setTimeout(function() {
			iframe_bg.setStyle({
				zIndex : '99993',
				display : 'block',
				position : 'absolute',
				top : positions.top+'px',
				left : positions.left+'px',
				width : dimensions.width+'px',
				height : dimensions.height+'px',
				backgroundColor : ''
			})
		} , 300);

		if ( ! $('iframe_bg') ) $(document.body).insert(iframe_bg);
	},


	center : function ( id )
	{
		var page_size		= this.docSize();
		var page_width		= page_size.w;
		var page_height		= page_size.h ;

		var dimensions		= $(id).getDimensions();
		var top_lp_body		= document.documentElement.scrollTop + ( ( document.viewport.getHeight() - dimensions.height ) / 2 );
		var left_lp_body	= document.documentElement.scrollLeft + ( ( page_width - dimensions.width ) / 2 );


		if ($('lp_film'))
		{
			$('lp_film').setStyle({
				width : page_width+'px',
				height : page_height+'px'
			});
		}


		$(id).setStyle({
			top : top_lp_body+'px',
			left : left_lp_body+'px',
			width : dimensions.width+'px',
			height : dimensions.height+'px'
		});
	},


	open : function ( body , opct , timeout )
	{
		var film_opacity = opct || 0.3 ;
		//var film_opacity = opct || 0.3 ;
		//var film_opacity = opct || 0 ;

		this.insertDiv();

		$('lp_body').update(body);

		this.center ('lp_body');

		$('lp_film').setStyle({
			opacity: film_opacity
		});

		$('lp_film').show();
		$('lp_body').show();

		//-----------------------------------------------

		BrowserDetect.init();

		if ( BrowserDetect.browser == 'Explorer' && ( BrowserDetect.version == '5.5' || BrowserDetect.version == '6' ) )
		{
			this.insertIframe();
		}

		//-----------------------------------------------



		if (timeout)
		{
			setTimeout ( "Layerpop.close();" , timeout );
		}
	},


	box : function ( txt )
	{
		var box_html = '<div id="popwin_dataetc"><table border="0" cellspacing="0" cellpadding="0"><tr><td width="12" height="12"><img src="'+Vars.img_g+'/box/box1_topleft.gif" width="12" height="12" /></td><td background="'+Vars.img_g+'/box/box1_topbg.gif" ></td><td width="12" height="12"><img src="'+Vars.img_g+'/box/box1_topright.gif" width="12" height="12" /></td></tr><tr><td background="'+Vars.img_g+'/box/box1_leftbg.gif">&nbsp;</td><td bgcolor="#FFFFFF" height="30" align="center">'+txt+'</td><td background="'+Vars.img_g+'/box/box1_rightbg.gif" no-repeat="no-repeat" right="right" 0>&nbsp;</td></tr><tr><td width="12" height="12"><img src="'+Vars.img_g+'/box/box1_botleft.gif" /></td><td background="'+Vars.img_g+'/box/box1_botbg.gif" height="12"></td><td width="12" height="12"><img src="'+Vars.img_g+'/box/box1_botright.gif" width="12" height="12" /></td></tr></table></div>';

		this.open ( box_html );
	},

	noti : function ( txt )
	{
		var html = '\
			<div id="login_error">\
			<div class="popbg_top_left"></div>\
			<div class="popbg_top_right" style="width:400px"></div>\
			<div class="popbg_mid3" style="width:374px">\
			<div class="pop_info_img"><img src="'+Vars.img_g+'/ico/ico_series_book.jpg" alt="" /></div>\
			<div class="pop_info_txt">'+txt+'</div>\
			<div class="pop_info_close"><img src="'+Vars.img_l+'/btn/btn_ok.gif" alt="확인" onclick="Layerpop.close();" style="cursor:pointer"/></div>\
			</div>\
			<div class="popbg_bot_left"></div>\
			<div class="popbg_bot_right" style="width:400px"></div>\
			</div>\
		';

		this.open ( html );
	},


	blink : function ( txt )
	{
		var box_html = '<div id="popwin_dataetc"><div class="popbg_top_left"></div><div class="popbg_top_right" style="width:200px"></div><div class="popbg_mid3" style="width:174px">'+txt+'</div><div class="popbg_bot_left"></div><div class="popbg_bot_right" style="width:200px"></div></div>';

		//this.open ( box_html , 0.10 , 1200 );
		this.open ( box_html , 0 , 1200 );
	},


	close :function ()
	{
		$('lp_film').hide();
		//$('lp_body').hide();

		//$('lp_film').remove();
		$('lp_body').remove();

		if ($('iframe_bg'))
		{
			$('iframe_bg').remove();
		}
	}
};

//Layerpop.insertDiv();
