var galleryPlay = false;
var galleryindex = 0;
var refresh = 8;
var timerID;

if (random)
{
changeGallery(Math.floor(Math.random()*galleryitems.length));
}
else
{
changeGallery(0);
}

if (autochange){autoChanger();}



function autoChanger()
{
timerID=setTimeout("galleryTimer()",refresh*1000);
galleryPlay = true;
}

function galleryChanger()
{
changeGallery(getNextGalleryIndex());
}


function changeGallery(n)
{
//turn off current item
galleryitems[galleryindex].className = "rg_gallery_off";

//turn off current item button
gallerybuttons[galleryindex].className = "rg_gallery_changer_item";


if(content)
{
gallerycontent[galleryindex].className = "rg_gallery_off";
}

galleryindex = n;

//turn on current item
galleryitems[galleryindex].className = "rg_gallery_on";

//turn on current item button
gallerybuttons[galleryindex].className = "rg_gallery_changer_item_on";

if(content)
{
gallerycontent[galleryindex].className = "rg_gallery_dtext";
}

}




function galleryTimer()
{
clearTimeout(timerID);
galleryChanger();
timerID=setTimeout("galleryTimer()",refresh*1000);
}


function getNextGalleryIndex()
{
gallerynext = galleryindex + 1;
if (gallerynext == galleryitems.length)
{
gallerynext = 0;
}
return gallerynext;
}

function gallerySelect(num)
{
if (autochange)
{galleryPlay = true;
toggleGallery();}
changeGallery(num);
}


function toggleGallery()
{
if (galleryPlay)
{
//turn off timer
clearTimeout(timerID);
//change icon
document.getElementById("gallerycontrol").innerHTML = ">";
galleryPlay = false;
}
else
{
//turn on timer
timerID=setTimeout("galleryTimer()",refresh*1000);
//change icon
document.getElementById("gallerycontrol").innerHTML = "||";
galleryPlay = true;
}
}

