//the complete mashed contents in alphabetical order 


function mash()
{
    var snippets = [];
    var minLength = 0;
    var form = document.getElementById('front_page'); // Get the form with all of our checkboxes.
    for (var i = 0; i < form.elements.length; i++)
    {
        var e = form.elements[i];
        if (e.checked) // Is this checkbox checked?
        {
            var c = contents[e.value];
            c.chop(); // CHOP!!!

            // Concatenate the array c.chopped with the array of snippets
            // we're building.
            snippets = snippets.concat(c.chopped);
            if (c.chopped.length < minLength || minLength == 0)
            {
                // If this is the shortest (or minLength is still 0, meaning this is the first one we've seen), save the length;
                minLength = c.chopped.length;
            }
        }
    }

    var mashed = "";

    // Limit to length of shortest source.
    for (i = 0; i < minLength; i++)
    {
        // Yank a random element out of the array.
        var s = snippets.splice( // removes an element, and returns it
            Math.floor( // use floor to round down to an integer
                Math.random() * (snippets.length + 1)) // random gives a number between 0 and 1. Multiply by snippets.length + 1 to get a number between 0 and the number of snippets remaining. I think.
            , 1); // just remove one element
            if ((s !="!") && (s != "?") && (s !=".") && (s !="\\n") && (s != "<br/>") && (s !="\'")){
        mashed += "<br>" + s; // Include a BR to put each snippet on a new line.
          }
    }

    // Finally, stuff the "mash" text onto the page.
    document.getElementById("mash").innerHTML = mashed;
}

document.write("<form id='front_page'>");
for (var i = 0; i < contents.length; i++) {
 while (contents[i].mashable==false && i < (contents.length-1)) {
   i++;
   }
  document.write("<input id='checkboxes' type='checkbox' value='" + i + "'>" + contents[i].title+ " by " + contents[i].author + "</input>"+ " &nbsp;&nbsp;&nbsp;<br/>");
}
document.write("<input type='button' onClick='mash();' value='Mash' >");
document.write("</form>");
document.write("<h1>Mashup:</h1><p id='mash'></p>");

