/**
 * $RCSfile: editor_plugin_src.js,v $
 * $Revision: 1.24 $
 * $Date: 2006/02/10 16:29:38 $
 *
 * @author Moxiecode
 * @copyright Copyright � 2004-2006, Moxiecode Systems AB, All rights reserved.
 */

/* Import plugin specific language pack */
tinyMCE.importPluginLanguagePack('su3advlink', 'en,fi,tr,de,sv,zh_cn,cs,fa,fr_ca,fr,pl,pt_br,nl,he,nb,ru,ru_KOI8-R,ru_UTF-8,nn,cy,es,is,zh_tw,zh_tw_utf8,sk,da');

var TinyMCE_su3AdvancedLinkPlugin = {
	getInfo : function() {
		return {
			longname : 'Siteupdate 2 - Advanced link',
			author : 'Moxiecode Systems',
			authorurl : 'http://www.sitefactory.fi',
			infourl : 'http://www.sitefactory.fi',
			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
		};
	},

	initInstance : function(inst) {
		inst.addShortcut('ctrl', 'k', 'lang_su3advlink_desc', 'su3advlink');
	},

	getControlHTML : function(cn) {
		switch (cn) {
			case "su3advlink":
				return tinyMCE.getButtonHTML(cn, 'lang_su3advlink_desc', '{$themeurl}/images/link.gif', 'su3advlink');
		}

		return "";
	},

	execCommand : function(editor_id, element, command, user_interface, value) {
		switch (command) {
			case "su3advlink":

				var anySelection = false;
				var inst = tinyMCE.getInstanceById(editor_id);
				var focusElm = inst.getFocusElement();
				var selectedText = inst.selection.getSelectedText();

				if (tinyMCE.selectedElement)
					anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (selectedText && selectedText.length > 0);

				if (anySelection || (focusElm != null && focusElm.nodeName == "A")) {
					var template = new Array();



/*					if (linkto=="page"){
						template['file']   = tinyMCE.getParam("su3_homeurl")+'siteupdate/tinymce/su3_advlinkdlg/-/linkto/page/selected_page_id/'+page_id+'/';
					} else if (linkto== "file"){
						template['file']   = tinyMCE.getParam("su3_homeurl")+'siteupdate/tinymce/su3_advlinkdlg/-/linkto/file/selected_file_id/'+file_file_id+'/selected_dir_id/'+file_dir_id+'/';
					} else {
						template['file']   = tinyMCE.getParam("su3_homeurl")+'siteupdate/tinymce/su3_advlinkdlg/-/linkto/other/';
					}
*/

					template['file']   = tinyMCE.getParam("su3_homeurl")+'siteupdate/tinymce/su3_advlinkdlg/';

					//alert("eka="+koira);
					//template['file']   = '../../plugins/advlink/link.htm';

					template['width']  = 480;
					if (tinyMCE.isMSIE)
						template['height'] = 560;
					else
						template['height'] = 550;

					// Language specific width and height addons
					template['width']  += tinyMCE.getLang('lang_advlink_delta_width', 0);
					template['height'] += tinyMCE.getLang('lang_advlink_delta_height', 0);

					tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
				}

				return true;
		}

		return false;
	},

	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
		if (node == null)
			return;

		do {
			if (node.nodeName == "A" && tinyMCE.getAttrib(node, 'href') != "") {
				tinyMCE.switchClass(editor_id + '_advlink', 'mceButtonSelected');
				return true;
			}
		} while ((node = node.parentNode));

		if (any_selection) {
			tinyMCE.switchClass(editor_id + '_advlink', 'mceButtonNormal');
			return true;
		}

		tinyMCE.switchClass(editor_id + '_advlink', 'mceButtonDisabled');

		return true;
	}
};

tinyMCE.addPlugin("su3advlink", TinyMCE_su3AdvancedLinkPlugin);
