var Uploader = 
{
	UDIR : getComponentURL('_UpLoader'),
	SwfID : 'Uploader',
	fileName : null,
	setMember : function ()
	{
		this.swfFile = this.UDIR +'_SWF/upload.swf';	
	},
	
	setFileType : function (Obj, Path)
	{
	   var 	Type 		= (isString(Obj)) ? Obj : Obj.Type;
	  // var	UpPath 	= ( Path ) ? '/'+Path : '';			// Path 가 있다면 해당 디렉토리 하위로 설정
	   
	   switch (Type)
	   {
	       case 'Images' :
	                this.fileTypeName = "Images";
        	        this.limitSize = this.getSizeMega(50);
                    this.fileType = "*.gif;*.jpg;*.jpeg;*.bmp;*.png;";
                    this.savePath = "/Images";
           break;
           
           case 'Audio' :
	                this.fileTypeName = "음악 파일";
        	        this.limitSize = this.getSizeMega(50);
                    this.fileType = "*.mp3;*.wma;*.mp4;*.wav;*.mid;";
                    this.savePath = "/Audio";
           break;
           
	    
	       default :
	               this.fileTypeName = 'All of Type';
	               this.limitSize = this.getSizeMega(700);
	               this.fileType = "*.*";
	               this.savePath = "/Utility";
	       break;
	   }   
	    
	    if(isString(Path)) 			          	{ this.savePath 		   = Path; }
	      
	    if(isObject(Obj))
	    {
	        if(Obj.limitSize > 0) 				{ this.limitSize 		= this.getSizeMega(Obj.limitSize); }
	        if(isString(Obj.fileName)) 			{ this.fileName 		= Obj.fileName; }
	        if(isString(Obj.fileType)) 			{ this.fileType 		= Obj.fileType; }
	        if(isString(Obj.fileTypeName)) 		{ this.fileTypeName 	= Obj.fileTypeName; }
	        if(isString(Obj.savePath)) 			{ this.savePath 		= Obj.savePath; }
	        if(isString(Obj.fileName)) 			{ this.fileName 		= Obj.fileName; }
	        if(isString(Obj.fileOption)) 	    { this.fileOption 		= Obj.fileOption; }
	        if(isFunction(Obj.onComplete)) 		{ this.onComplete	 	= Obj.onComplete; }
	    }
	    
	    this.saveUrl = this.UDIR + '/FileSave.php?Path='+ this.savePath;  
	    
	    if(this.fileOption) this.saveUrl += '&Option=' + this.fileOption;
	    if(this.fileName) this.saveUrl += '&FileName=' + this.fileName;
	},
	
	getSizeMega : function (Mega)
	{
		return Mega * 1024 * 1024; 
	},
	
	showLoader : function(Obj, Type)
	{
	    var Windows = this.getLoader(Type);
	         
	    
	     	
	},
	
	getLoader : function (Obj, Button, Path)
	{
	  	
	  	this.setFileType(Obj, Path);
	  	    
	  	if(this.Windows)
	  	{
	        this.Windows.remove();
	        this.Windows = null;
	    }
	  
    	   
    	   
           this.Windows = _Window.view('FileUploader', 'File Uploader', 302, null, true);
      	   this.Windows.setPosition(true);
      	   this.Windows.append( _Window.parentWindow( Button ).Content );
    	   
    	   
	       addFlash( this.Windows.Content , this.swfFile, 'UploaderFlashSingle', '100%', '140');
	     
	       this.Windows.setCenter();
	     
	     return this.Windows;   
	},
	
	getLayer : function (Obj, Button, Path)
	{
	    this.setFileType(Obj, Path);
	    
	    var Pos = UI.getOffsetPos(Button);
	    var Size = UI.getObjSize(Button);
	  
	    var Div = document.createElement('div');
	    
	  
	    
	    addEvent(Div, 'mousedown', function(e){  cancel(e) ;} )
	    
	    
	       Div.style.position = 'absolute';
	       Div.style.width = '210px';
	       Div.style.backgroundColor = '#FFF';
	       Div.style.border = 'solid 1px #AAA';
	       Div.style.zIndex = 600;
	    
	      document.body.appendChild(Div);
	       
	      var F = function(e)
	      {
	          Div.style.display ='none';
	          
	         removeEvent(document, 'mousedown', this );
	          
	          return true;
	      }
	     
	    
	     addEvent(document, 'mousedown', F );
	       
	      Div.style.left = Pos.x +'px';
	      Div.style.top = Pos.y + Size.h +'px';
	      
	    addFlash( Div , this.swfFile, 'UploaderFlashSingle', '210', '120');
	    
	    this.Div = Div;
	   
	    return Div;
	},
	
	
	
	getKorUploader : function (Div, Obj,Path)
	{
        this.swfFile = this.UDIR +'_SWF/upload_kor.swf';	
        this.setFileType(Obj, Path);
	     
	      addFlash( Div , this.swfFile, 'UploaderFlash', '100%', '120');
	     
	},
	
	
	getEngUploader : function (Div, Obj,Path)
	{
        var swfFile = this.UDIR +'_SWF/upload_eng.swf';	
       
        this.setFileType(Obj, Path);
	     
	      addFlash( Div , swfFile, 'UploaderFlash', '100%', '120');
	     
	},
	
	
	
	
	
	setParam : function()
	{
	    if(window.document.UploaderFlashSingle)
	    {
	        for(var  key in Uploader)
    	    {
    	       var Val = Uploader[key];
    	       if(isFunction(Val) || isObject(Val)) continue;
    	       window.document.UploaderFlashSingle.SetVariable(key, Val);
    	    }
    	    
        	window.document.UploaderFlashSingle.SetVariable("goto", "");
	        
	        
	    }
	},
	
	
	
	setParamMulti : function()
	{
	  for(var  key in Uploader)
	    {
	       var Val = Uploader[key];
	       if(isFunction(Val) || isObject(Val)) continue;
	       window.document.UploaderFlash.SetVariable(key, Val);
	    }
	
	   window.document.UploaderFlash.SetVariable("goto", "");
	    
	},
	
	
	
	FromWrite : function ( FName, FSize )
	{
		var B_FILE_NAME 		= $('B_FILE_NAME');
		var B_FILE_SIZE 		= $('B_FILE_SIZE');
		
		if ( B_FILE_NAME ) 		{ $('B_FILE_NAME').value = FName; }
		if ( B_FILE_SIZE ) 		{ $('B_FILE_SIZE').value = FSize; }
	},
	
	// 리스트 중 하나의 파일의 전송이 끝났을 때 호출 됨
	Completed : function ( Arr )
	{
	     //if ( FName ) { this.FromWrite( FName, FSize ); }
	    
	},
	
	// 모든 파일의 전송이 완료 되었을 경우 호출
	uploadComplete : function ()
	{
		
		
		
		if (isFunction(this.onComplete))  setTimeout(this.onComplete.bind(this), 10);
		
		if(this.Windows)
		{
	       this.Windows.remove();
	       this.Windows = null;
		}
	},
	
	overSize : function (LimitSize)
	{
		alert('Limit exceeded.' );
			   
	    //alert('Size Over : ' + LimitSize );
	},
	
	ioError : function (Msg)
	{
	    alert('IO Error :' + Msg);
	},
	
	httpError : function (File, Msg)
	{
	    alert('HTTP Error :' + File + ' : ' + Msg);
	},
	
	seError : function (File, Msg)
	{
	    alert('Security Error : ' + File + "\n" + Msg + "\n The file cannot be transferred to another server.");
	},
	
	versionError : function ()
	{
	    // alert('Flash 8 버전 이상의 소프트웨어가 필요합니다');
	}
	
	
}

	

Uploader.setMember();
