var title1 = "";
var commonPath1 = "";
var imagePath1 = "";
var section1 = "";
var position1 = 0;
var images1=[];
var runId1 = 0;

function runPages( )
{
	runId1 = setInterval("nextPage( )",1000);
}

function stopPages( )
{
	if ( runId1 != 0 ) {
		clearInterval( runId1 );
		runId1 = 0;
		}
}

function initialPage( )
{
	var i1 = 0;
	var s1 = section1.toLowerCase();

	if ( s1 != "" ) {
		for( i1=0; i1<images1.length; i1++)
			if ( (images1[i1].length>=4) && (images1[i1][4-1].toLowerCase() == s1) )
				break; 				
		position1 = (i1<images1.length) ? i1 : 0;
		}

	displayPage( );	
}

function firstPage( )
{
	position1 = 0;
	displayPage( );
}

function nextPage( )
{
	position1++;
	if ( position1 >= images1.length )
		position1 = 0;
	
	displayPage( );
}

function jumpForward( )
{
	var i1;
	for (i1=position1+1 ; i1<images1.length; i1++) {
		if ( i1 >= position1+10 )
			break;
		if ( (images1[i1].length>=4) && (images1[i1][4-1] != null) )
			break;
		} 				
	position1 = (i1<images1.length) ? i1 : 0;
	displayPage( );
}

function previousPage( )
{
	position1--;
	if ( position1 < 0 )
		position1 = images1.length-1;
	displayPage( );
}

function displayPage( )
{

	if ( ( position1 < 0 ) || ( position1 > (images1.length-1) ) )
		return;
	if ( position1 == (images1.length-1))
		stopPages( );
	if ( images1[position1].length >= 1 )
		centralimg.src=imagePath1 + images1[position1][0];
}	

function onImageLoad( ) 
{
	var ih;

	for ( ih = position1; ih >= 0; ih-- )
		if ( (images1[ih].length>=4) && (images1[ih][4-1].length > 0) )
			break; 				
	heading1.innerHTML= (ih >= 0) ? images1[ih][4-1] + "&nbsp;" : "";

	heading2.innerHTML= ( images1[position1].length >= 2 ) ? images1[position1][2-1] : "&nbsp;";
	centraltext.innerHTML= ( images1[position1].length >= 3 ) ? images1[position1][3-1] : "";
	pgno.innerHTML = 'Page: ' + (position1+1) + ' of ' + images1.length;
	showPgnoInStatus( );
	window.focus( );
	window.scrollTo(0,0);
}

function showPgnoInStatus( )
{
	window.status = 'Page: ' + (position1+1) + ' of ' + images1.length;
}

