jQuery( function() {
    CP.init();
});

var CP = {

    init : function() {
        CP.tweets();
        CP.tabs_servicos();
    },

    tweets : function() {
        var twitterFollows = jQuery( '#twitter-authors .twitter-follow' );
        var twitterTweets = jQuery( '#twitter-tweets .tweets' );
        twitterFollows.not( ':first' ).hide();
        twitterTweets.not( ':first' ).hide();

        jQuery( '.twitter-author-image' ).each( function( index ) {
            jQuery( this ).click( function() {
                twitterFollows.hide();
                twitterTweets.hide();
                jQuery(this).next().fadeIn( function() {
                    twitterTweets.eq( index ).fadeIn();
                });
            })
        } );
    },

    tabs_servicos : function() {
            
        jQuery( '#servicos div' ).not( ':first' ).hide();
        jQuery( '#servicos ul li:first' ).addClass( 'current_page_item' );

        jQuery( '#servicos a' ).click( function( event ) {
            var href = jQuery( this ).attr( 'href' );
            CP._set_active_tab( href );
            event.preventDefault();
        } );
        
        var _pageHash = window.location.hash;
        var pageHash = _pageHash.replace( '#', '' );
        if ( pageHash ) {
            CP._set_active_tab( '#tabs-' + pageHash );
        }
    },

    _set_active_tab : function( hash ) {
        jQuery( '#servicos div' ).hide();
        jQuery( hash ).fadeIn();
        // Seta como atual
        jQuery( '#servicos .current_page_item' ).removeClass( 'current_page_item' );
        jQuery( 'a[href="' + hash + '"]' ).parent( 'li' ).addClass( 'current_page_item' );
    }
}
