function getImageArray($dir, $depth = 0, $max_depth = -1, $extension = array('jpg', 'gif', 'png'))
 {
     if ($max_depth >= 0 && $depth > $max_depth || $depth == 10) {
         return array();
     }
     //end if
     $images = array();
     $handle = @opendir($dir);
     while ($file = @readdir($handle)) {
         if ($file != '.' && $file != '..') {
             $file_name = $dir . $file;
             if (is_dir($file_name)) {
                 if ($file != '_vti_cnf' && $file != '.AppleDouble') {
                     $new_depth = $depth + 1;
                     $additional_images = PSUFiles::getImageArray($file_name . '/', $new_depth, $max_depth);
                     $images = array_merge($images, $additional_images);
                 }
                 //end if
             } elseif (substr($file, 0, 1) != '.') {
                 $path_info = pathinfo($dir . '/' . $file_name);
                 if (in_array($path_info['extension'], $extension)) {
                     $images[] = $file_name;
                 }
                 //end if
             }
             //end elseif
         }
         //end if
     }
     //end while
     @closedir($handle);
     return $images;
 }
 /**
  * selects a random file from a given directory
  */
 public function _random()
 {
     if ($this->type == 'image') {
         $files = PSUFiles::getImageArray($this->base_dir . $this->dir, 0, $this->depth);
     } else {
         $files = PSUFiles::getImageArray($this->base_dir . $this->dir, 0, $this->depth, array('txt', 'html'));
     }
     //end if
     $this->set(PSUFiles::chooseRandomElement($files));
 }