<?php
include_once "tadtools_header.php";
include_once "jquery.php";

class slider{
  var $show_jquery;
  var $word_num;
  var $item=array();

  //建構函數
  function slider($word_num=60,$show_jquery=true){
    $this->word_num = $word_num;
    $this->show_jquery = $show_jquery;
  }

  function add_content($sn="",$title="",$content="",$image="",$date="",$url=""){
    $this->item[$sn]['title']=$title;
    $this->item[$sn]['content']=$content;
    $this->item[$sn]['image']=$image;
    $this->item[$sn]['date']=$date;
    $this->item[$sn]['url']=$url;
  }

  //產生語法
  function render(){
    $utf8_word_num = $this->word_num * 3;
    if(empty($utf8_word_num))$utf8_word_num=90;
    $jquery=($this->show_jquery)?get_jquery():"";

    $all=$nav="";
    $i=1;
    foreach($this->item as $sn => $item_content){
      $title=xoops_substr(strip_tags($item_content['title']), 0, 45);
      $content=xoops_substr(strip_tags($item_content['content']), 0, $utf8_word_num);

      $pi=($i%2)?"1":"2";
      $image=empty($item_content['image'])?TADTOOLS_URL."/ResponsiveSlides/images/demo{$pi}.jpg":$item_content['image'];

      $caption=($content)?"
      <div class='caption'>
      <div style='font-size:11pt;color:#33CCFF;font-weight:bold;'>{$title}</div>
      <div style='font-size:11px;'>{$content}</div>
      </div>":"";

      $all.="
        <li>
          <a href='{$item_content['url']}'><img src='$image' alt='{$title}' title='{$title}' /></a>
        </li>
      ";

      $nav.="<li><span>{$i}</span></li>";
      $i++;
    }

    $main="
    <link rel='stylesheet' type='text/css' href='".TADTOOLS_URL."/ResponsiveSlides/reset.css' />
    <link rel='stylesheet' type='text/css' href='".TADTOOLS_URL."/ResponsiveSlides/responsiveslides.css' />
    $jquery
    <script language='javascript' type='text/javascript' src='".TADTOOLS_URL."/ResponsiveSlides/responsiveslides.js'></script>

    <script type='text/javascript'>
     $(document).ready( function(){
        $('#ResponsiveSlides').responsiveSlides({
          auto: true,
          pager: false,
          nav: true,
          speed: 800,
          pause: true,
          pauseControls: true,
          namespace: 'callbacks'
        });
      });
    </script>
    <!-- Place somewhere in the <body> of your page -->
    <div class='rslides_container'>
      <ul class='rslides' id='ResponsiveSlides'>
        $all
      </ul>
    </div>
    <div class=\"clearfix\"></div>
    ";
    return $main;
  }

}
?>
