<?php

/*
 * 컨텐츠 슬라이더
 */
if (!defined('_GNUBOARD_')) {
    exit;
}

function plugin_parallaxcontentslider($tag) {
    global $g5;
    $attach_url = G5_DATA_URL . "/asktheme_attach";
    $cfg = get_plugin_config('parallaxcontentslider'); //플러그인 환경설정
    //플러그인 미설정 중지
    if (!$cfg) {
        return false;
    }
    //플러그인 미사용 중지
    if ($cfg['pc_use'] == 0) {
        return false;
    }
    $sql = "select * from ask_plugin_cslider_parent where acp_area = '{$tag}'";
    $parent = sql_fetch($sql);
    if ($parent['acp_status'] == '1') {
        $sql = "select ac_idx, ac_parent_idx, ac_status, ac_subject, ac_content, ac_image_name, ac_link, ac_mime, ac_sort from ask_plugin_cslider where ac_parent_idx = '{$parent['acp_idx']}' and ac_status = '1' order by ac_sort";
        $result = sql_query($sql);
        $str = "<div class='ask-row-fluid'>
                        <div id='contents-slider'>
                            <div id='da-slider' class='da-slider' style='background: transparent url(" . G5_PLUGIN_URL . "/asktheme/plugin/parallaxcontentslider/images/{$parent['acp_bg']}) repeat 0% 0%;'>";
        for ($i = 0; $rows = sql_fetch_array($result); $i++) {
            if (!$rows['ac_link']) {
                $link = "#link";
            } else {
                $link = $rows['ac_link'];
            }
            $str .= "<div class='da-slide'>
                        <h2>{$rows['ac_subject']}</h2>
                        <p>{$rows['ac_content']}</p>
                        <a href='{$link}' class='da-link'>Read more</a>
                        <div class='da-img'><img src='{$attach_url}/{$rows['ac_image_name']}'/></div>
                    </div>";
        }//for
        $str .= "

                                <nav class='da-arrows'>
                                    <span class='da-arrows-prev'></span>
                                    <span class='da-arrows-next'></span>
                                </nav>
                            </div>
                        </div>    
                    </div>";
        $str .= '<script type="text/javascript">
    $(function () {
        //메인슬라이더
        $(\'#da-slider\').cslider({
            autoplay: true,
            bgincrement: 450
        });
    });
</script>';
        if ($str) {
            add_stylesheet('<link rel="stylesheet" href="' . G5_PLUGIN_URL . "/asktheme/plugin/parallaxcontentslider/parallaxcontentslider.css" . '">');
            add_javascript('<script src="' . G5_PLUGIN_URL . '/asktheme/plugin/parallaxcontentslider/parallaxcontentslider.js"></script>');
        }
        echo $str;
    }//if
}