function Toggler(element) {
    this.element = $(element);
    this.last_toggled = null;

    this.init = function() {
        var toggler = this;
        // hide all but first
        this.element.find('.toggle-block').each(function() {
            $(this).hide();
        });

        this.toggle(this.element.find('.toggle-element:first'));

        // bind headers to toggling blocks
        this.element.find('.toggle-element').each(function() {
            var toggle_element = $(this);
            if (toggle_element.length > 0) {
                $(this).find('.toggle-handler').click(function() {
                    toggler.toggle(toggle_element);
                    toggler.analytics(toggle_element);
                });
            }
        });
    };

    this.analytics = function(element) {
    	var name = element.find('.toggle-handler').text();
    	var url = document.URL;
    	if (typeof(_gaq) == "object") _gaq.push(['_trackEvent', 'Boite contenus', name, url]);
    };
    
    this.toggle = function(element) {
        if (this.last_toggled != null) {
            this.last_toggled.find('.toggle-block').each(function() {
                $(this).toggle('slow');
            });
            this.last_toggled.removeClass('expanded');
        }
        if (element) {
            element.find('.toggle-block').each(function() {
                $(this).toggle('slow');
            });
            this.last_toggled = element;
            this.last_toggled.addClass('expanded');
        }
    };

    this.init();
}
