public static function carousel(array $items, array $attributes = array()) {
        self::$carousels++;
        $id = (isset($attributes['id'])) ? $attributes['id'] : 'myCarousel' . self::$carousels;
        $class = (isset($attributes['class'])) ? $attributes['class'] . ' carousel slide' : 'carousel slide';
        $attributes['id'] = $id;
        $attributes['class'] = $class;
        $controls = (isset($attributes['controls']) && !$attributes['controls']) ? false : true;
        unset($attributes['controls']);
        ob_start();
        ?>
        <div <?= self::parseAttributes($attributes) ?> >
            <!-- Carousel items -->
            <div class="carousel-inner">
                <?php foreach ($items as $t_id => $item): ?>
                    <?php if (isset($item['img'])): ?>
                        <div id="<?= $t_id ?>" class="item <?= (isset($item['active']) && $item['active']) ? 'active' : '' ?>">
                            <?= $item['img'] ?>
                            <?php if (isset($item['caption'])): ?>
                                <div class="carousel-caption">
                                    <?= $item['caption'] ?>
                                </div>
                            <?php endif; ?>
                        </div>
                    <?php endif; ?>
                <?php endforeach; ?>
            </div>
            <?php if ($controls): ?>
                <!-- Carousel nav -->
                <a class="carousel-control left" href="#<?= $id ?>" data-slide="prev">&lsaquo;</a>
                <a class="carousel-control right" href="#<?= $id ?>" data-slide="next">&rsaquo;</a>
            <?php endif; ?>
        </div>
        <?php
        if (self::$addCarouselJs):
            self::$addCarouselJs = false;
            ?>
            <script>
                function positionActiveImg(container) {
                    if (!container)
                        container = '.carousel';
                    $.each($(container).children('.carousel-inner'), function (i, inner) {
                        var img = $(inner).children('.item.active').children('img');
                        $(img).on('complete', function () {
                            $(img).css({'margin-left': (($(inner).width() - $(img).width()) / 2)});
                            $(inner).css({'margin-top': (($(inner).parent().height() - $(inner).height()) / 2)});
                        });
                    });
                }

                function resizeImgs(container) {
                    if (!container)
                        container = '.carousel';
                    $.each($(container), function (i, v) {
                        if ($(v).height())
                            var h = ($(v).height() > $(v).width()) ? $(v).width() : $(v).height();
                        else
                            var h = $(v).width();

                        h = (!h) ? 'auto' : h;
                        $.each($(this).children('.carousel-inner').children().children('img'), function (i, value) {
                            $(value).css({height: h, width: 'auto'});
                        });
                    });

                    setTimeout(positionActiveImg, 1000, container);
                }
            </script>
        <?php endif; ?>
        <script>
            $(document).ready(function () {
                $('#<?= $id ?>').carousel();
                resizeImgs('#<?= $id ?>');
            });
        </script>
        <?php
        return ob_get_clean();
    }