W.FlashUploader	= {
	
	debug 		: false,
	id			: '',		// id for flash uploader
	details		: null,		// reference to details object
	folder_id	: '',		// id of folder for when you only want to display the contents of a single folder
	root		: '',		// set a default root level
	user_id		: '',		// for logging
	
	
	
	start : function(id)
	{
		var div	= W.$(id);
		if (!div) { return; }
		
		var clone	= div.cloneNode(false);
		var index	= id.search(/\d/);
		var num		= id.substr(index);
		var root	= id.substring(0, index);
		var new_id	= root + (++num);
		clone.id	= new_id;
		
		var container	= W.$('uploads');
		container.insertBefore(clone, div);

		this.create(new_id);
		
		W.Event.add(this);
	},
	
	
	
	complete : function(id)
	{
		if (this.debug) { console.log('complete ' + id); }
		
		this.update();
		W.Dom.remove(id);
	},
	
	
	
	error : function(message)
	{
		if (this.debug) { console.log('error: ' + message); }
	},
	
	
	
	log : function(message)
	{
		if (this.debug) { console.log('debug: ' + message); }
	},
	
	
	
	update : function()
	{
		if (this.debug) { console.log('update ' + this.folder_id); }
		
		var obj	= this;
		if (W.$('folder')) W.$('folder').value = '';
		var tmp = new W.Request('GET', 'xhr/files.php?id=' + this.folder_id).call(obj.list.bind(obj));
	},
	
	
	
	set_root : function(folder_id)
	{
		this.root = folder_id
	},
	
	
	
	folder : function()
	{
		if (this.debug) { console.log('folder'); }
		
		var obj		= this;
		var name	= escape(W.$('folder').value);
		var root	= this.root
		var tmp;
		
		if (this.details.folder) {
			root	= this.details.id;
		}
		
		
		if (name) {
			tmp = new W.Request('GET', 'xhr/folder.php?f=' + name + '&parent=' + root).call(obj.update.bind(obj));
		}
	},
	
	
	
	list : function(req)
	{
		if (this.debug) { console.log('list'); }
		
		tree.preserve();
		W.Event.broadcast('onBeforeFileList', {source: this});
		W.$('files').innerHTML = req.responseText;
		W.Event.broadcast('onAfterFileList', {source: this});
		tree.refresh();
	},
	
	
	
	create : function(id)
	{
		if (this.debug && !window.console) { this.debug = false; }
		
		if (this.debug) { console.log('create'); }
		
		this.id	= id + 'flash';
		
		var FO = { movie:"flash/uploader.swf", width:"215", height:"22", id:this.id, name:this.id, majorversion:"8", build:"0", bgcolor:"#EEF5F5", xi:"true", 
				   ximovie:"flash/ufo.swf", swliveconnect:"true", allowscriptaccess:"samedomain", flashvars:"id=" + id + "&ps=" + this.root + "&user_id=" + this.user_id };
		UFO.create(FO, id);
		

		W.Event.add(this);	// FIXME: this should be in an init() function
	},
	
	
	
	onSortSelect : function(event)
	{
		// FIXME: duplicate of code in Details.js
		var target	= W.Event.getTarget(event.event);
		
		this.selected	= target;
		if (this.selected.tagName.toUpperCase() == 'LI') { this.selected = this.selected.firstChild; }	// IE sometimes will target LI instead of DIV - FIXME: firstChild could be a text node
		
		if (this.selected.tagName.toUpperCase() != 'DIV') { return; }	// ignore click that occur between divs
		
		var li	= this.selected.parentNode;
		var ps	= li.getAttribute('data-ps');
		var so = li.getAttribute('data-so');

	},
	
	
	
	onSortUnselect : function(event)
	{
		$(".selected").removeClass("selected");
	}
};
