function write_recordings (rIndex) {
	
  var myPdf = myRecordings[(rIndex * 3) + 2];
  if (myPdf == "no-pdf") {
    pdfLink = "<img class=\"controls\" src=\"images/spacer.gif\" height=\"16\" width=\"1\" border=\"0\" /><br />";
  }
  else {
    pdfLink = "Read &nbsp;<a href=\"pdf/" + myRecordings[(rIndex * 3) + 2] + "\" border=\"0\" target=\"_blank\" ><img class=\"controls\" src=\"images/pdf.png\" border=\"0\" alt=\"\" /></a>\n";
  }


  
  var myHtml = 
    "<div id=\"page_item\">\n" +
    "<b>" + myRecordings[rIndex * 3] + "</b><br/>\n" +

    //"Listen &nbsp;<a href=\"clips/" + myRecordings[(rIndex * 3) + 1] + "\" border=\"0\" ><img class=\"controls\" src=\"images/listen.png\" border=\"0\" alt=\"\" /></a><br/>\n" +

    "Listen &nbsp;<br/>" +
    pdfLink +

    "<object type=\"application/x-shockwave-flash\" data=\"player.swf\" id=\"audioplayer" + rIndex + "\" height=\"18\" width=\"180\" class=\"flash_controls\">\n" +
    "<param name=\"movie\" value=\"player.swf\">\n" +
    "<param name=\"FlashVars\" value=\"playerID=" + rIndex + "&amp;soundFile=clips/" + myRecordings[(rIndex * 3) + 1] + "\">\n" +
    "<param name=\"quality\" value=\"high\">\n" +
    "<param name=\"menu\" value=\"false\">\n" +
    "<param name=\"wmode\" value=\"transparent\">\n" +
    "</object><br />\n" +
    
    "</div>\n";
	
  return myHtml;
  
}

// *** update this variable below to change the recordings per page ***
var recordingsPerPage = 6;

function write_page (pIndex) {
	
	var startNo = pIndex * recordingsPerPage;
	var curIndex = startNo;
	var myHtml1 = "";
	var myHtml2 = "";
	
	while (curIndex < startNo + (recordingsPerPage / 2) && curIndex < myRecordings.length / 3) {
		myHtml1 = myHtml1 + write_recordings (curIndex);
		curIndex++;
	}
	document.getElementById("page_content1").innerHTML = myHtml1;
	
	while (curIndex < startNo + recordingsPerPage && curIndex < myRecordings.length / 3) {
		myHtml2 = myHtml2 + write_recordings (curIndex);
		curIndex++;
	}
	document.getElementById("page_content2").innerHTML = myHtml2;

	var pageNo = page + 1;
	var pageTotal = Math.ceil(myRecordings.length / (recordingsPerPage * 3));
	document.getElementById("page_no").innerHTML = "(Page " + pageNo + " of " + pageTotal + ")";
}

// create a random function
function randOrd() {
    return (Math.round(Math.random())-0.5);
}

function write_images () {
	
	// sort the array of images using the random function
	myRecImages.sort( randOrd );
	
	// update the images using the first 6 images from the random sorted array
	document.getElementById("mugshots_grey").innerHTML =
	"<img class=\"mugshot\" src=\"images_rec/" + myRecImages[0] + "\" border=\"0\" alt=\"\" />\n" +
	"<img class=\"mugshot\" src=\"images_rec/" + myRecImages[1] + "\" border=\"0\" alt=\"\" />\n" +
	"<img class=\"mugshot\" src=\"images_rec/" + myRecImages[2] + "\" border=\"0\" alt=\"\" />\n" +
	"<img class=\"mugshot\" src=\"images_rec/" + myRecImages[3] + "\" border=\"0\" alt=\"\" />\n" +
	"<img class=\"mugshot\" src=\"images_rec/" + myRecImages[4] + "\" border=\"0\" alt=\"\" />\n" +
	"<img class=\"mugshot\" src=\"images_rec/" + myRecImages[5] + "\" border=\"0\" alt=\"\" />\n";
	
}

function write_prev () {
	if (page > 0) {
	  write_images();
	  page--;
	  write_page(page);
	}
}

function write_next () {
	if ((page + 1) * recordingsPerPage < myRecordings.length / 3) {
	  write_images();
	  page++;
	  write_page(page);
	}
}
