/* jqAlternate.js 
 * Requires JQuery library version 1.2.2 or higher

/* Replaces the SRC field of an element with CLASS="jqalternate"
 * with a new filename that has a random single digit number at
 * the end of it. Name your files starting at 0 and ending at 9.
 * e.g. image0.jpg
 *      image1.jpg
 *      image2.jpg
 *
 * In your code, the SRC attribute should include the last filename
 * in the series. For the above example, your code should look like:
 * <img src="image2.jpg">
 *
 * This script can be used on any element that contains
 * a SRC attribute (e.g. IMG, IFRAME, SCRIPT).
 */

/* set namespace */
var jqAlt = { max: 0 };
/* perform swap */
$(document).ready(function(){
        var mysrc = $('.jqalternate').attr("src");
        jqAlt.max = parseInt(mysrc.slice(-5,-4), 10)+1; //grab max number from filename and add 1
        if(isNaN(jqAlt.max)) {
           alert("jqAlternate.js Error: Image filename does not end in a single digit.");
        } 
        var randomnum = Math.floor(Math.random()*(jqAlt.max));
        // insert randomnum so that: randomnum>=0 and randomnum<jqAlt.max 
        mysrc = mysrc.slice(0,-5) + randomnum + mysrc.slice(-4);
        $('.jqalternate').attr("src", mysrc);
}); 
