var Nav = Class.extend({
    init: function(){
        this.current_view = null;
        
        $('.accordion').accordion();
        
        /* Esconde as seções que não estão selecionadas */
        $('> ul > li:not(.selected)', 'div.header, div.content').hide();
        $('div.menu.vertical dl').hide();
        
        //muda a foto do background
        this.change_background('/static/img/bg/acre.jpg');
        
        $('.slider').nivoSlider({
            effect: 'fade',
            directionNav: false,
            controlNav: false,
            keyboardNav: false
        });
    },
    start: function(){
        this.current_view = new SectionView();
    },
    go_to: function(page){
        
    },
    change_background: function(path){
        $("body").ezBgResize({ img : path });
    }
});


/**
 * Methods helper to apply in custom 'dado.' plugins.
 * @author Leo Berdu
 * @version 1.0 (1th March 2011)
 */
(function($){
    $.fn.methodsHelper = function(obj, method, args){
        if (obj[method]) {
            return obj[method].apply( this, Array.prototype.slice.call( args, 1 ));
        } else if (typeof method === 'object' || !method) {
            return obj.init.apply( this, args || arguments);
        } else {
            $.error( 'Method ' +  method + ' does not exist in this plugin.' );
        }
    };
})(jQuery);

(function($){
    
    var methods = {
        init : function(options){
            return this.each(function(){
                var holder = $(this);
                $('.accordion-container', holder).hide();
                methods.events();              
            });
        },
        events : function(){
            $('.accordion-trigger').bind('click', methods.animate);
            $.address.externalChange(methods.onChangeURL);
        },
        onChangeURL : function(e){
            var section = e.value,
                button = $('.accordion > .accordion-trigger > a[href$=#'+ section.replace(/^\//, '') +']').parent();
                button.trigger('click');
        },
        animate : function(e){
            var button = $(this),
                link = $('a', button),
                holder = button.parent();
            
            function open(){ 
                link.toggleClass('active');
                
                button.next().animate({
                        width: 'show'
                    }, 600, 'easeInOutExpo', function(){
                        if(button.parent().hasClass('accordion')){
                            $.address.value( link.attr('href').replace(/^#/, '') );
                        }
                        button.next().trigger('change');
                        document.title = 'Brasil a gosto - ' + link.text();
                });
            }
            function close(){
                $('> .accordion-trigger a', holder).removeClass('active');
                $('> .accordion-trigger', holder).next().animate({
                        width: 'hide'
                    }, 600, 'easeInOutExpo');
            }
            
            if(button.next().is(':hidden')){
                close();
                open();
            } else {
                close();
            }
            
            return false;
        },
        openItem : function(value){
            $('> .accordion-trigger:eq(' + value + ')', '.accordion').addClass('active').next().show();
        }
    };
    
    $.fn.accordion = function(method){
        this.methodsHelper(methods, method, arguments);
    };
    
})(jQuery);
