/**=======================================================================================
*				The APMSOFT Template AJAX SOLUTION License, version 1.0
*			Copyright (c) 2006 김종관(ApmSoft.net). All rights reserved......
*
*=============+================+===========================+=============================+
*    개발자   |     연락처     |          홈페이지         |            Editor           |
*-------------+----------------+---------------------------+-----------------------------+
*    김종관   |  011-726-7046  |   http://www.apmsoft.net  | EditPlus 굴림체 Regular 9pt |
*-------------+----------------+---------------------------+-----------------------------+
* ▣ 사용목적
* = 풍선도움말
* = utf-8
* = Ex :7, Opera : 9.10, FF : 2.x
* = update : 2007-04-20
-----------------------------------------------------------------------------------------*/
var balloon = {};
balloon.ApmSoftNet = {};

/**
	@ callback	: 되돌아갈 함수명
	@ divid		: 현재위치 파악할 아이디
	@ params	: callback으로 다시 리턴해 줄 값
	@ w			: 창 넓이
	@ h			: 창 높이
	@ mode		: 생성, 감춤등 모드
	@ skin		: 적용할 스킨명
	@ arrowImgSrc:화살표경로
	@ padAddXY	: 추가로 XY위치 벌리기
*/
balloon.ApmSoftNet.ALTZ = function(callback, divid, params, w,h, mode, skin, arrowImgSrc,padAddXY)
{
	this.callback	= callback;
	this.chkid		= divid;
	this.params		= params;

	this.dndid		= 'balloon';
	this.arrowid	= 'balloonarrow';
	this.skin		= (skin) ? skin : 'default';
	this.width		= w;
	this.height		= h;
	this.mode		= mode;

	// 창 위치
	this.paddingX	= 10;
	this.paddingY	= 30;

	// 화살표 위치
	this.arrowPadX	= 20;
	this.arrowPadY	= 9;

	// 추가 패딩
	this.padAX = 0;
	this.padAY = 0;

	if (padAddXY){
		var txy = padAddXY.split(':');
		this.padAX = parseInt(txy[0]);
		this.padAY = parseInt(txy[1]);
	}

	this.binData		= '';
	this.binArrowData	= '';
	this.binArrowSrc	= (arrowImgSrc) ? arrowImgSrc : '../';

	this.x	= 0;
	this.y	= 0;
	this.arrowx	= 0;
	this.arrowy = 0;

	this.screenW = document.body.clientWidth;
	this.screenH = document.body.clientHeight;

	this.getChkIdXY();
}

balloon.ApmSoftNet.ALTZ.prototype =
{
	// 풍성 도움말 레이어 생성 및 위치값 재 조정
	display : function ()
	{
		// 스킨 설정
		this.setSkin();

		if (!document.getElementById(this.dndid))
		{
			if (this.binArrowSrc != 'none')
			{
				var binArrow = document.createElement('DIV');
				binArrow.innerHTML = this.binArrowData;
				document.body.appendChild(binArrow);
			}

			var bin = document.createElement('DIV');
			bin.innerHTML = this.binData;
			document.body.appendChild(bin);
		}else{
			if (this.binArrowSrc != 'none')
			{
				var binArrow = document.getElementById(this.arrowid);

				if (binArrow){
					binArrow.style.left	= this.arrowx+"px";
					binArrow.style.top	= this.arrowy+"px";
					binArrow.style.visibility = 'visible';
				}else{
					var binArrow = document.createElement('DIV');
					binArrow.innerHTML = this.binArrowData;
					document.body.appendChild(binArrow);
					
					//binArrow.style.visibility = 'visible';
				}
			}


			var bin = document.getElementById(this.dndid);

			bin.style.zIndex=2;
			bin.style.visibility = 'visible';
			bin.style.left	= this.x+"px";
			bin.style.top	= this.y+"px";
			bin.style.width	= this.width+"px";
			bin.style.height= this.height+"px";
		}

		if (this.callback){
			this.callback(this.mode, this.params);
		}
	},

	// 클릭 위치 아디 X,Y 축 위치 값 가져오기
	getChkIdXY : function ()
	{
		varObject = document.getElementById(this.chkid);

		// 브라우저 체크
		if(new RegExp(/Firefox/).test(navigator.userAgent)){
			var idx = mouse.GUI.getX(varObject);
			var idy = mouse.GUI.getY(varObject);
		}else if(new RegExp(/MSIE/).test(navigator.userAgent)){
			var idx = mouse.GUI.getX(varObject);
			var idy = mouse.GUI.getY(varObject);
		}else{	
			var idx = varObject.scrollLeft;
			var idy = varObject.scrollTop;
		}

		var tmpX = parseInt(idx + this.width);

		// left
		if (idx < this.paddingX){
			this.x = idx + this.padAX;
		}else if (tmpX > this.screenW)	{
			var tmpSX = parseInt(tmpX - (this.screenW - 10));

			this.x = parseInt(idx - tmpSX) + this.padAX;
			this.arrowx = (idx + this.arrowPadX) + this.padAX;

			//alert((idx+this.width)+' '+this.screenW);
		}else{
			this.x = (idx + this.paddingX) + this.padAX;
			this.arrowx = (idx + this.arrowPadX) + this.padAX;
		}

		// top
		if (idy < this.paddingY){
			this.y = idy + this.padAY;
		}else{
			this.y = (idy + this.paddingY) + this.padAY;
			this.arrowy = (idy + this.arrowPadY) + this.padAY;
		}

		//alert(this.chkid+' 위치 : '+this.x+' '+this.y);
		this.display();
	},

	// 스킨
	setSkin : function ()
	{
		switch (this.skin)
		{
			case 'round' :
				this.binData = "<div id='"+this.dndid+"' style='position:absolute; z-index:2;left:"+this.x+"px;top:"+this.y+"px;width:"+this.width+";height:"+this.height+";filter:alpha(opacity:92);'>";
				this.binData+= '<b class="rndtop"><b class="rnd1"></b><b class="rnd2"></b><b class="rnd3"></b><b class="rnd4"></b></b>';
				this.binData+= '<div class="canvas" id="'+this.dndid+'contents">';
				this.binData+= "&nbsp;&nbsp;";
				this.binData+= '</div>';
				this.binData+= '<b class="rndbottom"><b class="rnd4"></b><b class="rnd3"></b><b class="rnd2"></b><b class="rnd1"></b></b>';
				this.binData+= '</div>';
			break;

			default :
				this.binData = "<div id='"+this.dndid+"' style='position:absolute; z-index:2;left:"+this.x+"px;top:"+this.y+"px;width:"+this.width+";height:"+this.height+";filter:alpha(opacity:92);'>";
				this.binData+= '<div id="'+this.dndid+'contents">';
				this.binData+= "&nbsp;&nbsp;";
				this.binData+= '</div>';
				this.binData+= '</div>';

		}

		if (this.binArrowSrc != 'none')
		{
			this.binArrowData = "<div id='"+this.arrowid+"' style='position:absolute; z-index:2;left:"+this.arrowx+"px;top:"+this.arrowy+"px;'>";
			this.binArrowData+= '<img src="'+this.binArrowSrc+'/scripts/img/balloon/arrow.gif">';
			this.binArrowData+= '</div>';
		}
	}
}
