<?php
  // CuteButtons.php - RJM Programming - June, 2014
  $ij = 0;
  $numbuts = 6;

  function fix($inis) {
     global $ij;
     if ($ij > 0) {
       $inis = $_GET['image' . $ij];
       $ij = $ij - 1;
     }
     $outis = $inis;
     if (file_exists(dirname(__FILE__) . "/" . $inis) && (str_replace(" ","",$inis) != $inis || str_replace("#","",$inis) != $inis)) {
       $outis = str_replace(" ","",str_replace("#","",$inis));
       if (!file_exists(dirname(__FILE__) . "/" . $outis)) {
         copy(dirname(__FILE__) . "/" . $inis, dirname(__FILE__) . "/" . $outis);
       }
     } else if (!file_exists(dirname(__FILE__) . "/" . $inis)) {
       if (str_replace("http","",$inis) == $inis) {
         $outis = "";
       }
     }
     return $outis;
  }
?>
<html>
<head>
<title>Cute Images - RJM Programming - June, 2014</title>
<script type='text/javascript'>
var ij = 0;
var next = 0;
var plus = -1;
var bmode = 0;
var numbuts = 6;
var bsmode = ["Ordered", "Random"];
var imgs = [];
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.24 PM #2.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.24 PM #3.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.24 PM #4.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.24 PM #5.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.24 PM.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.25 PM #2.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.25 PM #3.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.25 PM #4.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.25 PM #5.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.25 PM #6.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.25 PM #7.jpg"); ?>';
imgs[imgs.length] = '<?php echo fix("Photo on 2-01-14 at 12.25 PM.jpg"); ?>';
<?php 

if (isset($_GET['image1'])) {
  echo "\n imgs = []; \n";
  $iij = 1;
  while (isset($_GET['image' . $iij])) {
    echo "\n imgs[imgs.length] = '" . fix($_GET['image' . $iij]) . "'; \n";
    $iij = $iij + 1;
  }
  $iij = $iij - 1;
  if ($iij < 6) {
    echo "\n numbuts = " . $iij . "; \n";
    $numbuts = $iij;
  }
  echo "\n ij = " . $iij . "; \n";
  $ij = $iij;
}
?>

function getimagePhoto() {
 var sofar = " ", jj, ii, cii;
 var iis;
 for (ii=1; ii<=6; ii++) {
  cii = 'i' + ii;
  iis = document.getElementById(cii);
  if (ii > numbuts) {
   iis.style.display = 'none';
  } else {
   iis.style.display = 'block';
   if (bmode == 0) {
    next = eval((next + 1) % imgs.length);
    iis.src = imgs[next];
   } else {
    jj = Math.floor((Math.random() * imgs.length) + 0);
    while (sofar.indexOf(" " + jj + " ") != -1) {
      jj = Math.floor((Math.random() * imgs.length) + 0);
    } 
    sofar = sofar + jj + " ";
    iis.src = imgs[jj];
   }
  }
 }
}

function nw(iis) {
  alert("Image is called " + iis);
}
</script>
</head>
<body style='background-color: yellow;' onload=' if (numbuts < 6) { for (var iii=eval(numbuts + 1); iii<=6; iii++) { document.getElementById("i" + iii).style.display = "none"; } }  setInterval(getimagePhoto, 5000); ' align='center'>
<h1 align='center'>Snapshots</h1>
<table align='center' border=4 cellpadding=5 cellspacing=5>
<tbody>
<tr><td>
<input id='i1' type='image' onclick='nw(this.src);' src="<?php echo fix('Photo on 2-01-14 at 12.24 PM #2.jpg'); ?>"></input>
</td><td>
<input id='i2' type='image' onclick='nw(this.src);' src="<?php echo fix('Photo on 2-01-14 at 12.24 PM #3.jpg'); ?>"></input>
</td><td>
<input id='i3' type='image' onclick='nw(this.src);' src="<?php echo fix('Photo on 2-01-14 at 12.24 PM #4.jpg'); ?>"></input>
</td><td>
<input id='i4' type='image' onclick='nw(this.src);' src="<?php echo fix('Photo on 2-01-14 at 12.24 PM #5.jpg'); ?>"></input>
</td><td>
<input id='i5' type='image' onclick='nw(this.src);' src="<?php echo fix('Photo on 2-01-14 at 12.24 PM.jpg'); ?>"></input>
</td><td>
<input id='i6' type='image' onclick='nw(this.src);' src="<?php echo fix('Photo on 2-01-14 at 12.25 PM #2.jpg'); ?>"></input>
</td><td>
&nbsp;<a href="#" id='toggle' title='Ordered' onclick=' bmode = eval(1 - bmode); this.innerHTML = bsmode[bmode]; '>Ordered</a>
</td><td>
&nbsp;<a href="#" id='numbuts' title='Number of buttons' onclick=' if (numbuts == <?php echo $numbuts; ?>) { plus = -1; } else if (numbuts == 2) { plus = 1; } numbuts = eval(plus + numbuts); this.innerHTML = numbuts; '><?php echo $numbuts; ?></a>
</td></tr>
</tbody>
</table>
</body>
</html>



