<?php
  // index.php
  // RJM Programming
  // September, 2019
  // Inhouse slideshow presenter supervisor

$wh="";
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
if ($isiPad === false) {
 $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPhone');
 if ($isiPad === false) {
 $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'Android');
 }
}
$isiPad=false;
if ($isiPad) {
 $wh=' style="width:600px;height:400px;" width="600" height="400" ';
}
   
$fcform='<form action="//www.rjmprogramming.com.au/PHP/form_creator.php" method="POST" target="i0" id="ffcformb" style="display:none;"><input style="display:none;" id=slideshowlist value="" name=slideshowlist></input><input style="display:none;" id=rp name=rp value=""></input><input id=fcformb type=submit style="display:none;"></input></form>';
$surlprefix=str_replace("//localhost/", "/",str_replace("index.php", "", str_replace("indexslideshow.php", "", str_replace("phpidea.php", "", "//" . $_SERVER['SERVER_NAME'] . explode("#", explode("?", $_SERVER['REQUEST_URI'])[0])[0]))));
$prepurlis=str_replace('//localhost','http://localhost','//' . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "/PHP/"); 
$purlis=str_replace("index.php","",'http://' . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "" . explode("#", explode("?", $_SERVER['REQUEST_URI'])[0])[0]); 
$ssurlprefix=".." . str_replace("index.php","",explode("#", explode("?", $_SERVER['REQUEST_URI'])[0])[0]);
$zerobit=' style="vertical-align:top;padding-top:200px;" ';
$zerobit='';
$tos="";

function pdfw($inw) {
  global $isiPad;
  if ($isiPad) { return '600'; }
  return '' . $inw;
}

function pdfh($inh) {
  global $isiPad;
  if ($isiPad) { return "400px;\" width=\"600px;\" height=\"400"; }
  return '' . $inh;
}

function oururlencode($instgis) {
  global $tos, $fcform;
  if (strpos($instgis, "&") === false) {
    return urlencode($instgis);
  } else {
    $rvas=explode("&", $instgis);
    $rva=urlencode($rvas[0]);
    $fcform=str_replace(' value="" ', ' value="' . $rvas[0] . '" ', $fcform);
    for ($ir=1; $ir<sizeof($rvas); $ir++) {
      $rve=explode("=", $rvas[$ir]);
      $rva.="&" . $rve[0] . "=" . urlencode(substr($rvas[$ir],(strlen($rve[0]) + 1)));
      $fcform=str_replace(' value="">', ' value="' . substr($rvas[$ir],(strlen($rve[0]) + 1)) . '">', $fcform);
    }
    return $rva;
  }
}

function andmore($oneis, $twois) {
     $couldbe=$oneis . $twois;
     $suffix="&rp=" . $oneis;
     $oneis="";
     $andthenmaybe="";
     $items = glob("*[-_][0-9]*of.[jJgGpP][pPiInN]*");
     natsort($items);
     //foreach (glob("*[-_][0-9]*of.[jJgGpP][pPiInN]*") as $ifil) {
     foreach ($items as $key => $val) {
      if ($andthenmaybe == "") {
        $andthenmaybe=$oneis . $val;
      } else if (strpos($andthenmaybe, $oneis . $val) === false) {
        $andthenmaybe.=',' . $oneis . $val;
      }
     }
     $items = glob("*[-_][0-9]*.[jJgGpP][pPiInN]*");
     natsort($items);
     foreach ($items as $key => $val) {
      if ($andthenmaybe == "") {
        $andthenmaybe=$oneis . $val;
      } else if (strpos($andthenmaybe, $oneis . $val) === false) {
        $andthenmaybe.=',' . $oneis . $val;
      }
     }
     if ($andthenmaybe == "") {
       return $couldbe;
     } else {
       return $andthenmaybe . $suffix;
     }
}

function ourrealpath($inid) {
  global $surlprefix, $purlis, $ssurlprefix;
  //echo $purlis;
  //exit;
  if (realpath($inid) != $inid && realpath($inid) != '') {
  if (strpos($inid, $delim) === false && strpos($inid, "/") === false) {
    $surlprefix="";
  } 
    return realpath($inid);
  }
  $delim=substr("\\" . "\\",0,1);
  if (PHP_OS=='WINNT' || PHP_OS=='WIN32' || PHP_OS=='Windows') {
  if (strpos($inid, $delim) === false && strpos($inid, "/") === false) {
    $surlprefix="";
    return dirname(__FILE__) . $delim . $inid;
  }
    $bits=explode($delim, $inid);
    $lbit=$bits[-1 + sizeof($bits)];
    if (strpos($lbit, ".") !== false) {
      if (file_exists(str_replace($delim . $lbit, $delim, $inid))) {
         if (realpath(str_replace($delim . $lbit, $delim, $inid)) != str_replace($delim . $lbit, $delim, $inid) && realpath(str_replace($delim . $lbit, $delim, $inid)) != '') {
           return realpath(str_replace($delim . $lbit, "", $inid)) . $delim . $lbit;
         }
      }
    }
  } else {
  if (strpos($inid, "/") === false) {
    $surlprefix="";
    return dirname(__FILE__) . "/" . $inid;
  }
    $bits=explode("/", $inid);
    $lbit=$bits[-1 + sizeof($bits)];
    if (strpos($lbit, ".") !== false) {
      if (file_exists(str_replace("/" . $lbit, "/", $inid))) {
         if (realpath(str_replace("/" . $lbit, "/", $inid)) != str_replace("/" . $lbit, "/", $inid) && realpath(str_replace("/" . $lbit, "/", $inid)) != '') {
           return realpath(str_replace("/" . $lbit, "", $inid)) . "/" . $lbit;
         }
      }
    }
  }  return $inid;
} 

function startBackgroundProcess(
    $command,
    $stdin = null,
    $redirectStdout = null,
    $redirectStderr = null,
    $cwd = null,
    $env = null,
    $other_options = null
) {  // thanks to https://stackoverflow.com/questions/45953/php-execute-a-background-process
    global $wh;

    
    $trunning = false;  
    $proc = null;
    
    
    $descriptorspec = array(
        1 => is_string($redirectStdout) ? array('file', $redirectStdout, 'w') : array('pipe', 'w'),
        2 => is_string($redirectStderr) ? array('file', $redirectStderr, 'w') : array('pipe', 'w'),
    );
    if (is_string($stdin)) {
        $descriptorspec[0] = array('pipe', 'r');
    }
    //if ($iswatchdog) { file_put_contents("zz.5",""); }
    //if ($isthere) { 
    //if ($iswatchdog) { file_put_contents("zz.6",""); }
        $proc = proc_open($command, $descriptorspec, $pipes, $cwd, $env, $other_options); 
    //} 
    if (!is_resource($proc)) {
        //throw new \Exception("Failed to start background process by command: $command");
        $proc=null;
    } 
    if (is_string($stdin)) {
        fwrite($pipes[0], $stdin);
        fclose($pipes[0]);
    }
    if (!is_string($redirectStdout)) {
        fclose($pipes[1]);
    }
    if (!is_string($redirectStderr)) {
        fclose($pipes[2]);
    }
    
    return $proc;
}
  $sothers="";
  $tdid=''; //' id="tdfirst" ';
  $stitle=""; //"Please sign it";
  if (isset($_GET['title'])) { $stitle=str_replace("+"," ",urldecode($_GET['title'])); } 
  $scnt=0;
  $sscnt=1;
  $whsbits="";
  //$zerobit="";
  $slo=-1;
  $smodebit="";
  $spush="";
  if (isset($_GET['exif'])) {  // //www.rjmprogramming.com.au/PHP/read_exif_off_image_rotate.php?image=
  $surlprefix=str_replace("//www.rjmprogramming.com.au/", "../", $surlprefix);
  $smodetemplate="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td><div style=\"overflow:scroll !important; -webkit-overflow-scrolling:touch !important;\"><iframe" . $wh . " onclick=\"onck(this);\" id=\"i1\" src=\"//www.rjmprogramming.com.au/PHP/read_exif_off_image_rotate.php?image=http://localhost:8888/please_sign_2.jpg\" title=\"Please Sign It\"></iframe></div></td>'; \n";
  } else if (isset($_GET['pdf'])) {  // //www.rjmprogramming.com.au/PHP/read_exif_off_image_rotate.php?image=
  $surlprefix=str_replace("//www.rjmprogramming.com.au/", "../", $surlprefix);
  $smodetemplate="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td><div style=\"overflow:scroll !important; -webkit-overflow-scrolling:touch !important;\"><iframe" . $wh . " onclick=\"onck(this);\" id=\"i1\" src=\"//www.rjmprogramming.com.au/PHP/form_creator.php?slideshowlist=http://localhost:8888/please_sign_2.jpg\" title=\"Please Sign It\"></iframe></div></td>'; \n";
  } else {
  $smodetemplate="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td><img onclick=\"onck(this);\" id=\"i1\" src=\"http://localhost:8888/please_sign_2.jpg\" title=\"Please Sign It\" /></td>'; \n";
  }
  
  // Zip file coding
  $rmcmd="";
  $onlyzip="";
  $pattern1 = '/[-_][0-9]*of.[jJgGpP][pPiInN]/';
  $pattern2 = '/[-_][0-9]*.[jJgGpP][pPiInN]/';
  $matches1 = [];
  $matches2 = [];
  // End of zip file coding


  if (!file_exists("index.htm") && !file_exists("index.html")) {
     // Zip file coding
     foreach (glob("*[-_][0-9]*.[zZ][iI][pP]") as $ifil) {
       $onlyzip=$ifil;
     }
     foreach (glob("*[-_][0-9]*of.[zZ][iI][pP]") as $ifil) {
       $onlyzip=$ifil;
     }
     if ($onlyzip != "") {
       foreach (glob("*[-_][0-9]*of.[jJgGpP][pPiInN]*") as $ifil) {
         $onlyzip="";
       }
       foreach (glob("*[-_][0-9]*.[jJgGpP][pPiInN]*") as $ifil) {
         $onlyzip="";
       }
     }
     if ($onlyzip != "") {
      foreach (glob("*[-_][0-9]*.[zZ][iI][pP]") as $ifil) {
        $zip = zip_open($ifil);
        if ($zip) {
          while ($zip_entry = zip_read($zip)) {
           $ourfilename=zip_entry_name($zip_entry);
           preg_match($pattern1, $ourfilename, $matches1, PREG_OFFSET_CAPTURE);
           if (sizeof($matches1) == 0) {
            preg_match($pattern2, $ourfilename, $matches2, PREG_OFFSET_CAPTURE);
           }
           if (sizeof($matches1) > 0 || sizeof($matches2) > 0) {
           if (zip_entry_open($zip, $zip_entry)) {
            // some code
            $cont=zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
            file_put_contents(basename($ourfilename), $cont);
            if ($rmcmd == "") { $rmcmd=" sleep 3600; "; }
            $rmcmd.=" rm -f " . realpath(basename($ourfilename)) . "; ";
           }
           }
           $matches1 = [];
           $matches2 = [];
          }
          zip_close($zip);
        }
      }
      $matches1 = [];
      $matches2 = [];
      foreach (glob("*[-_][0-9]*of.[zZ][iI][pP]") as $ifil) {
        $zip = zip_open($ifil);
        if ($zip) {
          while ($zip_entry = zip_read($zip)) {
           $ourfilename=zip_entry_name($zip_entry);
           preg_match($pattern1, $ourfilename, $matches1, PREG_OFFSET_CAPTURE);
           if (sizeof($matches1) == 0) {
            preg_match($pattern2, $ourfilename, $matches2, PREG_OFFSET_CAPTURE);
           }
           if (sizeof($matches1) > 0 || sizeof($matches2) > 0) {
           if (zip_entry_open($zip, $zip_entry)) {
            // some code
            $cont=zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
            file_put_contents(basename($ourfilename), $cont);
            if ($rmcmd == "") { $rmcmd=" sleep 3600; "; }
            $rmcmd.=" rm -f " . realpath(basename($ourfilename)) . "; ";
           }
           }
           $matches1 = [];
           $matches2 = [];
          }
          zip_close($zip);
        }
      }
     }
     // End of zip file coding

     // Zip file coding
     if ($rmcmd != "") {
       $huhp = startBackgroundProcess($rmcmd);
       header("Location: " . $_SERVER['REQUEST_URI']);
       exit;
     }
     // End of zip file coding
     
     $items = glob("*[-_][0-9]*of.[jJgGpP][pPiInN]*");
     natsort($items);
     //foreach (glob("*[-_][0-9]*of.[jJgGpP][pPiInN]*") as $ifil) {
     foreach ($items as $key => $val) {
       $ifil=$val; //$items[$iio];
       $ibits=explode("-", $ifil);
       if (sizeof($ibits) <= 1) {
       $ibits=explode("_", $ifil);
       }
       if (sizeof($ibits) > 1) {
         $proposedstitle=str_replace("_", " ", $ibits[0]);
         if ($proposedstitle != $stitle) {
           if ($stitle == "") {
             $stitle=$proposedstitle;
           } else if (strpos($sothers, $proposedstitle) === false) {
             $spush.="\n firstones.push(" . $scnt . "); \n";
             $spush.="\n lastones.push(" . (-1 + $scnt) . "); \n";
             $sothers.="<br><a id='apre" . $sscnt . "' href='#s" . $scnt . "' title=\"Movie'ize Here vs Follow Red Right Arrows with Bottom Scrollbar\" onclick='prehavealook(this); havealook(-" . $scnt . ");'>" . $proposedstitle . "</a>";
             $sscnt++;
           }
         }
         if (isset($_GET['exif'])) {  // //www.rjmprogramming.com.au/PHP/read_exif_off_image_rotate.php?image=
         //echo ourrealpath($ifil);
         //exit;
         list($width, $height, $type, $attr) = getimagesize(ourrealpath($ifil));
         if (strpos($zerobit, ' style="') !== false) {
         $zerobit=str_replace(' style="', ' style="width:' . $width . 'px;height:' . $height . 'px;', $zerobit);
         } else {
         $zerobit=" style=\"vertical-align:top;width:" . $width . "px;height:" . $height . "px;\" ";
         }
         $smodebit.="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td style=\"width:" . $width . "px;height:" . $height . "px;\"><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td style=\"width:" . $width . "px;height:" . $height . "px;\"><iframe style=\"width:" . $width . "px;height:" . $height . "px;\" onclick=\"onck(this);\" id=\"i" . $scnt . "\" src=\"" . $prepurlis . "read_exif_off_image_rotate.php?image=" . urlencode($ssurlprefix . $ifil) . "\" title=\"" . $proposedstitle . "\"></iframe></td>'; \n";
         } else if (isset($_GET['pdf'])) {  // //www.rjmprogramming.com.au/PHP/read_exif_off_image_rotate.php?image=
         //echo ourrealpath($ifil);
         //exit;
         list($width, $height, $type, $attr) = getimagesize(ourrealpath($ifil));
         if (strpos($zerobit, ' style="') !== false) {
         $zerobit=str_replace(' style="', ' style="width:' . $width . 'px;height:' . $height . 'px;', $zerobit);
         } else {
         $zerobit=" style=\"width:" . $width . "px;height:" . $height . "px;\" ";
         }

         if (strpos($smodebit, "form_creator.php?slideshowlist=") === false) {
         $smodebit.="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td style=\"width:" . $width . "px;height:" . $height . "px;\"><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td style=\"width:" . $width . "px;height:" . $height . "px;\"><div style=\"overflow:scroll !important; -webkit-overflow-scrolling:touch !important;\"><iframe onload=\"setTimeout(fcb,2000);\" style=\"width:" . pdfw($width) . "px;height:" . pdfh($height) . "px;\" onclick=\"onck(this);\" id=\"i" . $scnt . "\" name=\"i" . $scnt . "\" src=\"" . $prepurlis . "form_creator.php?slideshowlist=" . oururlencode(andmore($ssurlprefix, $ifil)) . "\" title=\"" . $proposedstitle . "\"></iframe></div></td>'; \n";
         }
         } else {
         $smodebit.="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td><img onclick=\"onck(this);\" id=\"i" . $scnt . "\" src=\"" . $surlprefix . $ifil . "\" title=\"" . $proposedstitle . "\" /></td>'; \n";
         }
         $spush.="\n uarraydatauri.push('" . $surlprefix . $ifil . "'); \n";
         $scnt++;
       }
     }
     $items = glob("*[-_][0-9]*.[jJgGpP][pPiInN]*");
     natsort($items);
     foreach ($items as $key => $val) {
       $ifil=$val; //$items[$iio];
         //echo ourrealpath($ifil) . ' surlprefix=' . $surlprefix;
         //exit;
       if (strpos($spush, "'" . $surlprefix . $ifil . "'") === false) {
       $ibits=explode("-", $ifil);
       if (sizeof($ibits) <= 1) {
       $ibits=explode("_", $ifil);
       }
       if (sizeof($ibits) > 1) {
         $proposedstitle=str_replace("_", " ", $ibits[0]);
         if ($proposedstitle != $stitle) {
           if ($stitle == "") {
             $stitle=$proposedstitle;
           } else if (strpos($sothers, $proposedstitle) === false) {
             $spush.="\n firstones.push(" . $scnt . "); \n";
             $spush.="\n lastones.push(" . (-1 + $scnt) . "); \n";
             $sothers.="<br><a id='apre" . $sscnt . "' href='#s" . $scnt . "' title=\"Movie'ize Here vs Follow Red Right Arrows with Bottom Scrollbar\" onclick='prehavealook(this); havealook(-" . $scnt . ");'>" . $proposedstitle . "</a>";
             $sscnt++;
           }
         }
         if (isset($_GET['exif'])) {
         //echo $surlprefix;
         //exit;
         list($width, $height, $type, $attr) = getimagesize(ourrealpath($ifil));
         if (strpos($zerobit, ' style="') !== false) {
         $zerobit=str_replace(' style="', ' style="width:' . $width . 'px;height:' . $height . 'px;', $zerobit);
         } else {
         $zerobit=" style=\"width:" . $width . "px;height:" . $height . "px;\" ";
         }
         $smodebit.="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td" . $tdid . " style=\"width:" . $width . "px;height:" . $height . "px;\"><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td style=\"width:" . $width . "px;height:" . $height . "px;\"><iframe style=\"width:" . $width . "px;height:" . $height . "px;\" onclick=\"onck(this);\" id=\"i" . $scnt . "\" src=\"" . $prepurlis . "read_exif_off_image_rotate.php?image=" . urlencode($ssurlprefix . $ifil) . "\" title=\"" . $proposedstitle . "\"></iframe></td>'; \n";
         $tdid="";
         } else if (isset($_GET['pdf'])) {
         //echo $surlprefix;
         //exit;
         list($width, $height, $type, $attr) = getimagesize(ourrealpath($ifil));
         if (strpos($zerobit, ' style="') !== false) {
         $zerobit=str_replace(' style="', ' style="width:' . $width . 'px;height:' . $height . 'px;', $zerobit);
         } else {
         $zerobit=" style=\"width:" . $width . "px;height:" . $height . "px;\" ";
         }
         if (strpos($smodebit, "form_creator.php?slideshowlist=") === false) {
         $smodebit.="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td" . $tdid . " style=\"width:" . $width . "px;height:" . $height . "px;\"><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td style=\"width:" . $width . "px;height:" . $height . "px;\"><div style=\"overflow:scroll !important; -webkit-overflow-scrolling:touch !important;\"><iframe style=\"width:" . pdfw($width) . "px;height:" . pdfh($height) . "px;\" onclick=\"onck(this);\" id=\"i" . $scnt . "\" name=\"i" . $scnt . "\" src=\"" . $prepurlis . "form_creator.php?slideshowlist=" . oururlencode(andmore($ssurlprefix, $ifil)) . "\" title=\"" . $proposedstitle . "\"></iframe></div></td>'; \n";
         }
         $tdid="";
         } else {
         $smodebit.="\n  if (smode != '0') document.getElementById('row').innerHTML+='<td><span style=\"color:red;font-size:14px;\"><b>&gt;</b></span></td><td><img onclick=\"onck(this);\" id=\"i" . $scnt . "\" src=\"" . $surlprefix . $ifil . "\" title=\"" . $proposedstitle . "\" /></td>'; \n";
         }
         $spush.="\n uarraydatauri.push('" . $surlprefix . $ifil . "'); \n";
         $scnt++;
       }
       }
     }
     
     
  }
?>
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.4, minimum-scale=0.1, maximum-scale=8, user-scalable=yes">
<title><?php echo $stitle; ?> - via RJM Programming Slideshow Presentation</title> 
<?php 
if (1 == 1 && isset($_GET['exif'])) {  // //www.rjmprogramming.com.au/PHP/read_exif_off_image_rotate.php?image=
 echo "
<style>
 iframe { width: 100%; height: 100%; }
 td { vertical-align: top; }
</style>
";
}
?>
<script type="text/javascript"> 
 var fdone=false;
 var smode = location.search.split('smode=')[1] ? location.search.split('smode=')[1].split('&')[0] : '1'; 
 var ttl = ' ... click to have this slide stay longer'; 
 var nextone=0, inextone=1, jnextone=0, lastast=0; 
 var whs=[<?php echo $whsbits; ?>];
 var lastones=[], firstones=[0];
 var lastone=<?php echo (-1 + $scnt); ?>; 
 var haveseen=0; 
 var aminterested=0, dt=''; 
 var doit=1, uarraydatauri=[]; 
 
<?php
   echo $spush; 
   echo "\n lastones.push(" . (-1 + $scnt) . "); \n";
?>


 function onck(that) { 
   doit = 0; 
 } 

 function prehavealook(obackto) { 
   if (obackto.id == 'apre0' && document.URL.indexOf('exif=') != -1) {
    document.getElementById('s0').style.width=document.getElementById('i0').style.width;
    document.getElementById('s0').style.height=document.getElementById('i0').style.height;
   }
   lastast=eval(obackto.id.replace('apre',''));
   lastone=lastones[lastast];
 }
 
 function havealook(backto) { 
   if (smode == '0') { 
   if (eval(backto) <= 0) {  location.href=document.URL.replace('smode=0','smode=1'); }
   document.getElementById('i' + nextone).src=uarraydatauri[jnextone]; 
   document.title=dt + " Slide " + inextone + " of " + eval(lastone + 1); 
   if (dt == '') {  document.getElementById('myh1').innerHTML='Slideshow Data URI version below';  document.getElementById('som').innerHTML='Start of Movie'; dt=document.getElementById('i' + nextone).title; } else if (inextone == 1) { document.getElementById('som').innerHTML='Start of Movie';  } else { document.getElementById('som').innerHTML='';  }  
   inextone=eval(eval(inextone % eval(1 + lastone)) + 1); jnextone=eval(-1 + inextone); 
   } else { 
   var thissrc=''; 
   var prefix=''; 
   if (doit == 0) { 
   doit = 1; 
   } else { 
   if (aminterested != 0 || eval(backto) <= 0) { 
   var cit = document.getElementById('s0'); 
   if (nextone == lastone) { 
     thissrc = document.getElementById('i' + nextone).src; 
     cit.innerHTML = prefix + "<<?php if (isset($_GET['exif'])) { echo 'iframe' . str_replace('"',"'",$zerobit); } else { echo 'img'; } ?> onclick='onck(this);' id='j" + nextone + "' src='<?php if (isset($_GET['exif'])) { echo ''; } else { echo ''; } ?>" + <?php if (isset($_GET['exif'])) { echo 'thissrc'; } else { echo 'thissrc'; } ?> + "' title='" + document.getElementById('i' + nextone).title + ttl + "' <?php if (isset($_GET['exif'])) { echo '></iframe>'; } else { echo '/>'; } ?>"; 
     nextone = firstones[lastast]; //0; 
   } else { 
     thissrc = document.getElementById('i' + nextone).src; 
     if (eval(backto) > 0 && nextone == 0) { 
        prefix = 'Start of Movie: '; 
     } 
     cit.innerHTML = prefix + "<<?php if (isset($_GET['exif'])) { echo 'iframe' . str_replace('"',"'",$zerobit); } else { echo 'img'; } ?> onclick='onck(this);' id='j" + nextone + "' src='<?php if (isset($_GET['exif'])) { echo ''; } else { echo ''; } ?>" + <?php if (isset($_GET['exif'])) { echo 'thissrc'; } else { echo 'thissrc'; } ?> + "' title='" + document.getElementById('i' + nextone).title + ttl + "' <?php if (isset($_GET['exif'])) { echo '></iframe>'; } else { echo '/>'; } ?>"; 
     nextone = nextone + 1; 
     if (nextone > 1) haveseen = 1; 
   } 
   if (eval(backto) <= 0) { 
     nextone = Math.abs(backto); 
     aminterested = 1; 
   } 
   } 
   var nnext = eval(nextone + 0); 
   var llast = eval(lastone + 1); 
   if (nnext >= 1 && nnext <= llast) { 
     nnext = nnext; 
   } else if (prefix != '') { 
     nnext = 1;   
   } else if (aminterested != 0 && haveseen == 1) { 
     nnext = llast; 
   } else if (aminterested != 0) { 
     nnext = 1; 
   } else if (nnext == 0) { 
     nnext = 1; 
   } 
   document.title=document.getElementById('i' + nextone).title + " Slide " + nnext + " of " + llast; 
   } 
   } 
 } 
 function ol() { 
 <?php 
  echo $smodebit;
?>
 } 
 
 function changeto(tvis) {
   if (tvis.toLowerCase().indexOf('exif') == 0) {
    if (document.URL.indexOf('?') == -1) { 
     location.href=document.URL.split('#')[0] + '?exif=y';
    } else {
     location.href=document.URL.split('#')[0].replace(/pdf\=/g, 'pdTf=') + '&exif=y';
    }
   } else if (tvis.toLowerCase().indexOf('pdf') == 0) {
    if (document.URL.indexOf('?') == -1) { 
     location.href=document.URL.split('#')[0] + '?pdf=y';
    } else {
     location.href=document.URL.split('#')[0].replace(/exif\=/g, 'exTif=') + '&pdf=y';
    }
   } else {
    if (document.URL.indexOf('exif=') != -1 || document.URL.indexOf('pdf=') != -1) { 
     location.href=document.URL.split('#')[0].replace(/exif\=/g, 'exTif=').replace(/pdf\=/g, 'pdTf=');
    } else {
     location.href=document.URL.split('#')[0] + '&eHuhxif=y';
    }
   }
 }
 
 function fcb() {
 if (!fdone) {
 fdone=true;
 //nwpdf(document.getElementById('i0'));
 if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) { 
 document.getElementById('ffcformb').target='_blank';
 }  
 document.getElementById('fcformb').click();
 }
 }
 
 function blater() {
 var tdsare=document.getElementsByTagName('td');
 var rectg=tdsare[2].getBoundingClientRect(); //document.getElementById('i0').getBoundingClientRect();
 tdsare[2].style.borderRight='2px solid white';
 //alert("URL('" + document.getElementById('i1').src + "'); background-position: " + rectg.left + "px " + rectg.top + "px; background-repeat: no-repeat;");
 document.body.style.backgroundImage="URL('" + document.getElementById('i0').src + "')";
 var rl=eval('' + rectg.left);
 rl+=eval('' + rectg.width);
 rl+=10;
 //alert(rl + ';' + rectg.left + ',' + rectg.width + ' ... ' + eval(eval('' + rectg.left) + eval('' + rectg.width) + 10) + ' vs ' + screen.width);
 //document.body.style.backgroundPosition=" " + Math.floor(eval(eval('' + rectg.left) + eval('' + rectg.width) + 10)) + "px " + Math.floor(rectg.top) + "px";
 document.body.style.backgroundPosition=" " + rl + "px " + Math.floor(rectg.top) + "px";
 document.body.style.backgroundRepeat="no-repeat";
 document.body.style.backgroundClip="content-box";
 }
 
 function zoom_maybe() {
 if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {  
 if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {  
 document.getElementById('rfs').innerHTML='<style> html { zoom: .5;  body { max-width: 100%; max-height: 80vh; }  table { max-width: <?php if (strpos($_SERVER['QUERY_STRING'],'exif=') !== false) {  echo "100"; } else { echo "95";  }  ?>%; max-height: 80vh; margin: auto; overflow-x: hidden; }  </style>';
 } else {  
 document.getElementById('rfs').innerHTML='<style> html { body { max-width: 100% !important; max-height: 80vh !important; }  table { max-width: <?php if (strpos($_SERVER['QUERY_STRING'],'exif=') !== false) {  echo "100"; } else { echo "95";  }  ?>% !important; max-height: 80vh !important; margin: auto !important; overflow-x: hidden !important; }  </style>';
 }
 setTimeout(blater, 2000);
 }
 }
 
 function nwpdf(iithis) {
 if (('' + iithis.src).length > 0) {
 if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {   
 window.open(iithis.src,'_blank');
 }
 }
 }
 
 function mytw() {
 if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {    
    document.body.style.width='' + (window.orientation == 0 ? window.screen.width : window.screen.height) + 'px';
    document.getElementById('myt').style.width='100%'; //'' + (window.orientation == 0 ? window.screen.width : window.screen.height) + 'px';
    //document.getElementById('myt').style.overflow='hidden';
 }
 }
 
 window.setInterval(function(){havealook(1)},2000);  
 </script> 
 <style>
  td { vertical-align:top; }
  @media only screen and (max-width: 800px) {  
  body { max-width: 100%; max-height: 80vh; }  table { max-width: <?php if (strpos($_SERVER['QUERY_STRING'],'exif=') !== false) {  echo "100"; } else { echo "95";  }  ?>%; max-height: 80vh; margin: auto; overflow-x: hidden; } 
  }
</style>
 </head> 
 <body onload=" mytw(); zoom_maybe(); if (document.URL.indexOf('pdf=') != -1) { document.getElementById('selmode').value='PDF Slideshow'; if (document.getElementById('tdfirst')) { document.getElementById('s0').style.width=document.getElementById('tdfirst').style.width; document.getElementById('s0').style.height=document.getElementById('tdfirst').style.height; } }  if (document.URL.indexOf('exif=') != -1) { document.getElementById('selmode').value='Exif Slideshow'; if (document.getElementById('tdfirst')) { document.getElementById('s0').style.width=document.getElementById('tdfirst').style.width; document.getElementById('s0').style.height=document.getElementById('tdfirst').style.height; } } document.title=document.title + ' ' + lastone; ol(); "> 
 <h1 id=myh1><?php echo $stitle; ?> <select id=selmode onchange="changeto(this.value);"><option value="Slideshow">Slideshow</option><option value="Exif Slideshow">Exif Slideshow</option><option value="PDF Slideshow">PDF Slideshow</option></select> version below<h1><h2> ... optionally get content via web browser (Windows right click, Mac OS X two finger gesture) ... <span id=som></span></h2><br> 
 <table id=myt style='height:80vh;'> 
 <tr id=row> 
 <td<?php echo $zerobit; ?>><span id='s0'><a id='apre0' href='#' title="Movie'ize Here vs Follow Red Right Arrows with Bottom Scrollbar" onclick='prehavealook(this); havealook(0);' style='font-size:64px;'>&#10145;</a><?php echo $sothers; ?></span><span style="color:red;font-size:14px;"><b>&gt;</b></span></td><!--td><img onclick="onck(this);" id="i0" src="http://localhost:8888/please_sign_1.jpg" title="Please Sign It" /></td--> 
 </tr>
 </table><?php echo $fcform; ?>
<div id=rfs></div>
</body>
</html>
