/**
 * @use 螳��� ���� ��襦������朱� ���������給����.
 * @author cielo
 * @See nhn.husky.SE2M_Configuration 
 * @ ���� 襷������� SimplePhotoUpload.html螻� SimplePhotoUpload_html5.html�� ���給����. 
 */

nhn.husky.SE2M_AttachQuickPhoto = jindo.$Class({		
	name : "SE2M_AttachQuickPhoto",

	$init : function(){},
	
	$ON_MSG_APP_READY : function(){
		this.oApp.exec("REGISTER_UI_EVENT", ["photo_attach", "click", "ATTACHPHOTO_OPEN_WINDOW"]);
	},
	
	$LOCAL_BEFORE_FIRST : function(sMsg){
		if(!!this.oPopupMgr){ return; }
		// Popup Manager���� ������ param
		this.htPopupOption = {
			oApp : this.oApp,
			sName : this.name,
			bScroll : false,
			sProperties : "",
			sUrl : ""
		};
		this.oPopupMgr = nhn.husky.PopUpManager.getInstance(this.oApp);
	},
	
	/**
	 * ���� �麹�� �ろ��
	 */
	$ON_ATTACHPHOTO_OPEN_WINDOW : function(){			
		this.htPopupOption.sUrl = this.makePopupURL();
		//this.htPopupOption.sProperties = "left=0,top=0,width=640,height=459,scrollbars=yes,location=no,status=0,resizable=no";
        this.htPopupOption.sProperties = "left="+(screen.width-640)/2+", top="+(screen.height-459)/2+",width=640,height=459,scrollbars=yes,location=no,status=0,resizable=no";

		this.oPopupWindow = this.oPopupMgr.openWindow(this.htPopupOption);
		
		// 豌��� 襦�����螻� IE���� 貉れ��螳� ���� ���� 蟆曙��
		// 覲旧�� ��襦������� ����螳� 覦���	
		this.oApp.exec('FOCUS');
		return (!!this.oPopupWindow ? true : false);
	},
	
	/**
	 * ��觜��る�襦� ������  parameter襯� 豢�螳����� URL�� ���燕���� ����	 
	 * nhn.husky.SE2M_AttachQuickPhoto.prototype.makePopupURL襦� ���伎���� ��������覃� ��.
	 */
	makePopupURL : function(){
		//var sPopupUrl = "./photo_uploader/popup/photo_uploader.html";
		var sPopupUrl = "./photo_uploader/popup/index.html";
		return sPopupUrl;
	},
	
	/**
	 * �������� �語����� 覃��語�.
	 */
	$ON_SET_PHOTO : function(aPhotoData){
		var sContents, 
			aPhotoInfo,
			htData;
		
		if( !aPhotoData ){ 
			return; 
		}
		
		try{
			sContents = "";
			for(var i = 0; i <aPhotoData.length; i++){				
				htData = aPhotoData[i];
				
				if(!htData.sAlign){
					htData.sAlign = "";
				}
				
				aPhotoInfo = {
				    sName : htData.sFileName || "",
				    sOriginalImageURL : htData.sFileURL,
					bNewLine : htData.bNewLine || false 
				};
				
				sContents += this._getPhotoTag(aPhotoInfo);
			}

			this.oApp.exec("PASTE_HTML", [sContents]); // ��讀� 豌�� ���� 覿�覿� ����
		}catch(e){
			// upload�� error覦����� ���伎�� skip��
			return false;
		}
	},

	/**
	 * @use �朱� ���� tag ����
	 */
	_getPhotoTag : function(htPhotoInfo){
		// id�� class�� �碁�れ�手骸 �郁��� 襷��給����. ������ �碁�れ�� ���㈲� Test
		var sTag = '<img src="{=sOriginalImageURL}" title="{=sName}" >';
		if(htPhotoInfo.bNewLine){
			sTag += '<br style="clear:both;">';
		}
		sTag = jindo.$Template(sTag).process(htPhotoInfo);
		
		return sTag;
	}
});