/**
 * Stub for Map Carousel.
 * @author Guy Whitfield
 */
rn.PanelMapCarousel = function () {
    var that = this;

    this.init = function () {
        this.parent.init.call(this);
        this.domNode = $('#panel-carousel');
        this.setDomElements();
    };

    this.setDomElements = function () {

        $('#panel-carousel .close').click(function () {
            that.toggleCarousel(this);
        });

        $('#panel-carousel .header').click(function () {
            that.toggleCarousel();
        });


        //  Ops_Carousel
        this.slider = $('.ops_carousel').bxSlider({ infiniteLoop: false, hideControlOnEnd: true });
        this.setItemOpacity();

        $('.bx-next').click(function () {
            that.setItemOpacity();
        });

        $('.bx-prev').click(function () {
            that.setItemOpacity();
        });

    }

    this.setItemOpacity = function () {
        var index = this.slider.getCurrentSlide() + 2;
        $('.ops_carousel li').animate({ opacity: '0.2' }, 100);
        jqselector = ".ops_carousel li:nth-child(" + index + ")";
        $(jqselector).animate({ opacity: '1' }, 400);
        return;
    }

    this.toggleCarousel = function (domNode) {

        var textNode = domNode || '#panel-carousel .close';

        var carousel = $('.global-ops-popup-carousel');
        if (carousel.height() > 0) {
            rn.Events.fireGlobalEvent(rn.Events.registry.EVENT_MAP_CAROUSEL_CLOSE, {});
            carousel.animate({ height: 0 }, 500);
            $(textNode).attr('title', 'Open').text('Open');

        } else {
            rn.Events.fireGlobalEvent(rn.Events.registry.EVENT_MAP_CAROUSEL_OPEN, {});
            carousel.animate({ height: 140 }, 500);
            $(textNode).attr('title', 'Close').text('Close');
        }
    }

    /**
    * EVENT LISTENERS
    */

    this.onPanelVesselOpen = function () {
        $('.global-ops-popup-carousel').animate({ height: 0 }, 500);
        $('#panel-carousel .close').attr('title', 'Open').text('Open');
    }

    return this;
}

rn.PanelMapCarousel.prototype = new rn.Panel();
rn.PanelMapCarousel.constructor = rn.PanelMapCarousel;
rn.panelMapCarousel = new rn.PanelMapCarousel();
rn.panelMapCarousel.parent = rn.PanelMapCarousel.prototype;

