/* BBCode.functions
 * by Lisaraël (http://www.lisarael.be)
 *
 * ***** BEGIN LICENSE BLOCK *****
 * This file is part of BBCode.functions.
 * Copyright (c) 2008 Lisaraël and contributors. All rights
 * reserved.
 *
 * BBCode.functions is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * BBCode.functions is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with BBCode.functions; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * ***** END LICENSE BLOCK *****
 *
 */  
 
// addBBCode, ajoute un bbcode dans un textarea
function addBBCode( textarea_id, tag1, tag2 ) {
	var textarea = document.getElementById(textarea_id);
	if( !textarea ) {
		return false;
	} else {
		initInsertions( textarea );
		if( !tag2 ) {
			insert_text(tag1, true, false, textarea);
		} else {
			bbfontstyle(tag1, tag2, textarea);
		}
	}	
} // addBBCode

var colorLoad = false;

// initialisation des actions sur les boutons des BBCodes
jQuery(window).ready(function() {
	// BB_left
	jQuery('div.BBCodeToolBar a.BB_left').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[align=left]", "[/align]" );
	});
	
	// BB_center
	jQuery('div.BBCodeToolBar a.BB_center').click(function(e) { 
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[align=center]", "[/align]" );
	}); 

	
	// BB_right
	jQuery('div.BBCodeToolBar a.BB_right').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[align=right]", "[/align]" );
	});
	
	// BB_justify
	jQuery('div.BBCodeToolBar a.BB_justify').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[align=justify]", "[/align]" );
	});
	
	// BB_bold
	jQuery('div.BBCodeToolBar a.BB_bold').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[b]", "[/b]" );
	});
	
	// BB_italic
	jQuery('div.BBCodeToolBar a.BB_italic').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[i]", "[/i]" );
	});
	
	// BB_underline
	jQuery('div.BBCodeToolBar a.BB_underline').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[u]", "[/u]" );
	});
	
	// BB_del
	jQuery('div.BBCodeToolBar a.BB_del').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[del]", "[/del]" );
	});
	
	// BB_size
	jQuery('div.BBCodeToolBar a.BB_size').click(function(e) {
		e.preventDefault();
		ttarea = jQuery(this).attr("rel");
		prompt_box(bb_message_size, 11, function(value) {
			addBBCode( ttarea, "[size="+value+"]", "[/size]" );
		});
	});
	
	// BB_ulist
	jQuery('div.BBCodeToolBar a.BB_ulist').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[ulist]", "[/ulist]" );
	});
	
	// BB_olist
	jQuery('div.BBCodeToolBar a.BB_olist').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[olist]", "[/olist]" );
	});
	
	// BB_listElmt
	jQuery('div.BBCodeToolBar a.BB_listElmt').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[li]", "[/li]" );
	});
		
	// BB_img
	jQuery('div.BBCodeToolBar a.BB_img').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[img]"+prompt("Adresse de l'image", "http://")+"[/img]" );
		/* ttarea = jQuery(this).attr("rel");
		prompt_box(bb_message_image, "http://", function(url) {
			addBBCode( ttarea, "", "[img]"+url+"[/img]" );
		}); */
	});
		
	// BB_url
	jQuery('div.BBCodeToolBar a.BB_url').click(function(e) {
		e.preventDefault();
		addBBCode( jQuery(this).attr("rel"), "[url="+prompt("Adresse du lien", "http://")+"]", "[/url]" );
		/* ttarea = jQuery(this).attr("rel");
		prompt_box(bb_message_link, "http://", function(url) {
			addBBCode( ttarea, "[url="+url+"]", "[/url]" );
		}); */
	});
	
}); // initBBButtons