wmp.editor.baseModuleInline = new Class({
	Extends: wmp.editor.baseModule,
	type: "inline",
	legalChilds: ["inline"],
	allowedAttributes: [],
	fixme: function() {
		this.nodes.content = this.node;
		this.fixMoveOutIllegal();
		this.fixInline();
		if (this.fixme2)
			this.fixme2();
		//todo: this.fixRemoveEmpty();
	}
});

wmp.editor.modules.a = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "a",
	title: "Link",
	nodeName: "a",
	illlegalChilds: ["a", "br"],
	attributes: $H({"backuphref":{"noexport":true}, "href":{"exportempty":true}, "title":{}}),
	shortcut: "l",
	icon: "link.png",
	fixme2: function() {
		this.fixCreateAttibute("href");
		this.fixUrl();
	},
	fixUrl: function() {
		//var abs = wmp.url.toDomainAbs(href)
		var href = this.node.getAttribute("href",2)||"";
		if (href.test("^image/") || href.test("^file/") || href.test("^#"))
			return;
		var abs = this.node.href.replace(new RegExp("https?://"+window.location.host),"");
		//console.log("href", href, abs,"http://"+window.location.host);
		if (href!="" && href!=abs) {
			this.node.setAttribute("href", abs);
			this.logfix("a: href fix", href + " to " + abs);
		}
	},
	guiactivateme: function() {
		this.guicreatemenu();
		this.menu.addItem({title:"Link aufrufen", func:this.visiturl.bind(this), icon: "editor/16x16/go-jump.png"});
		wmp.gui.linker(this.inputs.wmplink.node, this.inputs.href.node, this.setproperty_href.bind(this));
	},
	
	manipulators: {
		"wmplink": {
			title: "Link auf WMP Suchen",
			type: "string",
			help: ""
		},
		"href": {
			title: "Adresse",
			type: "url"
		}
	},
	getproperty_href: function() {
		return this.node.getProperty("href");
	},
	setproperty_href: function() {
		this.node.setAttribute("href", this.inputs.href.getValue());
		this.node.setAttribute("backuphref", this.inputs.href.getValue());
	},
	getproperty_wmplink: function() {},
	setproperty_wmplink: function() {},
	visiturl: function() {
		var url = this.inputs.href.getValue();
		if (wmp.url.type(url)=="rel")
			url = (this.editor.options.relativeUrlPrefix || "") + url;
		window.open(url);
	},
	onFormatInline: function() {
		var selection = this.editor.sel.selection + "";
		var findUrl = new RegExp ("^\\s*(http://.*?)\\s*$");
		var result = findUrl.exec(selection);
		if (result && result[1]) {
			this.node.setAttribute("href", result[1]);
			this.inputs.href.setValue(result[1]);
		}
		var field = this.inputs.href.field;
		window.setTimeout(function(){field.focus();},100);
	}
});
wmp.editor.modules.a_with_upload = new Class({
	Extends: wmp.editor.modules.a,
	name: "a",
	title: "Link",
	nodeName: "a",
	shortcut: "l",
	icon: "link.png"
});/*
wmp.editor.modules.a_with_upload = new Class({
	Extends: wmp.editor.modules.a,
	name: "a",
	title: "Link",
	nodeName: "a",
	shortcut: "l",
	icon: "link.png",
	guiactivateme: function() {
		this.guicreatemenu();
		this.urlinput = new wmp.gui.url({
			onchange: this.changeurl.bind(this),
			value: this.node.getProperty("href") || ""
		});
		this.menu.addInput({
			title: "Adresse",
			input: this.urlinput,
			help: "Hilfetext"
		});
		this.menu.addItem({title:"Link entfernen", func:this.editor.formatInline.bindWithEvent(this.editor, "unlink"), icon: "editor/16x16/edit-delete.png"});
		this.menu.addItem({title:"Link aufrufen", func:this.visiturl.bind(this), icon: "editor/16x16/go-jump.png"});
		
		this.inputs.upload = new wmp.gui.upload({
			onchange: this.afterupload.bind(this),
			fieldname: "file",
			target: "/profile/temp/file/create-ajax/"
		});
		this.menu.addInput({title: "Datei hochladen",input: this.inputs.upload, closed: true});
	},
	afterupload: function() {
		this.values.url = 'file/' + this.inputs.upload.getValue();
		this.node.setAttribute("href", this.values.url);
		this.urlinput.setValue(this.values.url);
	}
});
*/
wmp.editor.modules.br = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "br",
	title: "Zeilenumbruch",
	nodeName: "br",
	canBeEmpty: true,
	fixme: function() {},
	exportXml: function() {
		return "<br />";
	}	
});

wmp.editor.modules.strong = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "strong",
	title: "Fett",
	nodeName: "strong",
	shortcut: "b",
	icon: "format-text-bold.png",
	convertElement: function(node, editor) {
		if (node.get('tag') == "b")
			return wmp.xml.renameNode(node, this.nodeName);
	}
});

wmp.editor.modules.em = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "em",
	title: "Hervorgehoben",
	nodeName: "em",
	icon: "format-text-italic.png",
	convertElement: function(node, editor) {
		if (node.get('tag') == "i" || node.get('tag') == "u")
			return wmp.xml.renameNode(node, "em");
	}
});

wmp.editor.modules.code = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "code",
	title: "einzeiliger Quelltext",
	nodeName: "code",
	allowedAttributes: ["language"],
	icon: "document-properties.png"
});

wmp.editor.modules.abbr = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "abbr",
	title: "Abkürzung",
	nodeName: "abbr",
	allowedAttributes: ["title"],
	icon: "abk.gif",
	
	fixme2: function() {
		this.fixCreateAttibute("title");
	},
	
	guiactivateme: function() {
		this.guicreatemenu();
		this.inputs.title = new wmp.gui.url({
			onchange: this.change.bind(this),
			value: this.node.getAttribute("title") || ""
		});
		this.menu.addInput({
			title: "ausgeschriebener Begriff",
			input: this.inputs.title,
			help: "Geben Sie hier die augeschrieben Abkürzung ein. Sie erscheint wenn man mit der Maus über die Abkürzung fährt."
		});
	},
	
	change: function() {
		this.node.setAttribute("title", this.inputs.title.getValue());
	},
	
	convertElement: function(node, editor) {
		if (node.get('tag') == "abbr")
			return wmp.xml.renameNode(node, this.nodeName);
	}
});

wmp.editor.modules.cite = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "cite",
	title: "Zitat",
	nodeName: "cite",
	icon: "internet-group-chat.png" 
});

wmp.editor.modules["var"] = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "var",
	title: "Variable",
	nodeName: "var",
	icon: "var.gif"
});

wmp.editor.modules.samp = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "samp",
	title: "Beispiel",
	nodeName: "samp",
	icon: "accessories-text-editor.png" 
});

wmp.editor.modules.ins = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "ins",
	title: "Einfügung",
	nodeName: "ins",
	icon: "einfuegung.gif",
	illlegalChilds: ["del"]
});

wmp.editor.modules.del = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "del",
	title: "Entfernung",
	nodeName: "del",
	icon: "entfernung.gif" ,
	illlegalChilds: ["ins"],
	convertElement: function(node, editor) {
		if (node.get('tag') == "strike")
			return wmp.xml.renameNode(node, this.nodeName);
	}
});

wmp.editor.modules.sup = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "sup",
	title: "Hochgestellt",
	nodeName: "sup",
	icon: "hochgestellt.gif"
});
wmp.editor.modules.sub = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "sub",
	title: "Tiefgestellt",
	nodeName: "sub",
	icon: "tiefgestellt.gif" 
});

wmp.editor.modules.span = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "span",
	title: "Span",
	nodeName: "span",
	arbitraryClasses: true,
	specificity: -3
});

wmp.editor.modules.span.prototype.extenders = {classes:{
	manipulators: {
		"classes": {
			title: "CSS Klassen",
			type: "url"
		}
	},
	getproperty_classes: function() {
		this.values.classes =  this.node.getAttribute("class",2) || "";
		return this.values.classes;
	},
	setproperty_classes: function() {
		this.values.classes = this.inputs.classes.getValue();
		this.node.setAttribute("class", this.values.classes);
	}
}};



wmp.editor.modules.img = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "img",
	title: "Bild",
	nodeName: "img",
	legalChilds: [],
	canBeEmpty: true,
	attributes: $H({"src":{"exportempty":true}, "alt":{"exportempty":true}, "title":{}}),
	sampleImage: "/editor/sample-image/",
	fixme: function() {
		var src = this.node.getProperty("src") || "";
		if (src.trim().length<3) {
			this.node.setProperty("src", this.sampleImage);
		}
		this.node.style.width = "auto";
		this.node.style.height = "auto";
	},
	manipulators: {
		"src": {
			title: "Bildadresse",
			type: "url"
		},
		"alt": {
			title: "Alternativtext",
			type: "string"
		},
		"title": {
			title: "Titel",
			type: "string"
		}
	}
});


wmp.editor.modules.toolname = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "toolname",
	title: "Menüeintrag/Werkzeug",
	nodeName: "span",
	nodeClass: "toolname"
});

wmp.editor.modules.kbd = new Class({
	Extends: wmp.editor.baseModuleInline,
	name: "kbd",
	title: "Tastenkombi./Eingabe",
	nodeName: "kbd"
});

