Jquery Drag with PHP loop

Jquery Drag with PHP loop

I created a PHP directory that loads all images in the folder the file is placed in and i used it with the drag UI,

Drag

There is only one issue, it dosn't change Z-Index. does anyone know how i could change that? so when you click on the image it will bring forward

here is the source

<script type="text/javascript">
$(function() {
<?
$path = dirname($_SERVER['SCRIPT_FILENAME']);
$dir_handle = @opendir($path);
while ($file = readdir($dir_handle))
{
   if($file!="." && $file!="..") {
      if(strpos($file, ".png")!==false or strpos($file, ".gif")!==false or strpos($file, ".jpeg")!==false or strpos($file, ".jpg")!==false) {
         
         $trans = array(".png" => "", ".gif" => "", "~" => "");
         echo strtr('$("#'.$file.'").draggable();', $trans);
      }
}
}
closedir($dir_handle);
?>
});
</script>


<body>   
<?
$path = dirname($_SERVER['SCRIPT_FILENAME']);
$dir_handle = @opendir($path);
while ($file = readdir($dir_handle))
{
   if($file!="." && $file!="..") {
      if(strpos($file, ".png")!==false or strpos($file, ".gif")!==false or strpos($file, ".jpeg")!==false or strpos($file, ".jpg")!==false) {
         $trans = array(".png" => "", ".gif" => "", "~" => "");
         $filen = strtr($file, $trans);
         echo('<span id="'.$filen.'";><img src="'.$file.'"></span>');
      }
}
}
closedir($dir_handle);
?>
</body>