/**
 * This function will add a target _blank effect with the onclick attribute
 * on any css selector (i.e a.blank => all the a with the class blank)
 *
 * @author Francois Lavertu
 */

addTargetBlank = function(sCssSelector){
    $$(sCssSelector).invoke('observe', 'click', function(e){
        // check if the element as the href attribute
        if(this.href){
            window.open(this.href);
            Event.stop(e);
        }
    });
}

initToggleByClassname = function(buttonClass, containerClass, contentClass) {
	$$('.' + buttonClass).invoke('observe', 'click',
    	function(e){
    		var node, content, toggleElem;
    		var found = false;
    		var isUndefined = false;
    		node = Event.element(e);
			
    		while ( !found && !isUndefined ) {
    			if (node == document) {
    				isUndefined = true;
    			}
    			else {
    				node = node.up();
    				if ( node.hasClassName(containerClass) ) {
    					content = Element.select(node, '.' + contentClass);
						btn = this;
    					found = true;

    					if ( content.size() > 0 ) {
    						toggleElem = content.first();
    						if ( toggleElem.hasClassName('hide') ) {
    							toggleElem.removeClassName('hide');
								btn.addClassName('select');
    						}
    						else {
    							toggleElem.addClassName('hide');
								btn.removeClassName('select');
    						}
    					}
    				}
    			}
    		}

    		e.stop();
    	}
    );
}

document.observe('dom:loaded', function() {

	/* ajouter une classe à un lien pour simuler un target=blank */
	addTargetBlank('a.blank');

	/* ajouter une classe pour simuler un pseudo-selector pour IE */
	$$('.contentHolder li:first-child').invoke('addClassName', 'noBorder');

	/* fonction d'accessibilité pour la typo */
	/*var config = {
		sCssBtnSizeChange: '#btn_fontResize',
		sCssContainer: '.content_holder',
		aCssFontClass: ['size1','size2'],
		sCssRteContainer: '.rte_texte'
	}*/
	//var oFontSize = new FontSizeControl(config);
	initToggleByClassname('toggleBtn', 'toggleDisplay', 'toggleElem');
});