currentIndex = new Array();
nbPictures = new Array();
picture_id = "current_picture_";
next_button_id = "next_button_";
previous_button_id = "previous_button_";

//nbPictures = aImg.length;

for (var i=0; i < aImg.length; i++)
{
    currentIndex[i] = 0;
    nbPictures[i] = aImg[i].length;
}

function next_picture(id)
{
    if ((picture = document.getElementById(picture_id + id)) != null)
    { 
        if (currentIndex[id] +1 < nbPictures[id])
        {    
            currentIndex[id]++;
            picture.src = aImg[id][currentIndex[id]];
            
            if (currentIndex[id] > 0)
            {
                enable_button(previous_button_id + id);
            }
            
            if (currentIndex[id] + 1 >= nbPictures[id])
            {
                disable_button(next_button_id + id);
            }
        }
        /*else
        {
            //alert("disabled");
            disable_button(next_button_id);
        }*/
    }
}

function previous_picture(id)
{
    if ((picture = document.getElementById(picture_id + id)) != null)
    { 
        if (currentIndex[id] -1 >= 0)
        {    
            currentIndex[id]--;
            picture.src = aImg[id][currentIndex[id]];
            
            
            if (currentIndex[id] >= 0)
            {
                enable_button(next_button_id + id);
            }
            
            if (currentIndex[id] - 1 < 0)
            {
                disable_button(previous_button_id + id);
            }
            
        }
    }
}

function disable_button(id)
{
    if ((button = document.getElementById(id)) != null)
    {
        if (button.nodeName == "INPUT")
        {
            button.disabled = "disabled";
        }
        else if (button.nodeName == "IMG")
        {
            button.style.display = "none";
        }
        //alert(button.nodeName);
    }
}

function enable_button(id)
{
    if ((button = document.getElementById(id)) != null)
    {
        if (button.nodeName == "INPUT")
        {
            button.disabled = '';
        }
        else if (button.nodeName == "IMG")
        {
            button.style.display = '';
        }
    }
}
