<?php
$slidersModel = new N2SmartsliderSlidersModel();

$orderBy          = N2SmartSliderSettings::get('slidersOrder2', 'ordering');
$orderByDirection = N2SmartSliderSettings::get('slidersOrder2Direction', 'ASC');

$sliders = $slidersModel->getAll($groupID, $orderBy, $orderByDirection);

$router = $appType->router;
?>
<script type="text/javascript">
    N2R('documentReady', function ($) {
        var selected = null;
        window.selectSlider = function (el, mode, sliderIDorAlias, sliderID) {
            if (selected !== null) {
                selected.removeClass('n2-active');
            }
            window.parent.postMessage(JSON.stringify({
                "action": "ss3embed",
                "mode": mode,
                "value": sliderIDorAlias,
                "sliderID": sliderID
            }), "*");
            selected = $(el).addClass('n2-active');
            setTimeout(function () {
                selected.removeClass('n2-active');
            }, 1000);
        }
    });
</script>
<div id="n2-ss-slider-container" data-groupid="<?php echo $groupID; ?>">
    <div class="n2-ss-sliders">
        <div class="n2-ss-sliders-container">
            <?php

            if ($groupID > 0) {
                echo N2Html::tag('div', array(
                    'class'   => 'n2-box n2-box-full n2-box-up-group n2-h3 n2-uc',
                    'onclick' => 'window.location="' . $router->createUrl(array(
                            'sliders/' . $mode,
                            array(
                                'groupID' => 0
                            )
                        )) . '"'
                ), N2Html::link(n2_('UP'), '#', array(
                    'class' => 'n2-button n2-button-l n2-button-grey n2-radius-s n2-uc n2-h3'
                )));

                $attributes = array(
                    'class' => 'n2-box n2-box-full n2-box-insert-group n2-h3 n2-uc'
                );
                if (empty($group['alias'])) {
                    $attributes['onclick'] = 'selectSlider(this, "id", "' . $group['id'] . '", "' . $group['id'] . '");';
                } else {
                    $attributes['onclick'] = 'selectSlider(this, "alias", "' . $group['alias'] . '", "' . $group['id'] . '");';
                }


                if ($mode == 'embed') {
                    echo N2Html::tag('div', $attributes, N2Html::link(n2_('Insert group'), '#', array(
                        'class' => 'n2-button n2-button-l n2-button-green n2-radius-s n2-uc n2-h3'
                    )));
                }
            }
            foreach ($sliders AS $sliderObj) {
                echo N2SmartsliderSlidersModel::embedBox($mode, $sliderObj, $appType);
            }
            ?>

            <div class="n2-clear"></div>
        </div>
    </div>
</div>