var BentleighFC = {

    HomePageSlider: {
        /* Dots Slider 1 */
        init: function () {
            $('#imageSlider').after('<div id="imageSliderNav">').cycle({
                fx: 'fade',
                speed: 1550,
                timeout: 10000,
                pager: '#imageSliderNav'
            });
        }
    },

    HeaderSponsors: {
        init: function () {

            $(function () {
                $('.sponsorSlider').cycle({
                    fx: 'fade',
                    speed: 1000,
                    timeout: 6000
                });
            });
        }
    },

    Navigation: {

        Active: false, // boolean that tracks whether subnav is active
        NavId: 'topNavigation',
        SubNavClass: 'sub-nav',
        ActiveClass: 'current', // top-level nav active class

        init: function () {
            if (!$('#' + this.NavId).length) { return false; }
            this.initTopLevel();
        },

        initTopLevel: function () {

            var navitems = this.getTopLevel();

            navitems.bind({
                mouseenter: function () {
                    if (BentleighFC.Navigation.hideAllSubNav()) {

                        BentleighFC.Navigation.showSubNav($(this));
                    }
                },
                mouseleave: function () {
                    BentleighFC.Navigation.hideSubNav($(this));
                }
            });
        },

        showSubNav: function (navitem) {
            this.Active = true;
            var link = this.getNavLink(navitem);
            var subnav = this.getNavSubNav(navitem);

            link.addClass(this.ActiveClass);

            if ($.browser.msie) {
                subnav.show();
            } else {
                setTimeout(function () {
                    if (link.hasClass(BentleighFC.Navigation.ActiveClass)) {
                        subnav.stop(false, true).fadeIn(100, function () { subnav.show(); });
                    }
                }, 100);
            }
        },

        hideSubNav: function (navitem) {
            this.Active = false;
            var link = this.getNavLink(navitem);
            var subnav = this.getNavSubNav(navitem);

            link.removeClass(this.ActiveClass);

            if ($.browser.msie) {
                subnav.hide();
            } else {
                setTimeout(function () {
                    if (!(link.hasClass(BentleighFC.Navigation.ActiveClass))) {
                        subnav.stop(false, true).fadeOut(100, function () { subnav.hide(); });
                    }
                }, 125);
            }

        },

        getTopLevel: function () {
            return $('#' + this.NavId).children('li');
        },

        getNavLink: function (navitem) {
            return $(navitem.children('a')[0]);
        },

        getNavSubNav: function (navitem) {
            return $(navitem.find('.' + this.SubNavClass)[0]);
        },

        hideAllSubNav: function () {
            $('#' + this.NavId).children('li').children('a').removeClass(this.ActiveClass);
            $('.' + this.SubNavClass).stop(false, true).hide();
            return true;
        }

    } // EO BentleighFC.Navigation
};


$(document).ready(function () {
    BentleighFC.HomePageSlider.init();
    BentleighFC.HeaderSponsors.init();
    BentleighFC.Navigation.init();
});

