function Scroller(html){
    this.imgs = new Array();
    this.alts = new Array();
    this.numImgs = 0;
    this.current = 0;


    //Search for all of the alt tags in the string and add them to the alt array
    var re = new RegExp("alt=\"[\\w\\s\\d\-\.\/\\&\_\=;,]+\"", "img");
    var match;
    match = re.exec(html);
    while(match != null){
        var discription = match[0];                         //match is an Array, gets matched string from array
        var length = discription.length;
        this.alts.push(discription.substring(5, length - 1));    //Add the string to the alts array
        match = re.exec(html);
    }
    
    
    //Search for all of the src tags in the string and add them to the imgs array
    re = new RegExp("src=[\\w\\s\\d\-\.\/\\&\_\=;,]+", "img");
    match = re.exec(html);    
    while(match != null){
        this.numImgs++;
        var img = match[0];                         //match is an Array, gets matched string from array
        img = img.replace(/&amp;/gi, "&");
        length = img.length;
        this.imgs.push("phpThumb/phpThumb.php?src=" + img.substring(4));    //Add the string to the imgs array
        match = re.exec(html);
    }


    //Set the main image to the first image and fade in
    $("#mainImg").attr("src", this.imgs[this.current]);
    $("#mainImg").fadeIn(200);
    $("#discription").html(this.alts[this.current]);


    setNav(this);
    

}


function setNav(scroller){
    if(scroller.current > 0){
        $("#navLeft").html("<span onclick='prev();'>&lt; prev</span>");
    }else{
         $("#navLeft").html("");
    }
    if(scroller.current < scroller.numImgs - 1){
        $("#navRight").html("<span onclick='next();'>next &gt;</span>");
    }else{
         $("#navRight").html("");
    }
}

function next(){
     $("#mainImg").fadeOut(200, function(){
        $("#mainImg").attr("src", scroller.imgs[scroller.current + 1]);
        $("#discription").html(scroller.alts[scroller.current + 1]);
        scroller.current++;
        $("#mainImg").fadeIn(200);
        setNav(scroller);
     });
}

function prev(){
     $("#mainImg").fadeOut(200, function(){
        $("#mainImg").attr("src", scroller.imgs[scroller.current - 1]);
        $("#discription").html(scroller.alts[scroller.current - 1]);
        scroller.current--;
        $("#mainImg").fadeIn(200);
        setNav(scroller);
     });
}
