
//
// Filename: 	PhotoViewer.js
// Description: JavaScript to support the photo viewer app
// Author:	Lizi Attwood (mail@beeski.com)
//

var NonHighlight = 0;
var Highlight = 0;
var Inactive = 0;

var CurrentProject = 0;
var CurrentImage = 0;
var Projects = [];
var Images = [];

function SetColours( nonhighlight, highlight, inactive )
{
	NonHighlight 	= nonhighlight;
	Highlight 	= highlight;
	Inactive	= inactive;
}

function SetCurrentProject( projectIdx )
{
	CurrentProject 	= projectIdx;
}

function RegisterProject( projectIdx, name )
{
	Projects[projectIdx] 	= name;
	Images[projectIdx] 	= [];
}

function RegisterImage( projectIdx, imageIdx, src, text )
{
	Images[projectIdx][imageIdx] 	= [];
	Images[projectIdx][imageIdx][0] = src;
	Images[projectIdx][imageIdx][1] = text;
}

function SwapMainImage( projectIdx, imageIdx )
{
	CurrentProject 	= projectIdx;
	CurrentImage 	= imageIdx;
	MAINIMAGE.src 	= Images[CurrentProject][imageIdx][0];
	document.getElementById('MAINTEXT').innerHTML = Images[CurrentProject][imageIdx][1];
	
	for( var count = 0; count < 20; count++ )
	{
		if( count == imageIdx )
		{
			BorderColour( ('IMG' + count), Highlight );	
		}
		else if( Images[CurrentProject] && Images[CurrentProject][count] )
		{
			BorderColour( ('IMG' + count), NonHighlight );	
		}
		else
		{
			BorderColour( ('IMG' + count), Inactive );	
		}
	}
	
	return(false);
}

function PreviousImage()
{
	if( HasPreviousImage() )
	{
		CurrentImage = CurrentImage - 1;
		
		if( !HasPreviousImage() )
		{
			BorderColour( 'PREV', NonHighlight );	
		}
	}
	return SwapMainImage( CurrentProject, CurrentImage );
}

function NextImage()
{
	if( HasNextImage() )
	{
		CurrentImage = CurrentImage + 1;

		if( !HasNextImage() )
		{
			BorderColour( 'NEXT', NonHighlight );	
		}
	}
	return SwapMainImage( CurrentProject, CurrentImage );
}

function HasPreviousImage()
{
	return ( CurrentImage > 0 );
}

function HasNextImage()
{
	return ( Images[CurrentProject][CurrentImage+1] );
}

function MouseIn( idx )
{
	if( Images[CurrentProject] )
	{
		if( Images[CurrentProject][idx] )
		{
			BorderColour( 'IMG' + idx, Highlight );
		}
	}
}

function MouseOut( idx )
{
	if( Images[CurrentProject] )
	{
		if( Images[CurrentProject][idx] )
		{
			if( MAINIMAGE.src != Images[CurrentProject][idx][0] )
			{
				BorderColour( 'IMG' + idx, NonHighlight );
			}
		}
	}
}

function MouseInPrev()
{	
	if( HasPreviousImage() )
	{ 
		BorderColour( 'PREV', Highlight );
	}
}

function MouseOutPrev( idx )
{
	BorderColour( 'PREV', NonHighlight );
}

function MouseInNext()
{
	if( HasNextImage() )
	{
		BorderColour( 'NEXT', Highlight );
	}
}

function MouseOutNext()
{
	BorderColour( 'NEXT', NonHighlight );
}

function BorderColour( elementName, color )
{
	var element = document.getElementById( elementName );
	if( element )
	{
		element.style.borderColor = color;
	}
}

