/*
 * jquery-powerpush.js
*/

(function () {

  $(function () {

/* !jQuery Object */

    var $powerPush = $('#powerPush');
    var $pageSliderContents = $powerPush.find('section');


/* !プロパティ */    

    var pageTotal = Math.ceil($pageSliderContents.length / 3);
    var contentsData = [];


/* !初期化 */
    
    // ページの数だけ空の配列を用意する
    for (var i = 0; i < pageTotal; i++) {
      contentsData[i] = '';
    }
    
    // コンテンツの数だけ繰り返す
    for (var i = 0; i < $pageSliderContents.length; i++) {
      
      var $target = $pageSliderContents.eq(i);
      var $title = $target.find('h3');
      var $description = $target.find('.description');
      
      var index = Math.floor(i / 3);
      var titleText = $title.text();
      var descriptionText = $description.text();
      
      if (titleText.length > 13) {
        var text = titleText.substr(0,13) + '...';
        $title.text(text);
      }
      
      if (descriptionText.length > 14) {
        var text = descriptionText.substr(0,14) + '...';
        $description.text(text);
      }
      
      contentsData[index] += '<section class="' + $target.attr('class') + '">' + $target.html() + '</section>';
    }
    
    // プラグインを実行する
    $powerPush.pageSlider({
      autoPlay : true,
      interval : 4000,
      duration : 500,
      easing : 'swing'
    });
    
    // プラグインにページを追加する
    $powerPush.pageSlider.addPage(contentsData);
    
    $pageSliderContents = $powerPush.find('section');
    
    $pageSliderContents.fadeIn(400);
    
  });

})(jQuery);

