<?php
/**
 * Implementation of hook_theme()
 */
function morelikethis_googlevideo_theme() {
  return array(
    'morelikethis_googlevideo_block' => array('arguments' => array('items' => NULL)),
    'morelikethis_googlevideo_item' => array('arguments' => array('item' => NULL)),
   );
}

/**
 * Implementation of hook_morelikethis()
 */
function morelikethis_googlevideo_morelikethis() {
  return array(
    'googlevideo' => array(
      '#title' => 'Google Video',
      '#description' => 'Lookup related content using Google Video Search Service',
      '#class' => 'MoreLikeThisGoogleVideo',
      '#classfile' => 'morelikethis_googlevideo.class.inc',
      '#settings' => 'morelikethis_googlevideo_settings',
    ),
  );
}

/**
 * Implementation of theme override for morelikethis block for this service
 *
 * @param array $items
 * @return HTML string.
 * @see morelikethis.module
 */
function theme_morelikethis_googlevideo_block($items) {
	$output = "";
	if($items) {
	  foreach($items as $item) {  
		  $output .= theme('morelikethis_googlevideo_item', $item);
	  }
	}
  return $output;
}

/**
 * Theme for HTML surrounding video player.
 *
 * @param string $video_bar_id
 * @param string $status_bar_id
 * @return HTML string
 */
function theme_morelikethis_googlevideo_item($item) {
	//$video_bar_id, $status_bar_id){
  $output = "<div class='google_video_wrapper'>";
  $output .= "<div id='". $item['video_bar_id'] ."'>Loading...</div>";
  $output .= "<div id='". $item['status_bar_id'] ."'>Loading...</div>";
  $output .= "</div>";
  return $output;
}

/**
 * FAPI definition for morelikethis Google video settings
 *
 * @ingroup forms
 */
function morelikethis_googlevideo_settings() {

  node_types_rebuild();
  $types = node_get_types('types', NULL, TRUE);
  $form['mlt_gv_description'] = array(
    '#prefix' => "<h4>",
    '#suffix' => "</h4>",
    '#value' => t('More Like This Google Video allows you to incorporate content from Google Video on a node page, using the applied MLT terms that meet the Term Relevancy Threshold for MLT Google Video requirement.'),
  );
  
  $form['gv_types'] = array(
    '#type' => 'fieldset',
    '#title' => t('Enabled Node Types'),
    '#description' => t('Designate a set of content types that will support More Like This Google Video'),
  );
  
  foreach($types as $type) {
    $key = drupal_strtolower($type->type);
    $form['gv_types']["morelikethis_gv_content_type_$key"] = array(
     '#type' => 'checkbox',
     '#title' => t($type->name),
     '#default_value' => variable_get("morelikethis_gv_content_type_$key", NULL),
    );
  }
	
  $form['googlevideo'] = array(
    '#type' => 'fieldset',
    '#title' => t('Google Video Bar Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#description' => "Video Bar Documentation can be found <a target='_blank' href='http://www.google.com/uds/solutions/videobar/reference.html'>here</a>",
  );
  
  $form['googlevideo']['morelikethis_gv_large_result_set'] = array(
    '#type' => 'select',
    '#title' => t('Result Set Size'),
    '#options' => array( 'true' => t("Large"), 'false' => t("Small") ),
    '#default_value' => variable_get('morelikethis_gv_large_result_set', 'false'),    
    '#description' => t('Define the maximum number of results returned by Google Video (small = 4 results, large = 8 results).'),
  );
  $form['googlevideo']['morelikethis_gv_orient'] = array(
    '#type' => 'select',
    '#title' => t('Orientation'),
    '#description' => t('Choose an orientation for the video bar (horizontal row or vertical column).'),
    '#options' => array( 'true' => t('Horizontal'), 'false' => t('Vertical')),
    '#default_value' => variable_get('morelikethis_gv_orient', 'true'),    
  );  
  $form['googlevideo']['morelikethis_gv_cycle_time'] = array(
    '#type' => 'select',
    '#title' => t('Video Bar Cycle Time'),
    '#description' => t('Define the amount of time that elapses between refresh cycles (i.e. results set is larger than the number of videos that can be shown at once).'),
    '#options' => array(
      'GSvideoBar.CYCLE_TIME_SHORT' => t('CYCLE_TIME_SHORT // ~10s'),
      'GSvideoBar.CYCLE_TIME_MEDIUM' => t('CYCLE_TIME_MEDIUM // ~15s'),
      'GSvideoBar.CYCLE_TIME_LONG' => t('CYCLE_TIME_LONG // ~30s'),
    ),
    '#default_value' => variable_get('morelikethis_gv_cycle_time', 'GSvideoBar.CYCLE_TIME_SHORT'),
  );
  $form['googlevideo']['morelikethis_gv_cycle_mode'] = array(
    '#type' => 'select',
    '#title' => t('Video Bar Cycle Mode'),
    '#description' => t('Choose between random and sequential cycles.'),
    '#options' => array(
      'GSvideoBar.CYCLE_MODE_LINEAR' => t('CYCLE_MODE_LINEAR'),
      'GSvideoBar.CYCLE_MODE_RANDOM' => t('CYCLE_MODE_RANDOM'),
      ),
    '#default_value' => variable_get('morelikethis_gv_cycle_mode', 'GSvideoBar.CYCLE_MODE_LINEAR'),
  );
  $form['googlevideo']['morelikethis_gv_use_statusroot'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Status Root'),
    '#description' => t('Allow users to manually advance the rotation by clicking on links that correspond to the MLT terms utilized.'),
    '#default_value' => variable_get('morelikethis_gv_use_statusroot', TRUE),
  );  
  $form['googlevideo']['morelikethis_gv_statusroot_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Status Root CSS ID'),
    '#description' => t('HTML ID for this container of the status root.'),
    '#default_value' => variable_get('morelikethis_gv_statusroot_id', 'videoBarStatus'),
  );  
  $form['googlevideo']['morelikethis_gv_videobar_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Video Bar CSS ID'),
    '#description' => t('HTML ID for this container of the video bar.'),
    '#default_value' => variable_get('morelikethis_gv_videobar_id', 'google_video_like_this_bar'),
  );  

  return system_settings_form($form);
}
