
pics = new Array();
index = new Array();
cindex = -1;

root = "";

/*function addPic(p)
{
	pics[pics.length] = p;
}*/

function start_index_table()
{
	index = new Array();
	cindex = -1;
}

function new_row(name)
{
	cindex++;
	index[cindex] = new Array();
	index[cindex][0] = name;
}

function add_picture(pic)
{
	index[cindex][index[cindex].length] = pic;
}

function init_show(div, album)
{
	k = -1;
	
	for (i=0;i<index.length;i++)
	{
		if (index[i][0]==album) k = i;
	}

	if (k==-1)
	{
		document.getElementById(div).innerHTML = "Could not locate album folder: "+album;
		return 0;
	}
	
	document.getElementById(div).innerHTML = "<table align='center' border='0' cellpadding='0' cellspacing='0'><tr><td width='580' height='435' align='center'><img id='current_pic_"+album+"' height='400' src=''<img style='display:none' id='preload_pic_"+album+"' height='400' src=''></td></tr></table>";
	
	pics[album] = new Array();
	
	for (i=1;i<index[k].length;i++)
		pics[album][pics[album].length] = index[k][i];
		
	start_show(album);
}

function set_buffer(album)
{
	i = Math.floor(Math.random()*pics[album].length);
	document.getElementById("preload_pic_"+album).src = root+album+"/"+pics[album][i];
}

function tick(album)
{
	document.getElementById("current_pic_"+album).src = document.getElementById("preload_pic_"+album).src;
	set_buffer(album);
	//alert(document.getElementById("current_pic_"+album).src);
	setTimeout("tick('"+album+"')", 3000);
}

function start_show(album)
{
	set_buffer(album);
	setTimeout("tick('"+album+"')", 500);
}

