// Implementa a função ShowAll() e Hideall()
Accordion.implement({
    showAll: function() {
        var obj = {};
        this.previous = -1;                  //  Added this line
        this.elements.each(function(el, i){
            obj[i] = {};
            this.fireEvent('onActive', [this.togglers[i], el]);
            for (var fx in this.effects) obj[i][fx] = el[this.effects[fx]];
        }, this);
        return this.start(obj);
    },
    hideAll: function() {
        var obj = {};
        this.previous = -1;                  //  Added this line
        this.elements.each(function(el, i){
            obj[i] = {};
            this.fireEvent('onBackground', [this.togglers[i], el]);
            for (var fx in this.effects) obj[i][fx] = 0;
        }, this);
        return this.start(obj);
    }
});

window.addEvent('domready', function() {
	var myAccordion = new Accordion('h3.toggler', 'div.element', {
		start:'all-closed',
		opacity: true,
		duration: 350,
		alwaysHide: true,
		onActive: function(togglers, stretchers){
            togglers.addClass('sel');
            stretchers.setStyle('display', 'block');
            stretchers.setStyle('border', '1px #787E86 solid');
            stretchers.setStyle('border-width', '0 1px 1px');
            hideStyles3(togglers, stretchers);
        },
		onBackground: function(togglers, stretchers) {
			//$$('div.sub_element').setStyle('height','0');
            hideStyles(togglers, stretchers);
            myAccordion2.hideAll();
		}
	}, $('accordion'));
	var myAccordion2 = new Accordion('h3.sub_toggler', 'div.sub_element', {
		start:'all-closed',
		opacity: true,
		duration: 350,
		alwaysHide: true,
		onActive: function(togglers, stretchers){
			togglers.getParent().setStyle("height", "auto");
			togglers.addClass('sel2');
			stretchers.setStyle('border', '1px #889BB3 solid');
            stretchers.setStyle('border-width', '0 1px 1px');
            stretchers.setStyle('padding', '5px 15px 4px');
		},
		onBackground: function(togglers, stretchers){
			hideStyles2(togglers, stretchers);
		}
	}, $('accordion'));
});

function  hideStyles(a, b){
    window.setTimeout(function() {
        b.setStyle('border', 'none');
        a.removeClass('sel');
        b.setStyle('padding', '0 20px 0');
        b.setStyle('height', b.offsetHeight);
    }, 350);
}

function  hideStyles2(a, b){
    window.setTimeout(function() {
        a.removeClass('sel2');
        b.setStyle('border', 'none');
        b.setStyle('padding', '0 15px');
        b.setStyle('height',b.offsetHeight);
    }, 350);
}
 
function  hideStyles3(a, b){
    
    window.setTimeout(function() {
        b.setStyle('padding', '5px 20px 7px');

    }, 1);
}          

