var filebrowser = {
	init : function(wym, wdw) {
		var fb_url = doc_root + 'includes/ajax/wymeditor.filebrowser.get.php';
		
//		alert('adding link to filebrowser');
		
		var dlg = jQuery(wdw.document.body);
		if (dlg.hasClass('wym_dialog_image')) {
//			alert('class wym_dialog_image found');
			// this is an image dialog
			dlg.find('.wym_src').css('width', '200px').attr('id', 'filebrowser')
				.after('<a id="fb_link" title="' + gt.gettext("Dateibrowser") + '" href="#" >' + gt.gettext("Dateibrowser") + '</a>');
						
			wdw.document.getElementById('fb_link').onclick = function() {
				projectroom_id = typeof projectroom_id != 'undefined' ? projectroom_id : false;
				projectroom_id = typeof project_room_id != 'undefined' ? project_room_id : projectroom_id;
				fb_window = wdw.open(fb_url + '?pop=1&projectroom_id=' + projectroom_id, 'filebrowser', 'height=600,width=840,resizable=yes,scrollbars=yes');
				fb_window.focus();
				return false;
			}
		}
		
	},
	
	filelist : {
		get : function(projectroom_id) {
			jQuery.post(doc_root + 'includes/ajax/wymeditor.filebrowser.filelist.get.php', {
				projectroom_id : projectroom_id
			}, function(data, status) {
				jQuery('#filebrowser-filelist').html(data);
			}, 'json');
		}
	},
	preview : {
		get : function(media_id) {
			media_id = typeof media_id != 'undefined' ? media_id : false;
			
			// loading...
			jQuery.post(doc_root + 'includes/ajax/wymeditor.filebrowser.preview.get.php', {
				intMediaId : media_id
			}, function(data, status) {
				jQuery('#filebrowser-preview').html(data.html);
				jQuery('#filebrowser', window.opener.document).val(data.image_path);
			}, 'json');
		}
	},
	close : function () {
		window.close();
	},
	reset_close : function() {
		jQuery('#filebrowser', window.opener.document).val('');
		filebrowser.close();		
	}
}
