
var cleverfilesconfig; // TODO this is a nasty hack really....

jQuery.fn.clevereditor = function(options) {
	
	// give up if any matches already include tinymce
	if(this.next('.mceEditor').length > 0) return;
	
	
	var defaults = {
			width: 600,
			height: 400
	};
	var opts = jQuery.extend(defaults, options);
	
	 // TODO this is a nasty hack really....
	cleverfilesconfig = {
		      scriptList: baseUrl + 'stuff/ajax_list',
		      scriptProperties: baseUrl + 'stuff/ajax_properties',
		      bookmarks: [
		      				{name: currentUser.name, root: currentUser.id, icon: currentUser.avatarUrl, large: true},
		      				{ name: 'All My Stuff', root: currentUser.id, filter:{type:'^Folder', recursive: true}, icon: baseUrl + 'css/media/cleverfiles/color_swatch_2.gif'},
		      				{ name: 'Pictures', root: currentUser.id, filter:{filetype:'image', recursive: true}, icon: baseUrl + 'css/media/cleverfiles/photo.gif'},
		      				{ name: 'Videos', root: currentUser.id, filter:{filetype:'video', recursive: true}, icon: baseUrl + 'css/media/cleverfiles/film.gif'},
		      				{ name: 'Sounds', root: currentUser.id, filter:{filetype:'audio', recursive: true}, icon: baseUrl + 'css/media/cleverfiles/music.gif'}
		      			 ],
		      height: 250,
		      width: 600,
//		      showIcon: true,
		      showThumbnails: true,
		      showProperties: true,
		      showBookmarks: true,
		      showNavigation: true,
		      appTitle: 'Select stuff...',
		      allowMultiSelect: true,
		      allowSearch: true,
		      showTableHeaders: true
			};
	
	return this.tinymce({
		// Location of TinyMCE script
		script_url : baseUrl + 'js/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
		mode : "exact",
		plugins : "emotions,inlinepopups,safari,clevertube,cleverfiles,advimagescale",
		relative_urls : false,
		
		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
		theme_advanced_buttons2 : "fontselect,fontsizeselect,emotions,forecolor,backcolor,removeformat,image,clevertube,cleverfiles",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		//theme_advanced_statusbar_location : "bottom",
		
		width : opts.width,
		height : opts.height,  
		media_strict: false,
		
		advimagescale_noresize_class: "noresize",
		
		// Enable FireFox built in spellchecker
		gecko_spellcheck : true,
		
		extended_valid_elements: "object[classid|codebase|width|height|align],param[name|value],embed[quality|type|pluginspage|width|height|src|align|wmode]",
		
		cleverfilespreviewscript : baseUrl + 'stuff/ajax_view',
		
		// Example content CSS (should be your site CSS)
		content_css : baseUrl + 'css/extend.css'
			
	});
	
}

