// this script displays a youtube video randomly chosen from a list 
// with prev / next buttons wither side 

// VARIABLES

maxVideo=22;   // number of videos
currentVideo=0;

width='320';
height='220';

// PROGRAM

setUpArray();
setUpPage();

// FUNCTIONS

function setUpArray()
{
video=new Array();

video[0]  = ['a3IlRaKG7_4','http://www.inkpotamus.com/content/aint-read-nothing-yet-invention-of-cuneiform-writing-in-the-ancient-middle-east','Ain\'t Read Nothing Yet'];
video[1]  = ['Ov5uZmiS-Iw','http://www.inkpotamus.com/content/antidisestablishmentarianism-and-henry-the-eighth-poem','Antidisestablishmentarianism'];
video[2]  = ['kxznm85TQWY','http://www.inkpotamus.com/content/bad-medicine-made-from-mummies','Bad Medicine'];
video[3]  = ['8NztJuAMk0w','http://www.inkpotamus.com/content/let-me-live-an-old-mans-youth','Let Me Live An Old Man\'s Youth'];
video[4]  = ['7-sbczSPlqU','http://www.inkpotamus.com/content/nostradamus-and-his-remarkably-accurate-predictions','Nostradamus'];
video[5]  = ['H9aPqbtzBic','http://www.inkpotamus.com/content/no-such-thing-as-suction','No Such Thing As Suction'];
video[6]  = ['BRslImzKPkQ','http://www.inkpotamus.com/content/thurstaston-hill','Thurstaston Hill'];
video[7]  = ['A1KcTkHRaD0','http://www.inkpotamus.com/content/neanderthal-cannibalism-poem','Neanderthal'];
video[8]  = ['sxMllckUWaw','http://www.inkpotamus.com/content/regression-to-the-mean','Regression to the Mean'];
video[9]  = ['9c0K_6Y19nM','http://www.inkpotamus.com/content/scurvy-in-the-18th-century-english-navy','Scurvy'];
video[10]  = ['FFb_tSosPKs','http://www.inkpotamus.com/content/eureka-archimedes-and-the-displacement-of-water','Eureka!'];
video[11]  = ['drvddhuiOcI','http://www.inkpotamus.com/content/sir-francis-drake','Sir Francis Drake, For Goodness Sake'];
video[12] = ['_Nh1mDqWjTw','http://www.inkpotamus.com/content/gravity','Gravity'];
video[13] = ['E8ER5kh92hQ','http://www.inkpotamus.com/content/ancient-greek-the-decipherment-of-linear-b','Ancient Greek'];
video[14] = ['Plo9eZ5cA9Y','http://www.inkpotamus.com/content/father-bidmas-order-of-operations-in-an-equation','Father Bidmas'];
video[15] = ['PChDR_rw3fM','http://www.inkpotamus.com/content/when-i-nod-my-head','When I Nod My Head'];
video[16] = ['OEjur4w7BLU','http://www.inkpotamus.com/content/heavy-suitcase','Heavy Suitcase'];
video[17] = ['i6L1lFcph7o','http://www.inkpotamus.com/content/here-comes-santa-claus','Here Comes Santa Claus'];
video[18] = ['29e-oe59vdo','http://www.inkpotamus.com/content/dinosaurs','Dinosaurs!'];
video[19] = ['HM6zrIxh9As','http://www.inkpotamus.com/content/shy-bladder-bashful-bowel-movie','Shy Bladder, Bashful Bowel'];
video[20] = ['AH5ABLc-97E','http://www.inkpotamus.com/content/inside-the-wolf-three-little-pigs-poem','Inside the Wolf'];
video[21] = ['3eMdvxjaIBM','http://www.inkpotamus.com/content/idlejack-jack-and-the-beanstalk-poem','Idle Jack'];


text=new Array();

text[0]="<strong style=\"font-family:'Tempus Sans ITC' \" ><a href=\'";
text[1]="\' title='Click here to see more about this video' > ";
text[2]=" </a></strong><br />";

text[3]="<object id='myObject' width='" + width + "' height='" + height + "' ><param name='movie' value='http://www.youtube.com/v/";

text[4]="&hl=en_GB&fs=1&rel=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/";

text[5]="&hl=en_GB&fs=1&rel=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='" + width + "' height='" + height + "' ></embed></object>";

videoArray=new Array();

for (i=0; i<maxVideo; i++)
  {
  videoArray[i]  = text[0] + video[i][1] + text[1] + video[i][2] + text[2];
  videoArray[i] += text[3] + video[i][0] + text[4] + video[i][0] + text[5];
  }

currentVideo=Math.floor(Math.random() * maxVideo);
}

function next()
{
if (currentVideo >= (maxVideo - 1))
  {currentVideo=0;}
else
  {currentVideo=currentVideo+1;}

x=document.getElementById("myTable");
x.rows[0].cells[1].innerHTML=videoArray[currentVideo];
}

function prev()
{
if (currentVideo < 1)
  {currentVideo=maxVideo - 1;}
else
  {currentVideo=currentVideo - 1;}

x=document.getElementById("myTable");
x.rows[0].cells[1].innerHTML=videoArray[currentVideo];
}

function setUpPage()
{
document.write("<table style='border:none; border-width:0; border-collapse:collapse; border-spacing=0; margin:0; padding:0; ' >");

document.write("<thead>");
document.write("<tr style='vertical-align:middle' >");
document.write("<td style='font-family:\"Tempus Sans ITC\" '>");
document.write("Unusual topics from science, history and mathematics for the amusement of thoughtful kids and adults");
document.write("<p><strong style='font-family:\"Tempus Sans ITC\" '>Inkpotamus videos:</strong></p>");
document.write("</td>");
document.write("<td>");
document.write('<a href="http://www.kidzui.com/site_seals/df52174df99d33fe34d7813efd3643bb9fa5e33c;go" title="Click to get KidZui free for your family">');
document.write('<img src="http://www.kidzui.com/site_seals/df52174df99d33fe34d7813efd3643bb9fa5e33c;img?format=gif&tag=site_seal_91x59" alt="KidZui.com" title="Click to get KidZui free for your family" style=\'border:0; margin:0; padding:0;\' /></a></td>');
document.write("</tr>");
document.write("</thead>");

document.write("<tbody>");

document.write("<table id='myTable' ");
document.write("style='border:none; border-width:0; border-collapse:collapse; border-spacing=0; margin:0; padding:0; ' >");
document.write("<thead><tr>");

document.write("<td style='text-align:right; vertical-align:middle; ' >");
document.write("<input type='button' value='<<' onclick='prev()' title='<< Previous video' ");
document.write("style='font-family:\"Tempus Sans ITC\"; font-size:large; ' />");
document.write("</td>");

document.write("<td style='text-align:center; vertical-align:middle; width:25%; margin:0; padding:0; ");
document.write("border:none; border-width:0; border-collapse:collapse; border-spacing=0;  ' >");
document.write(videoArray[currentVideo]);
document.write("</td>");

document.write("<td style='text-align:left; vertical-align:middle; ' >");
document.write("<input type='button' value='>>' onclick='next()' title='Next video >>' ");
document.write("style='font-family:\"Tempus Sans ITC\"; font-size:large; ' />");
document.write("</td>");

document.write("</tr></thead>");
document.write("<tbody>");
document.write("</tbody>");
document.write("</table>");

document.write("</tbody>");
document.write("</table>");
}

// END 