var structure = {
    init: function () {
        trace('structure : init');

        structure.setCurrentSection();
        structure.transition.init();

        $('.main-nav li a')
        .bind('mouseenter', structure.mainNavMouseEnter)
        .bind('mouseleave', structure.mainNavMouseLeave);

        //$('.institutional-nav li a').fadeTo(0, .7);
    },

    setCurrentSection: function () {
        trace('structure : setCurrentSection');
        var pathname = document.location.pathname.replace(/\//g, '');

        var el = $('.main-nav li a[href*="{0}"]'.format(pathname));

        if (el.length > 0) {
            el.addClass('current');
            return;
        }

        el = $('.institutional-nav li a[href*="{0}"]'.format(pathname));

        if (el.length > 0) {
            el.addClass('current');
            return;
        }

        if (pathname.toLowerCase().indexOf('printandpractice') > -1) trace('Print');
        if (pathname.toLowerCase().indexOf('testeseuingles') > -1) trace('Teste');
        if (pathname.length == 0) $('.main-nav li a:eq(0)').addClass('current');


    },

    mainNavOverColor: '#004f97',
    mainNavOutColor: '#477fb1',

    mainNavMouseEnter: function (e) {
        var el = $(e.currentTarget);
        if (!el.hasClass('current')) el.animate({ backgroundPosition: '0 0', color: structure.mainNavOverColor }, { duration: 500, easing: 'easeOutQuint', queue: false });
    },

    mainNavMouseLeave: function (e) {
        var el = $(e.currentTarget);
        if (!el.hasClass('current')) el.animate({ backgroundPosition: '250px 0', color: structure.mainNavOutColor }, { duration: 500, easing: 'easeInQuint', queue: false });
    },

    transition: {
        init: function () {
            if (!Modernizr.csstransitions) {
                $('#nav')
                    .bind('mouseenter', structure.transition.navEnter)
                    .bind('mouseleave', structure.transition.navLeave);
            }
        },

        navEnter: function (e) {
            var _this = $(e.currentTarget);

            _this.animate({ backgroundColor: '#331ef9' }, { duration: 800, queue: false, easing: 'easeOutExpo' });
        },

        navLeave: function (e) {
            var _this = $(e.currentTarget);

            _this.animate({ backgroundColor: '#1cade8' }, { duration: 800, queue: false, easing: 'easeOutExpo' });
        }
    }
};

$(document).ready(structure.init);
