
function registerBBCodeToolbar(elm_textarea)
{
	var textarea_ID = elm_textarea.identify();
	var textarea = new Control.TextArea(textarea_ID);
	var toolbar = new Control.TextArea.ToolBar(textarea);
	var elm_helper = new Element('dfn');
	$(elm_textarea).insert({ 'before': elm_helper });
	var toolbar_ID = elm_helper.identify();
	$(elm_helper).remove();
	toolbar.container.id = toolbar_ID; //for css styles
	$(toolbar_ID).addClassName('markdown_toolbar');
	var tb_width = $(elm_textarea).getWidth()-2;
	$(toolbar_ID).setStyle({ width: tb_width+'px' });
	//buttons
	toolbar.addButton('Italics',function(){
		this.wrapSelection('[i]','[/i]');
	},{
		id: 'markdown_italics_button',
		title: 'Kursivschrift'
	});

	toolbar.addButton('Bold',function(){
		this.wrapSelection('[b]','[/b]');
	},{
		id: 'markdown_bold_button',
		title: 'Fettschrift'
	});

	toolbar.addButton('Link',function(){
		var selection = this.getSelection();
		var response = prompt('Bitte Link-URL eingeben','');
		if(response == null)
			return;

		this.replaceSelection('[url=' + (response == '' ? 'http://link_url/' : response).replace(/^(?!(f|ht)tps?:\/\/)/,'http://') + ']' + (selection == '' ? 'Link' : selection) + '[/url]');
	},{
		id: 'markdown_link_button',
		title: 'Hyperlink einfügen'
	});

	/*
	toolbar.addButton('Image',function(){
		var selection = this.getSelection();
		var response = prompt('Bitte Image-URL eingeben','');
		if(response == null)
			return;
		this.replaceSelection('[image]' + (response == '' ? 'http://image_url/' : response).replace(/^(?!(f|ht)tps?:\/\/)/,'http://') + '[/image]');
	},{
		id: 'markdown_image_button',
		title: 'Bild einfügen'
	});
	
	*/
	
	toolbar.addButton('Image',function(){
		Effect.toggle('comments_form_upload','appear');
	},{
		id: 'markdown_image_button',
		title: 'Bild einfügen'
	});

	toolbar.addButton('Help',function(){
		window.open(_FILES_ROOT+'/files/BBCodes.pdf');
	},{
		id: 'markdown_help_button',
		title: 'Zusätzliche Informationen'
	});



}

Event.onDOMReady( function(){ $$('textarea.bbcodeEdit').each(registerBBCodeToolbar) } );