SITE.navbar = function() {

    var $links = null;

    /**
     * Toggles the button to animate up or down based on its current state
     * 
     * @author gabrielh
     * @context The <li> element that triggers the mouseover/out event
     */
    var toggle = function() {

        var $button = $(this);

        if ( $button.hasClass('hover') ) {
            SITE.navbar.animate($button.removeClass('hover'), {
                marginTop : 0,
                height : $links.ogHeight,
                time : CONFIG.navBarOutAnimateTime,
                easing : CONFIG.navBarOutEasing
            });
        } else {
            SITE.navbar.animate($button.addClass('hover'), {
                marginTop : - CONFIG.navBarHeightIncrease,
                height : $links.ogHeight + CONFIG.navBarHeightIncrease,
                time : CONFIG.navBarOverAnimateTime,
                easing : CONFIG.navBarOverEasing
            });
        }

    };

    var toggle1 = function(evt)
    {
        $(evt.target).parent('li').addClass('hover');
        $(evt.target).parent('li').siblings().stop().animate({marginTop:0, height:'36px'});
        $(evt.target).parents('ul').css({marginTop:0, height:'36px'});
        $(evt.target).parent('li').stop().animate({marginTop:'-10px', height:'46px'});               
    };
    
    var toggle2 = function(evt)
    {
        $(evt.target).parent('li').removeClass('hover');
        $(evt.target).parent('li').stop().animate({marginTop:0, height:'36px'});
    };

    return {

        /**
         * Animates the passed button to the properties declared in the passed options
         * 
         * @author gabrielh
         * @param {Object} $button The <li> you wish to animate
         * @param {Object} options The options object which contains the following properties
         *     @property {Integer} marginTop The new margin-top property of the button
         *     @property {Integer} height The new height property of the button
         *     @property {Integer} time The time you would like the animation to occur in
         *     @property {String} easing The easing you would like the animation to use
         * @returns {Object} The button that was originally passed in     
         */
        animate : function ( $button, options ) {

            $button.stop().animate(
                {
                    marginTop: options.marginTop,
                    height: options.height
                }, options.time, options.easing
            );
            
            return $button;

        },

        /**
         * Sets the hover behavior for navbar links
         * 
         * @author gabrielh
         */
        init : function() {

            //-- Set private variables
            $links = $('#dvPageHeaderBottomNav li');
            $links.ogHeight = parseInt($links.css('height'), 10);

            //-- Add the hover actions
            //$links.hover(toggle);
            $links.hover(toggle1, toggle2);

        }

    };

} ();
$(document).ready(
    function() {
        SITE.navbar.init();
    }
);

SITE.subnav = function() {

    var $shadow = null,
        $subnav = null,
        $navbar = null;

    return {

        /**
         * Scrolls the window to the element contained in the rel attribute of the passed anchor
         * 
         * @author gabrielh
         * @context The anchor element that fired the event
         * @returns {Boolean} A false boolean value
         */
        goToAnchor : function() {
            $scrollTo = $(this).attr('rel');
            if ( $scrollTo.length ) {
                COMMON.scrollWindowToElem($scrollTo, true);
            }
            return false;
        },

        /**
         * Sets up the subnav bar behavior
         * 
         * @author gabrielh
         * @returns {Object} SITE.subnav
         */
        init : function() {

            $shadow = $('#dvPageHeaderShadow');
            $subnav = $('#dvSubNavBar');
            $wrapper = $('#dvPageBody div.wrapper');

            //-- Increase the wrapper padding
            $wrapper.css('padding-top', parseInt($subnav.height(), 10));

            //-- Alter the position of the shadow
            $shadow.css({
                top : parseInt($shadow.css('top'), 10) + parseInt($subnav.height(), 10)
            });

            //-- Set the link behavior
            $subnav.find('a').click(this.goToAnchor);

            return this;

        }
    };

} ();
$(document).ready(
    function() {
        SITE.subnav.init();
    }
);
