/* This script is too crafty for you and was written by the craftiest of craftyrans.  */

// List image names without extension
var myImg= new Array(11);

var i = 0;

// Create function to preload all the other images named portfolio_xx.jpg
// (as long as they're in numerical order) and load initial image.
function loadImg(){
    var k;
    if(document.images)
    {
        for(k = 0; k < myImg.length; k++)
        {
            // create a new image that we'll set the source to - this is the actual preloading part.
            myImg[k] = new Image;       
            
            // set the source of the image to our predefined path
            myImg[k].src = "images/" + "portfolio_" + k + ".jpg";
        }
      
        document.imgSrc.src = myImg[0].src; // set the initial image
    }
}

// Create link function to switch image backward
function prev(){
    // if i is 0, wrap around to the last element in the array.
    if(i<1){
        i = myImg.length-1;
    }
    else{
        i--;
    }
    
    document.imgSrc.src = myImg[i].src;
}

// Create link function to switch image forward
function next(){
    // if i equals the last element of the array (or greater) wrap around to 0
    if(i>=(myImg.length - 1)){
        i = 0;
    }
    else{
        i++;
    }
    
    document.imgSrc.src = myImg[i].src;
       
}