<?php

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

/**
 * 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',
      'pattern' => 'views_slideshow_cycle__',
    ),
    'views_slideshow_cycle_main_frame' => array(
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => NULL, 'rows' => NULL),
      'template' => 'theme/views-slideshow-cycle-main-frame',
      'pattern' => 'views_slideshow_cycle_main_frame__',
    ),
    'views_slideshow_cycle_main_frame_row' => array(
      'variables' => array('vss_id' => NULL, 'items' => NULL, 'count' => NULL, 'view' => NULL),
      'template' => 'theme/views-slideshow-cycle-main-frame-row',
      'pattern' => 'views_slideshow_cycle_main_frame_row__',
    ),
    'views_slideshow_cycle_main_frame_row_item' => array(
      'variables' => array('item' => NULL, 'item_count' => NULL, 'count' => NULL, 'view' => NULL, 'length' => NULL),
      'template' => 'theme/views-slideshow-cycle-main-frame-row-item',
      'views_slideshow_cycle_main_frame_row_item__',
    ),
  );
}

/**
 * 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;
  }
}

/**
 * Gets the path to the jQuery cycle library.
 *
 * @return
 *   The path to the cycle library js file, or FALSE if not found.
 */
function _views_slideshow_cycle_library_path() {
  $cycle_path = libraries_get_path('jquery.cycle');

  if (!empty($cycle_path)) {
    // Attempt to use minified version of jQuery cycle plugin.
    if (file_exists($cycle_path . '/jquery.cycle.all.min.js')) {
      $cycle_path .= '/jquery.cycle.all.min.js';
    }
    // Otherwise use non-minified version if available.
    elseif (file_exists($cycle_path . '/jquery.cycle.all.js')) {
      $cycle_path .= '/jquery.cycle.all.js';
    }
    else {
      $cycle_path = FALSE;
    }
  }
  else {
    $cycle_path = FALSE;
  }

  return $cycle_path;
}

/**
 * Gets the path to the jQuery pause library.
 *
 * @return
 *   The path to the pause library js file, or FALSE if not found.
 */
function _views_slideshow_cycle_pause_library_path() {
  $pause_path = libraries_get_path('jquery.pause');

  if (!empty($pause_path)) {
    // Attempt to use minified version of jQuery pause plugin.
    if (file_exists($pause_path . '/jquery.pause.min.js')) {
      $pause_path .= '/jquery.pause.min.js';
    }
    // Otherwise use non-minified version if available.
    elseif (file_exists($pause_path . '/jquery.pause.js')) {
      $pause_path .= '/jquery.pause.js';
    }
    else {
      $pause_path = FALSE;
    }
  }
  else {
    $pause_path = FALSE;
  }

  return $pause_path;
}


/**
 * Need to have preprocess functions here because drupal doesn't cache them
 * correctly in the theme.inc file.
 *
 * If you would like to override the preprocess functions make sure to look at
 * the associated function in theme.inc.
 */

// Trying to make sure the theme.inc get's loaded.
include_once('theme/views_slideshow_cycle.theme.inc');

function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
  _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame($vars);
}

function template_preprocess_views_slideshow_cycle_main_frame_row(&$vars) {
  _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame_row($vars);
}

function template_preprocess_views_slideshow_cycle_main_frame_row_item(&$vars) {
  _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame_row_item($vars);
}
