$ef(document).ready(function() {

    // JS For in Logged In
    if ($ef('#adminbar #pagebar').length) {
        if ($ef('#adminbar #toolbar').length) {
            $ef('#featuredRotator .sortContainer').cycle({
                fx: 'fade',
                timeout: 0,
				cleartypeNoBg: true,
                next: '#next',
                prev: '#prev'
            });
            $ef("#prev, #next").show();
            // $ef("#featuredRotator").css({"marginTop":"-36px"});
            $ef("#featured").css({
                "overflow": "visible"
            });
        }
        // JS For in Preview Mode
        else {
            $ef('#featuredRotator').before('<ul id="featuredNav">').cycle({
                fx: 'fade',
                pager: '#featuredNav',
				cleartypeNoBg: true,
                // callback fn that creates a thumbnail to use as pager anchor
                pagerAnchorBuilder: function(idx, slide) {
                    var imgPath = $ef("img", slide).attr('src');
                    return '<li><a href="#"><img src="' + imgPath + '" width="65" height="37" /></a></li>';
                }
            });
            $ef("#featuredRotatorWrapper").mouseenter(function() {
                $ef('#featuredNav').fadeIn();
            });
            $ef("#featuredRotatorWrapper").mouseleave(function() {
                $ef('#featuredNav').fadeOut();
            });
            $ef("#subFeatured").mouseleave(function() {
                $ef(this).children('div').animate({
                    opacity: 1.0
                });
            });
            $ef(".subBox").mouseenter(function() {
                $ef(this).animate({
                    opacity: 1.0
                });
                $ef(this).siblings('div').animate({
                    opacity: 0.5
                });
            });
        }
    }
    // JS For When Not Logged In
    else {
        $ef('#featuredRotator').before('<ul id="featuredNav">').cycle({
            fx: 'fade',
            timeout: "5000",
            speed: '1000',
            pager: '#featuredNav',
			cleartypeNoBg: true,
            // callback fn that creates a thumbnail to use as pager anchor
            pagerAnchorBuilder: function(idx, slide) {
                var imgPath = $ef("img", slide).attr('src');
                return '<li><a href="#"><img src="' + imgPath + '" width="65" height="37" /></a></li>';
            }
        });


        $ef("#featuredRotatorWrapper").mouseenter(function() {
            $ef('#featuredNav').fadeIn();
        });
        $ef("#featuredRotatorWrapper").mouseleave(function() {
            $ef('#featuredNav').fadeOut();
        });


        // $ef("#subFeatured").mouseleave(function() {
        //     $ef(this).children('div').animate({
        //         opacity: 1.0
        //     });
        // });
        // $ef(".subBox").mouseenter(function() {
        //     $ef(this).animate({
        //         opacity: 1.0
        //     });
        //     $ef(this).siblings('div').animate({
        //         opacity: 0.5
        //     });
        // });


        // News and Events Tabs
        function buildPager(ind, slide) {

            ind++;
            var tabTitle = $ef('.container', slide).remove().text();

            if (tabTitle.replace(/s/g, '') == '') {
                tabTitle = 'slide ' + ind
            }

            return '<li class="tab-' + ind + '"><a href="#">' + tabTitle + '</a></li>';

        }
        $ef('#newsEvents').cycle({
            fx: 'fade',
            speed: '300',
            timeout: 0,
			cleartypeNoBg: true,
			cleartype: true,
            height: 'auto',
            pager: '#newsEventsHeader',
            pagerAnchorBuilder: buildPager
        });
    }

});
