<?php
function _digett_block_random_image_configure($block=array()){
  $galleries = array();
  if ($tree = taxonomy_get_tree(_image_gallery_get_vid())) {
    foreach ($tree as $term) {
      $galleries[$term->tid] = _taxonomy_depth($term->depth) .' '. $term->name;
    }
  }
  $img_sizes = _image_get_sizes();
  foreach($img_sizes as $size){
    $sizes[] = $size['label'];
  }
  $form['digett_block_random_image_gallery'] = array(
    '#type' => 'select', 
    '#title' => t('Image Gallery'), 
    '#description' => t('The image gallery to pull the images from.'),
    '#default_value' => digett_block_variable_get($block, 'random_image_gallery', '1'),
    '#options' => $galleries,
  );
  $form['digett_block_random_image_size'] = array(
    '#type' => 'select', 
    '#title' => t('Image Size'), 
    '#description' => t('The image size to display.'),
    '#default_value' => digett_block_variable_get($block, 'random_image_size', 'thumbnail'),
    '#options' => drupal_map_assoc($sizes),
  );
  $form['digett_block_random_image_captions'] = array(
    '#type' => 'radios',
    '#title' => t('Show Captions'),
    '#description' => t('Should the caption (title) be shown'),
    '#default_value' => digett_block_variable_get($block, 'random_image_captions', '0'),
    '#options' => array('0'=>t('No'),'1'=>t('Yes')),
  );
  return $form;
}

function _digett_block_random_image_view($block=array()){
  $tid = digett_block_variable_get($block,'random_image_gallery', '1');
  $size = digett_block_variable_get($block,'random_image_size', 'thumbnail');
  $images = image_get_random($count = 1, $tid);
  $return['content'] = image_display($images[0], $size);
  if(digett_block_variable_get($block, 'random_image_captions', '0') == '1'){
    $return['content'] .= '<span class="caption">'.$images[0]->title.'</span>';
  }
  return $return;  
}

