﻿/*========================================
#사용제약
사용시 "공대여자는 예쁘다"를 나타내셔야합니다.

만든날 : 2007-06-11
수정일 : 2007-06-18
만든이 : mins01,mins,공대여자
홈페이지 : http://mins01.zerock.net 
NateOn&MSN : mins01(at)lycos.co.kr
========================================*/

var js_layer = function (ta){
	var layer = null; //대상 레이어

	this.init();

	if(ta) this.replaceLayer(ta);
	else   this.createLayer();
}

//============================================== 클래스 초기화
js_layer.prototype.init = function(){
	this.setBrowser();
}

//============================================== 브라우저 체크
js_layer.prototype.setBrowser = function(){
// 브라우저가 IE인지 체크 : IE=0,FF=1,OPERA=2,그외=255;
	var ua = window.navigator.userAgent;

	if(ua.indexOf('Firefox')!=-1)    this.browser=1;
	else if(ua.indexOf('Opera')!=-1) this.browser=2;
	else if(ua.indexOf('MSIE')!=-1)  this.browser=0;	
	else if(document.all)            this.browser=0; // FF,OPERA를 구분후 기타 나머지는 IE호환 브라우저로 치부
	else                             this.browser=255;
}

//============================================== 경고메세지(디버그용)
js_layer.prototype.alert = function(msg){
	alert(msg);
}

//============================================== 기본 레이어 생성
js_layer.prototype.createLayer = function(){
	this.removeLayer();
	var cssText="background-color:#ffccff;border:1px solid #cccccc;position:absolute;left:50px;top:50px;width:100px;height:50px;";
	var La = document.createElement('div');
	La.style.cssText=cssText
	this.layer = La;
	this.appendLayer();
}

//============================================== 레이어 삭제
js_layer.prototype.removeLayer = function(){
	if(this.layer!=null) this.layer.parentNode.removeChild(this.layer);
}

//============================================== 레이어 대체
js_layer.prototype.replaceLayer = function(ta){
//	this.removeLayer();

	if(ta.nodeType==1){
		this.layer = ta;
	}else{
		var La = document.getElementById(ta);

		if(La) this.layer = La;
		else this.alert('ERROR : replaceLayer()');
	}
}

//============================================== body에 레이어 붙임(이때부터 레이어가 페이지에서 보임)
js_layer.prototype.appendLayer = function(){
	if(!this.layer){this.alert('ERROR : appendLayer');return false;}
	document.body.appendChild(this.layer);
}

//============================================== left,top의 위치를 설정함
js_layer.prototype.setPosition  = function(left,top){

	if(this.layer.style.display == 'none') this.layer.style.display = 'block';
	else  this.layer.style.display = 'none';

	if(!this.layer){this.alert('ERROR : setPosition');return false;}
	if(left!=null)	this.layer.style.left = this.parseInt(left)+'px';
	if(top!=null)	this.layer.style.top = this.parseInt(top)+'px';
}

//============================================== 문자열을 숫자로 바꾸고 체크하고 반환
js_layer.prototype.parseInt = function(num){
	var num = parseInt(num);
	if(isNaN(num)){return 0;}
	else{return num;}
}
