/*
Create an ArticleTypeProductShowcase namespace.
*/
var ATPS = new Object();

/*
Initialise the image pager.
*/
ATPS.Initialise = function (indexControlId, imageCount)
{
	// Find the input control specifed and store a reference to it, we use it to store the index of
	// the image currently being viewed
	ATPS.indexControl = document.getElementById(indexControlId);
	
	// Store the number of images available for viewing and the number we can display at any one time
	ATPS.imageCount = imageCount;
}

/*
Get the index of the image currently being viewed.
*/
ATPS.GetCurrentIndex = function ()
{
	return parseInt(ATPS.indexControl.value);
}

/*
Set the index of the image currently being viewied.
*/
ATPS.SetCurrentIndex = function (index)
{
	ATPS.indexControl.value = index;
}

/*
Update the images so that only the current one is displayed.
*/
ATPS.UpdateImages = function()
{
	var current = ATPS.GetCurrentIndex();
	
	// Update each of the image, caption and spec sets
	for(var i = 0; i < ATPS.imageCount; i++)
	{
		// Try to locate the controls, some may not exist
		var hero = document.getElementById('hero' + i);
		var spec = document.getElementById('spec' + i);
		var link = document.getElementById('link' + i);
		
		if(i == current)
		{
			// Display the controls
			if(hero != undefined) hero.className = "";
			if(spec != undefined) spec.className = "spec";
			if(link != undefined) link.className = "link";
		}
		else
		{
			// Hide the controls
			if(hero != undefined) hero.className = "hidden";
			if(spec != undefined) spec.className = "spec hidden";
			if(link != undefined) link.className = "link hidden";
		}
	}
}

/*
Sets the currently displayed page to the given value.
*/
ATPS.SetPage = function (index)
{
	ATPS.SetCurrentIndex(index);
	
	ATPS.UpdateImages();
}

/*
Sets the currently displayed page to the previous one.
*/
ATPS.PreviousPage = function ()
{
	var current = ATPS.GetCurrentIndex();

	if(current > 0)
	{
		ATPS.SetCurrentIndex(current - 1);
	}
	
	ATPS.UpdateImages();
}

/*
Sets the currently displayed page to the next one.
*/
ATPS.NextPage = function ()
{
	var current = ATPS.GetCurrentIndex();

	if(current < (ATPS.imageCount - 1))
	{
		ATPS.SetCurrentIndex(current + 1);
	}
	
	ATPS.UpdateImages();
}


