/* 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 };
var logoAlt = { max: 0, count: 0};
/* perform swap */
$(document).ready(function(){
        //selector statement returns all obj of class .jqalternate-bg
        var mysrc = $('.jqalternate-bg').css("background-image" );

    if (mysrc) {
        var checkquotes = mysrc.indexOf('"');
        if (checkquotes != -1) {
            mysrc = mysrc.replace(/"/g, "");
        }
        var slicednum = mysrc.slice(-6,-5);
        jqAlt.max = parseInt(slicednum, 10)+1; //grab max number from filename and add 1
        //   alert("jqAlt: ending: <" + slicednum + ">, String:" + mysrc);
//        jqAlt.max = parseInt(mysrc.slice(-7,-6), 10)+1; //grab max number from filename and add 1
        if(isNaN(jqAlt.max)) {
           alert("jqAlt Error: Image filename does not end in a single digit: <" + slicednum + ">, String:" + mysrc);
        }
        var randomnum = Math.floor(Math.random()*(jqAlt.max));
        //insert randomnum so that: randomnum>=0 and randomnum<jqAlt.max
        mysrc = mysrc.slice(0,-6) + randomnum + mysrc.slice(-5);
         //  alert("jqAlt: mysrc: <" + mysrc + ">");

        //var pickeditem = closure +1
        $('.jqalternate-bg').css("background-image", mysrc);
    }
// LOGO swapper
/*
        var thesrc = $("div#TNLogo > a > img").attr("src");
        logoAlt.max = parseInt(thesrc.slice(-5,-4), 10); //grab max number from filename
        if(isNaN(logoAlt.max)) {
            alert("jqAlternate.js Error: Logo filename does not end in a single digit.");
        }
        //alert ( "logo max: "+ logoAlt.max);

        $("div#TNLogo > a > img").click(function(){
        //

        //var randomnum = Math.floor(Math.random()*(logoAlt.max));
        // insert randomnum so that: randomnum>=0 and randomnum<logoAlt.max
        //thesrc = thesrc.slice(0,-5) + randomnum + thesrc.slice(-4);

*/ /*
        if (logoAlt.count > logoAlt.max) {
            logoAlt.count = 0;
            thesrc = thesrc.slice(0,-5) + logoAlt.count + thesrc.slice(-4);
        }
        else {
            thesrc = thesrc.slice(0,-5) + logoAlt.count + thesrc.slice(-4);
            logoAlt.count = logoAlt.count + 1;
        }
*/ /*
        if (logoAlt.count > 0) {
            thesrc = thesrc.slice(0,-5) + logoAlt.count + thesrc.slice(-4);
            logoAlt.count = 0;
        } else {
            thesrc = thesrc.slice(0,-5) + logoAlt.count + thesrc.slice(-4);
            logoAlt.count = 1;
        }

        //alert ( "count: " +logoAlt.count+" string: "+ thesrc +", max: "+ logoAlt.max +" ");
        //alert ( logoAlt.count + ", thesrc: "+ thesrc);
//        alert(thesrc);
        $("div#TNLogo > a > img").attr("src", thesrc);
     });
     */
});

