<?php

/**
 * @file
 * Views Slideshow: cycle is typically used for field views.
 */

/**
 * Implements hook_init().
 */
function views_slideshow_cycle_init() {
  // Load jQuery Cycle
  $cycle_path = libraries_get_path('jquery.cycle');
  if (!empty($cycle_path) && file_exists($cycle_path . '/jquery.cycle.all.min.js')) {
    drupal_add_js($cycle_path . '/jquery.cycle.all.min.js');
  }
  
  // Load Json2
  $json_path = libraries_get_path('json2');
  if (!empty($json_path) && file_exists($json_path . '/json2.js')) {
    drupal_add_js($json_path . '/json2.js');
  }

  // Load our cycle js
  $module_path = drupal_get_path('module', 'views_slideshow_cycle');
  drupal_add_js($module_path . '/js/views_slideshow_cycle.js');
  
  // Load our cycle css
  drupal_add_css($module_path . '/views_slideshow_cycle.css', 'file');
}

/**
 * Implements hook_theme().
 */
function views_slideshow_cycle_theme($existing, $type, $theme, $path) {
  return array(
    'views_slideshow_cycle' => array(
      'variables' => array('view' => NULL, 'settings' => array(), 'rows' => array(), 'title' => ''),
      'template' => 'theme/views-slideshow-cycle',
      'file' => 'theme/views_slideshow_cycle.theme.inc',
    ),
    'views_slideshow_cycle_main_frame' => array(
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => NULL, 'rows' => NULL),
      'template' => 'theme/views-slideshow-cycle-main-frame',
      'file' => 'theme/views_slideshow_cycle.theme.inc',
    ),    
    'views_slideshow_cycle_main_frame_row' => array(
      'variables' => array('vss_id' => NULL, 'items' => NULL, 'count' => NULL),
      'template' => 'theme/views-slideshow-cycle-main-frame-row',
      'file' => 'theme/views_slideshow_cycle.theme.inc',
    ),
    'views_slideshow_cycle_main_frame_row_item' => array(
      'variables' => array('item' => NULL, 'item_count' => NULL),
      'template' => 'theme/views-slideshow-cycle-main-frame-row-item',
      'file' => 'theme/views_slideshow_cycle.theme.inc',
    ),
  );
}

/**
 * Implements hook_help().
 */
function views_slideshow_cycle_help($path, $arg) {
  switch ($path) {
    case 'admin/help#views_slideshow_cycle':
      if (module_exists('advanced_help')) {
        $output = '<p>' . l('Click here to view the documentation for Views Slideshow Cycle.',  'admin/advanced_help/views_slideshow_cycle') . '</p>';
      }
      else {
        $output = '<p>' . t('Views Slideshow Cycle help can be found by installing and enabling the !advanced_help',  array('!advanced_help' => l('Advanced Help module', 'http://drupal.org/project/advanced_help'))) . '</p>';
      }
      return $output;
  }
}