var $featured_content = $nc('#featured'),
    disable_toptier = $nc("meta[name=disable_toptier]").attr('content'),
    featured_slider_auto = $nc("meta[name=featured_slider_auto]").attr('content'),
    featured_auto_speed = $nc("meta[name=featured_auto_speed]").attr('content');

if ($featured_content.length) {
    (function ($) {
        $.fn.switcher = function (options) {
            var defaults = {
                slides: '>div',
                activeClass: 'active',
                linksNav: '',
                findParent: true,
                //use parent elements in defining lengths
                lengthElement: 'li',
                //parent element, used only if findParent is set to true
                useArrows: false,
                arrowLeft: 'prevlink',
                arrowRight: 'nextlink',
                auto: false,
                autoSpeed: 5000
            };

            var options = $.extend(defaults, options);

            return this.each(function () {
                var slidesContainer = $nc(this);
                slidesContainer.find(options.slides).hide().end().find(options.slides).filter(':first').css('display', 'block');

                if (options.linksNav != '') {
                    var linkSwitcher = $nc(options.linksNav);

                    linkSwitcher.click(function () {
                        var targetElement;

                        if (options.findParent) targetElement = $nc(this).parent();
                        else targetElement = $nc(this);

                        if (targetElement.hasClass('active')) return false;

                        targetElement.siblings('.active').removeClass('active');
                        targetElement.addClass('active');

                        var ordernum = targetElement.prevAll(options.lengthElement).length;

                        slidesContainer.find(options.slides).filter(':visible').hide().end().end().find(options.slides).filter(':eq(' + ordernum + ')').stop().fadeIn(700);

                        if (typeof interval != 'undefined') {
                            clearInterval(interval);
                            auto_rotate();
                        };

                        return false;
                    });
                };

                $nc('#' + options.arrowRight + ', #' + options.arrowLeft).click(function () {

                    var slideActive = slidesContainer.find(options.slides).filter(":visible"),
                        nextSlide = slideActive.next(),
                        prevSlide = slideActive.prev();

                    if ($nc(this).attr("id") == options.arrowRight) {
                        if (nextSlide.length) {
                            var ordernum = nextSlide.prevAll().length;
                        } else {
                            var ordernum = 0;
                        }
                    };

                    if ($nc(this).attr("id") == options.arrowLeft) {
                        if (prevSlide.length) {
                            var ordernum = prevSlide.prevAll().length;
                        } else {
                            var ordernum = slidesContainer.find(options.slides).length - 1;
                        }
                    };

                    slidesContainer.find(options.slides).filter(':visible').hide().end().end().find(options.slides).filter(':eq(' + ordernum + ')').stop().fadeIn(700);

                    if (typeof interval != 'undefined') {
                        clearInterval(interval);
                        auto_rotate();
                    };

                    return false;
                });

                if (options.auto) {
                    auto_rotate();
                };

                function auto_rotate() {
                    interval = setInterval(function () {
                        var slideActive = slidesContainer.find(options.slides).filter(":visible"),
                            nextSlide = slideActive.next();

                        if (nextSlide.length) {
                            var ordernum = nextSlide.prevAll().length;
                        } else {
                            var ordernum = 0;
                        }

                        if (options.linksNav === '') $nc('#' + options.arrowRight).trigger("click");
                        else linkSwitcher.filter(':eq(' + ordernum + ')').trigger("click");
                    }, options.autoSpeed);
                };
            });
        }
    })($nc);

    var featured_options = {
        linksNav: '#switcher a',
        auto: false,
        autoSpeed: featured_auto_speed,
        findParent: false,
        lengthElement: 'a'
    }

    if (featured_slider_auto == 1) featured_options.auto = true;

    $featured_content.switcher(featured_options);

    var $controllers_box = $nc('#controllers #switcher'),
        controllers_offset = Math.round((960 - ($controllers_box.width())) / 2);

    $controllers_box.css('marginLeft', controllers_offset);
}

;
(function ($) {
    $.fn.superfish = function (op) {};
})($nc);
