Control.TextArea.ToolBar.BBCode = Class.create();
Object.extend(Control.TextArea.ToolBar.BBCode.prototype,{
	textarea: false,
	toolbar: false,
	options: {
		preview: false
	},
	
	
	initialize: function(textarea,options){
		this.textarea = new Control.TextArea(textarea);
		this.toolbar = new Control.TextArea.ToolBar(this.textarea);

		
		if(options)
			for(o in options)
				this.options[o] = options[o];
		
		//buttons
		this.toolbar.addButton('',function(){
			this.wrapSelection('[b]','[/b]');
		},{
			id: 'bbcode_bold_button'
		});
		
		this.toolbar.addButton('',function(){
			this.wrapSelection('[i]','[/i]');
		},{
			id: 'bbcode_italics_button'
		});
		
		this.toolbar.addButton('',function(){
			this.wrapSelection('[u]','[/u]');
		},{
			id: 'bbcode_underline_button'
		});
				
		this.toolbar.addButton('',function(){
			selection = this.getSelection();
			this.replaceSelection('[url=' + (prompt('URL','') || 'http://link_url/').replace(/^(?!(f|ht)tps?:\/\/)/,'http://') + ']' + (selection == '' ? 'Saite' : selection) + '[/url]');
		},{
			id: 'bbcode_link_button'
		});

		this.toolbar.addButton('',function(){
			this.wrapSelection('[quote]','[/quote]');
		},{
			id: 'bbcode_quote_button'
		});
        
        this.toolbar.addButton('',function(){
            selection = this.getSelection();
            this.replaceSelection('[EMBED]' + (prompt('Video URL','') || 'http://link_url/').replace(/^(?!(f|ht)tps?:\/\/)/,'http://') + (selection == '' ? '' : selection) + '[/EMBED]');
        },{
            id: 'bbcode_vide_button'
        });
		
		var smileybar = $('smileys-placeholder');
	
		if (smileybar) {
		this.toolbar.addButton('',function(){
			
			var on = Element.getStyle (smileybar,'display');
			if (on=='none') 
				Element.setStyle (smileybar,{display:'block'});
			else 
				Element.setStyle (smileybar,{display:'none'});
		},{
			id: 'bbcode_smiley_button'
		});
		}

	}
});
