function load_previous(pos)
{
	var hrph = document.getElementById('ahref_'+photos[pos]['id']);
	hrph.href = 'javascript:show_photo('+(pos)+');';
	if (pos>0)
	{
		var par_td = document.getElementById('out_photo_td');
		var pre_img = document.getElementById('picture_'+photos[pos-1]['id']);
		if (pre_img == null)
		{
			var newpic = document.createElement("img");
			newpic.id = 'picture_'+photos[pos-1]['id'];
			newpic.src = './pictures/'+photos_directory+'/'+photos[pos-1]['file'];
			newpic.title = photos[pos-1]['prompt'];
			newpic.style.display = 'none';
			newpic.onload = function ()
			{
				load_previous(pos-1);
			}
			par_td.appendChild(newpic);
		}
	}
}

function load_next(pos)
{
	var hrph = document.getElementById('ahref_'+photos[pos]['id']);
	hrph.href = 'javascript:show_photo('+(pos)+');';
	if (pos < photos.length-1)
	{
		var par_td = document.getElementById('out_photo_td');
		var pre_img = document.getElementById('picture_'+photos[pos+1]['id']);
		if (pre_img == null)
		{
			var newpic = document.createElement("img");
			newpic.id = 'picture_'+photos[pos+1]['id'];
			newpic.src = './pictures/'+photos_directory+'/'+photos[pos+1]['file'];
			newpic.title = photos[pos+1]['prompt'];
			newpic.style.display = 'none';
			newpic.onload = function ()
			{
				load_next(pos+1);
			}
			par_td.appendChild(newpic);
		}
	}
}

function show_previous()
{
	prev = current_photo-1;
	var phot = document.getElementById('picture_'+photos[prev]['id']);
	if (phot != null)
	{
		phot.style.display = '';
		var photc = document.getElementById('picture_'+photos[current_photo]['id']);
		photc.style.display = 'none';
		
		current_photo = prev;
		test_arrows();
	}
	else
	{
		window.location.href = 'preview.php?id='+photos[prev]['id'];
	}
}

function show_next()
{
	next = current_photo+1;
	var phot = document.getElementById('picture_'+photos[next]['id']);
	if (phot != null)
	{
		phot.style.display = '';
		var photc = document.getElementById('picture_'+photos[current_photo]['id']);
		photc.style.display = 'none';
		
		current_photo = next;
		test_arrows();
	}
	else
	{
		window.location.href = 'preview.php?id='+photos[next]['id'];
	}
}

function show_photo(pos)
{
	for (var i = 0; i<photos.length; i++)
	{
		var photc = document.getElementById('picture_'+photos[i]['id']);
		if (photc != null) photc.style.display = 'none';
	}
	var photc = document.getElementById('picture_'+photos[pos]['id']);
	photc.style.display = '';
	current_photo = pos;
	test_arrows();
}


function test_arrows()
{
	var arr_up = document.getElementById('name_up_td');
//	var arr_dw = document.getElementById('name_down_td');
	arr_up.innerHTML = '&nbsp;&nbsp;'+photos[current_photo]['name']+'&nbsp;&nbsp;';
//	arr_dw.innerHTML = '&nbsp;&nbsp;'+photos[current_photo]['name']+'&nbsp;&nbsp;';

	var oid = document.getElementById('out_info_div');
	
	if (oid!=null) oid.innerHTML = photos[current_photo]['prompt'];
	
	var arr_ul = document.getElementById('arrow_up_left');
	var arr_dl = document.getElementById('arrow_down_left');
	var arr_ur = document.getElementById('arrow_up_right');
	var arr_dr = document.getElementById('arrow_down_right');
	
	if (current_photo > 0)
	{
		if (arr_ul!=null) arr_ul.style.display = '';
		if (arr_dl!=null) arr_dl.style.display = '';
	}
	else
	{
		if (arr_ul!=null) arr_ul.style.display = 'none';
		if (arr_dl!=null) arr_dl.style.display = 'none';
	}
	
	if (current_photo < photos.length-1)
	{
		if (arr_ur!=null) arr_ur.style.display = '';
		if (arr_dr!=null) arr_dr.style.display = '';
	}
	else
	{
		if (arr_ur!=null) arr_ur.style.display = 'none';
		if (arr_dr!=null) arr_dr.style.display = 'none';
	}
}

