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

	wym._options.subjectSelector = '.wym_subject';

	// construct the button's html
	var html = ''
		+ '<li class="wym_tools_email">'
			+ '<a title="E-Mail-Adresse einfügen" name="Email" href="#">E-Mail-Adresse einfügen</a>'
		+ '</li>';

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

	// handle click event
	jQuery(wym._box).find('li.wym_tools_email a').click(function() {
		var dialogEmailHtml = ''
			+ '<body class="wym_dialog wym_dialog_email">'
				+ '<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/email/jquery.wymeditor.email.plugin.js"></script>'

				+ '<form>'
					+ '<fieldset>'
						+ '<input type="hidden" class="wym_dialog_type" value="'+WYMeditor.DIALOG_EMAIL+'" />'
						+ '<legend>{Email}</legend>'
						+ '<div class="row first">'
							+ '<label for="email">{Email}:</label>'
							+ '<input type="email" id="email" class="wym_href" value="" size="40" required="required" autofocus="autofocus" />'
						+ '</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">'
							+ '<label for="subject">{Subject} ({optional}):</label>'
							+ '<input type="text" id="subject" class="wym_subject" value="" size="40" />'
						+ '</div>'
						+ '<div class="row indented">'
							+ '<input class="wym_submit sly-button" type="submit" value="{Submit}" />'
							+ '<input class="wym_cancel sly-button" type="button" value="{Cancel}" />'
						+ '</div>'
					+ '</fieldset>'
				+ '</form>'
			+ '</body>';

		wym.dialog('Email', null, dialogEmailHtml);
		return false;
    });
};
