\r";
$return_menu_table .= "";
return $return_menu_table;
}
//this function returns an array of valid image filenames within the supplied
//relative directory
function return_image_filenames($dir_name)
{
$file_list = array();
$i = 0;
$ext = '';
if (is_dir($dir_name))
{
$handle = opendir($dir_name);
while ($dir_name != '' && $file = readdir($handle))
{
$ext = strrchr( $file, '.' );
if (!is_dir($dir_name."/".$file) && $ext == '.jpg' || $ext == '.gif')
{
$file_list[$i] = $file;
$i++;
}
}
closedir($handle);
}
sort($file_list);
return $file_list;
}
//this function returns all the start indexes (also previous)
function return_factors($total, $multiple)
{
$factors = array();
$curr_factor = 0;
array_push($factors, 0);
while ($curr_factor < $total)
{
$curr_factor += $multiple;
if ($curr_factor <= $total)
array_push($factors, $curr_factor);
}
return $factors;
}
function return_previous($start_index, $max_thumbs, $num_images, $gallery)
{
$start_indexes = return_factors ($num_images, $max_thumbs);
$prev_index = $start_indexes[array_search($start_index, $start_indexes)-1];
if (is_integer($prev_index))
$return_prev = "
Prev ";
return $return_prev;
}
function return_next($start_index, $max_thumbs, $num_images, $gallery)
{
$start_indexes = return_factors ($num_images, $max_thumbs);
$next_index = $start_indexes[array_search($start_index, $start_indexes)+1];
if (is_integer($next_index))
$return_next = "
Next";
return $return_next;
}
//at the moment this function is replica of return_thumbnails_table in structure
//but it returns a css defined list which takes care of thumb wrapping
function return_thumbnails($max_thumbs=20, $start_index=-1, $gallery='')
{
$image_files = return_image_filenames('gallery/'.$gallery);
if (sizeof($image_files) != 0 && $start_index >= 0 && is_numeric($start_index))
{
$thumbs_table = "
";
$thumbs_table .= "
\r";
$thumbs_table .= "
\r";
$thumbs_table .= "".return_previous($start_index, $max_thumbs, sizeof($image_files), $gallery)."";
$thumbs_table .= "".return_next($start_index, $max_thumbs, sizeof($image_files), $gallery)."";
$thumbs_table .= "
\r";
$index_counter = $start_index;
$thumb_counter = 0;
$thumbs_table .= "
\r";
while ($index_counter <= sizeof($image_files)-1)
{
$thumbs_table .= "-

\r";
$index_counter++;
$thumb_counter++;
if ($thumb_counter == $max_thumbs)
{
break;//out of while loop
}
}
$thumbs_table .= "
\r";
$thumbs_table .= "";
$thumbs_table .= "
\r";
}
else
{
$thumbs_table = return_sub_albums();
}
return $thumbs_table;
}
function return_thumbnails_table($columns=4, $max_thumbs=20, $start_index=-1, $gallery='')
{
$image_files = return_image_filenames('gallery/'.$gallery);
if (sizeof($image_files) != 0 && $start_index >= 0 && is_numeric($start_index))
{
$thumbs_table = "
\r";
$col_count = 1;
$index_counter = $start_index;
$thumb_counter = 0;
while ($index_counter < sizeof($image_files))
{
if ($col_count == 1)
$thumbs_table .= "\r\r";
$thumbs_table .= "
 | \r";
$col_count++;
$index_counter++;
$thumb_counter++;
if ($col_count == ($columns + 1))
{
$thumbs_table .= "
\r\r";
$col_count = 1;
}
if ($thumb_counter == $max_thumbs)
{
break;//out of while loop
}
}
if ($col_count <= $columns && $col_count > 1)
$thumbs_table .= "\r\r";
$thumbs_table .= "
\r";
echo return_previous($start_index, $max_thumbs, sizeof($image_files), $gallery);
echo return_next($start_index, $max_thumbs, sizeof($image_files), $gallery);
}
else
{
$thumbs_table = return_sub_albums();
}
return $thumbs_table;
}
//this function returns the "previous" link for the enlarged picture slide
function return_prev_link($index='-1', $gallery)
{
if ($index < 0 || !is_numeric($index))
{
$return_prev_link = "";//nothing
}
else
{
$return_prev_link = "
prev";
}
return $return_prev_link;
}
//this function returns the "next" link for the enlarged picture slide
function return_next_link($index='', $gallery, $max_index)
{
if (!is_numeric($index) || $index == $max_index)
{
$return_next_link = "";//nothing
}
else
{
$return_next_link = "
next";
}
return $return_next_link;
}
//this function returns the enlarged version of the selected thumbnail with appropriate prev/next links
function return_enlarge_picture($index = '', $gallery='')
{
$image_files = return_image_filenames('gallery/'.$gallery);
if (sizeof($image_files) != 0 && $index <= sizeof($image_files) && $gallery != '' && is_numeric($index) && $index >= 0)
{
$return_enlarge_table = "
\r";
$return_enlarge_table .= "\r";
$return_enlarge_table .= " | ";
$return_enlarge_table .= "";
$return_enlarge_table .= " 
| ";
$return_enlarge_table .= " | ";
$return_enlarge_table .= "
";
$return_enlarge_table .= "";
$return_enlarge_table .= "".return_prev_link($index-1, $gallery)." | ";
$return_enlarge_table .= " | ";
$return_enlarge_table .= "".return_next_link($index+1, $gallery, sizeof($image_files))." | ";
$return_enlarge_table .= "";
$return_enlarge_table .= "
";
$return_enlarge_table .= "
";
}
else
{
$return_enlarge_table = return_sub_albums();
}
return $return_enlarge_table;
}
?>