// Image Picker 
//create a namespace 
YAHOO.namespace("qw.uploader")

//create a new object for this module:
YAHOO.qw.uploader.inDialog = function(){
	
	return {
		
		init: function()
		{
			
			// Instantiate the Dialog
            
            this.dialog = new YAHOO.widget.Dialog("yui-uploader-panel", {
                fixedcenter: true,
                visible: false,
				modal:true
            });
			
			this.dialog.render();
			
			// Show the dialog
	
			this.show = function(path,onSuccess,onError,name,tw,th)
			{
				this.path = path;
				this.onSuccess = onSuccess;
				this.onError = onError;
				$('yui-uploader-panel').style.display='block';
				ulform = $('yui-uploader-form');
				ulform.target = 'qw_upload_target';
				ulform.action = '/upload/' + path + '/'
				if(name!=null)
				{
					$('qw-fldupload-name').value = name;
				}
				else{
					$('qw-fldupload-name').value = "";
				}
				if(tw!=null)
				{
					$('qw-fldupload-thumbw').value = tw;
				}
				else{
					$('qw-fldupload-thumbw').value = "";
				}
				if(th!=null)
				{
					$('qw-fldupload-thumbh').value = th;
				}
				else{
					$('qw-fldupload-thumbh').value = "";
				}
				
				this.dialog.show();
				
			}
			
			
			this.upload = function(){
				ulform = $('yui-uploader-form');
				ifrm = $('qw_upload_target');
				ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
	            ifrm.document.open();
	            ifrm.document.write("<div style='color:yellow'>Uploading...</div>");
	            ifrm.document.close();
				ulform.submit();

			}
			
			this.cancel = function(){
				$('yui-uploader-panel').style.display = 'none';
				this.dialog.hide();
			}
				
			this.finish = function(file){
				
				this.dialog.hide();
				if(this.onSuccess)
				{
					this.onSuccess(file)
				}
				
			}
			
		}
		
		
	}

}()

YAHOO.util.Event.onDOMReady(YAHOO.qw.uploader.inDialog.init, YAHOO.qw.uploader.inDialog, true); 


function doUpload(path,onSuccess,onError,name,w,h)
{				
	YAHOO.qw.uploader.inDialog.show(path,onSuccess,onError,name,w,h);
}

function finishUpload(file)
{				
	YAHOO.qw.uploader.inDialog.finish(file);
}

function cancelUpload()
{				
	YAHOO.qw.uploader.inDialog.cancel();
}

uploadFile = function()
{
	YAHOO.qw.uploader.inDialog.upload();
}

