// Extend WYMeditor
WYMeditor.editor.prototype.filelink = function() {
	var wym  = this;
	var base = '../data/dyn/public/webvariants/wymeditor/wymeditor/';

	// construct the button's html
	var html = '<li class="wym_tools_file"><a title="Dateilink einfügen" name="FileLink" href="#">Dateilink einfügen</a></li>';

	// add the button to the tools box
	jQuery(wym._box)
		.find(wym._options.toolsSelector+wym._options.toolsListSelector+' .wym_tools_image')
		.after(html);

	// handle click event
	jQuery(wym._box).find('li.wym_tools_file a').click(function() {
		var dialogFileHtml = ''
			+ '<body class="wym_dialog wym_dialog_file">'
				+ '<script type="text/javascript">var wym = window.opener.WYMeditor.INSTANCES['+wym._index+'];</script>'
				+ '<script type="text/javascript" src="'+wym_sallyjs_path+'"></script>'
				+ '<script type="text/javascript" src="'+base+'plugins/filelink/jquery.wymeditor.filelink.plugin.js"></script>'

				+ '<form>'
					+ '<fieldset>'
						+ '<input type="hidden" class="wym_dialog_type" value="'+WYMeditor.DIALOG_FILE+'" />'
						+ '<legend>{FileLink}</legend>'
						+ '<div class="row first">'
							+ '<label for="file">{File}:</label>'
							+ '<input type="text" id="file" class="wym_href" value="" size="40" required="required" autofocus="autofocus" />'
							+ '<a class="mediapoolLink" href="#"><img src="assets/file_open.png" title="Mediapool" alt="Mediapool" /></a>'
						+ '</div>'
						+ '<div class="row">'
							+ '<label for="title">{Title} ({optional}):</label>'
							+ '<input type="text" id="title" class="wym_title" value="" size="40" />'
						+ '</div>'
						+ '<div class="row indented">'
							+ '<input class="wym_submit" type="submit" value="{Submit}" />'
							+ '<input class="wym_cancel" type="button" value="{Cancel}" />'
						+ '</div>'
					+ '</fieldset>'
				+ '</form>'
			+ '</body>';

		wym.dialog('FileLink', null, dialogFileHtml);
		return false;
	});
};
