
(function ($) {
    $(function () {

        /*$('body.home div.accordion h3').click(function () {
        if ($(this).parent().is('.active')) {
        $(this).siblings('.description').slideToggle(300);
        $(this).parent().removeClass('active');
        }
        else {
        $('body.home div.accordion .active div.description').slideToggle(300);
        $('body.home div.accordion .active').removeClass('active');
        $(this).siblings('.description').slideToggle(300);
        $(this).parent().addClass('active');
        }

        });*/

        $('fieldset.sfsearchBox input.sfsearchSubmit').remove();
        $('fieldset.sfsearchBox input.sfsearchTxt').after('<input class="sfsearchSubmit" type="button" value="Search" />');

        $('fieldset.sfsearchBox input.sfsearchTxt').remove();
        $('fieldset.sfsearchBox input.sfsearchSubmit').before('<input class="sfsearchTxt" type="text" />');

        $('fieldset.sfsearchBox input.sfsearchSubmit').click(function () {
            var textToSearch = $('fieldset.sfsearchBox input.sfsearchTxt').val();
            document.location.href = 'http://www.search.bostonbar.org/?query=' + encodeURIComponent(textToSearch);
            return false;
        });
        $('fieldset.sfsearchBox input.sfsearchTxt').keyup(function (event) {
            if (event.keyCode == 13) {
                $('fieldset.sfsearchBox input.sfsearchSubmit').click();
                return false;
            }
        });

        $('body.home div.accordion div.item').hoverIntent({
            over: makeTall,
            out: makeShort
        });

        function makeTall() {
            if ($(this).children('.description').is(":animated"))
                $(this).children('.description').stop(true, true).slideToggle(300);
            else
                $(this).children('.description').slideToggle(300);
            $(this).addClass('active');
        }

        function makeShort() {
            if ($(this).children('.description').is(":animated"))
                $(this).children('.description').stop(true, true).slideToggle(300);
            else
                $(this).children('.description').slideToggle(300);
            $(this).removeClass('active');
        }

        $('div#footer ul.rtsUL li:nth-child(2) a, div#footer ul.rtsUL li:nth-child(3) a').css("color", "#DB0029");



        /****** Menu highlights *******/

        $('div.highlight-placeholder > div.highlight').hover(
            function (e) {
                $(this).clearQueue().stop().show().css('opacity', 1);
            },
            function (e) {
                $(this).clearQueue().stop().css('opacity', 1).fadeOut('fast');
            }
        );

        $('div[id$="_rmShowed"]:first li.rmItem a').hover(
            function (e) {
                var $this = $(this);
                var $highlight = $('#' + $this.attr('rel'));
                var top = 0, left = 0, $pivot = $this, animate = false;


                if (!$this.is('a.rmRootLink')) {
                    var $rootLink = $this.parents('div.rmSlide:first').siblings('a.rmRootLink:first');
                    if ($highlight.length == 0) {
                        $highlight = $('#' + $rootLink.attr('rel'));
                    }

                    $pivot = $rootLink;
                }
                else animate = true;

                if ($highlight.length > 0) {
                    $highlight.css({
                        top: ($pivot.outerHeight() + 5) + 'px',
                        left: ($pivot.parent().position().left - $highlight.outerWidth() + 1) + 'px'
                    });
                    $highlight.clearQueue().stop().css('opacity', 1);
                    if (animate) $highlight.fadeIn('fast');
                    else $highlight.show();
                }
                $('div.highlight-placeholder > div.highlight:visible').not($highlight).clearQueue().stop().css('opacity', 1).hide();

            },
            function (e) {
                var $this = $(this);
                var $highlight = $('#' + $this.attr('rel'));

                if ($highlight.length == 0 && !$this.is('a.rmRootLink')) {
                    var $rootLink = $this.parents('div.rmSlide:first').siblings('a.rmRootLink');
                    $highlight = $('#' + $rootLink.attr('rel'));
                }

                $highlight.clearQueue().stop().css('opacity', 1).delay(500).fadeOut('fast');
            }
        );

    });
})(jQuery)
