/**
 * $RCSfile: editor_plugin_src.js,v $
 * $Revision: 1.12 $
 * $Date: 2006/02/22 20:06:23 $
 *
 * @author Moxiecode
 * @copyright Copyright ?2004-2006, Moxiecode Systems AB, All rights reserved.
 */

/* Import plugin specific language pack */
tinyMCE.importPluginLanguagePack('insertresource', 'en,tr,he,nb,ru,ru_KOI8-R,ru_UTF-8,nn,fi,cy,es,is,pl'); // <- Add a comma separated list of all supported languages

// Singleton class
var TinyMCE_insertresourcePlugin = {
	getInfo : function() {
		return {
			longname : 'insertresource plugin',
			author : 'Mark Wu',
			authorurl : 'http://blog.markplace.net',
			infourl : 'http://blog.markplace.net',
			version : "1.0"
		};
	},

	initInstance : function(inst) {
	},

	getControlHTML : function(cn) {
		switch (cn) {
			case "insertresource":
				return tinyMCE.getButtonHTML(cn, 'lang_insertresource_desc', '{$pluginurl}/images/insertresource.gif', 'mceinsertresource', true);
		}

		return "";
	},

	/**
	 * Executes a specific command, this function handles plugin commands.
	 *
	 * @param {string} editor_id TinyMCE editor instance id that issued the command.
	 * @param {HTMLElement} element Body or root element for the editor instance.
	 * @param {string} command Command name to be executed.
	 * @param {string} user_interface True/false if a user interface should be presented.
	 * @param {mixed} value Custom value argument, can be anything.
	 * @return true/false if the command was executed by this plugin or not.
	 * @type
	 */
	execCommand : function(editor_id, element, command, user_interface, value) {
		// Handle commands
		switch (command) {
			// Remember to have the "mce" prefix for commands so they don't intersect with built in ones in the browser.
			case "mceinsertresource":
				// Show UI/Popup
				if (user_interface) {
					// Open a popup window and send in some custom data in a window argument
					var insertresource = new Array();

					insertresource['file'] = '../../../../admin.php?op=resourceList&mode=1'; // Relative to theme
					insertresource['width'] = 500;
					insertresource['height'] = 450;

					tinyMCE.openWindow(insertresource, {editor_id : editor_id, resizable : "yes", scrollbars : "yes"});

					// Let TinyMCE know that something was modified
					tinyMCE.triggerNodeChange(false);
				} else {
					// Do a command this gets called from the insertresource popup
					alert("execCommand: mceinsertresource gets called from popup.");
				}

				return true;
		}

		// Pass to next handler in chain
		return false;
	}
};

tinyMCE.addPlugin("insertresource", TinyMCE_insertresourcePlugin);