/*
gallery viewer, w3c compliant

*/

//-----------------------------------------------------
function FillTable()
{
	SetCaption(0,now_showing);
	SetCaption(1,now_showing+1);
	SetThumbnailImage(0,now_showing);	
	SetThumbnailImage(1,now_showing+1);
	return true;
}

//-----------------------------------------------------------

function ReplaceTextContent(object_name,text)
{
	var object,child;

	object=document.getElementById(object_name);				
	RemoveNodeContents(object);
	child=document.createTextNode(text);
	object.appendChild(child);
	return true;
}

//-----------------------------------------------------------			

function RemoveNodeContents(object)
{
	var children;
	var old_node;

	if (children=object.childNodes.length)
	{	
		for (var i=0;i<children;i++)
		{
			old_node=object.childNodes[i];
			object.removeChild(old_node);
		}
	}
	return true;
}

//-----------------------------------------------------------			

function SetThumbnailImage(frame,painting)
{
	var object=document.getElementById('frame'+frame);
	RemoveNodeContents(object);				
	if (painting>no_of_paintings) return true;
	var child=document.createElement('img');
	child.src="art/250x200max/"+prefix+painting+".jpg";
	child.style.display="block";
	child.style.padding="20px";
	child.style.backgroundColor="#eeeeee";
	object.appendChild(child);
	return true;
}
//-----------------------------------------------------------			
function OpenViewer(frame)
{
	var image_id=now_showing+frame;
	var location_string="viewer.html?"+prefix.substr(0,1)+image_id+"+"+no_of_paintings;
	r=window.open(location_string,'viewer','fullscreen=yes,status=yes,scrollbars=yes,resizable=yes','true');
	return true;
}

//-----------------------------------------------------------			

function SetCaption(frame,painting)
{
	if (painting-1>=no_of_paintings)
	{
	 	ReplaceTextContent('text0_'+frame,"");
	 	ReplaceTextContent('text1_'+frame,"");
	 	ReplaceTextContent('index_'+frame,"");
	}
	else
	{
		ReplaceTextContent('text0_'+frame,text_line1[painting-1]);
		ReplaceTextContent('text1_'+frame,text_line2[painting-1]);
		ReplaceTextContent('index_'+frame,"Painting "+eval(painting)+": ");
	}
	return true;				
}

//-----------------------------------------------------------

function previousRow()
{
	now_showing-=2;
	if (now_showing<1) now_showing=last_page;
	FillTable();
	return true;
}

//-----------------------------------------------------------

function nextRow()
{
	now_showing+=2;
	if (now_showing>no_of_paintings) now_showing=1;			
	FillTable();
	return true;
}