/* ### slide.js ###

	Author	- Eddie Corrigall
	Date	- /08/07/2008
	Licence - General Public Licence
*/

// User Definition

var speed = 1;
var delay = 10;
var unit = "px";

// System Definition

var index = 0;
var width = 0;
var height = 0;
var interval = 0;
var resource = 0;

onload = start;

function start()
{
	var slide = document.getElementById( "slide" );

	resource = slide.getElementsByTagName( "img" );

	height = resource[ 0 ].height;

	index = 0;

	while( index < resource.length )
	{
		resource[ index ].style.left = width + unit;
		resource[ index ].style.position = "absolute";
		resource[ index ].style.top = 0 + unit;

		width += resource[ index ].width;
		height = Math.min( height, resource[ index ].height );

		index++;
	}

	slide.style.height = height + unit;
	slide.style.overflow = "hidden";
	slide.style.position = "relative";
	slide.style.width = Math.min( width - resource[ 0 ].width, document.body.offsetWidth ) + unit;

	//alert( "width: " + width );
	//alert( "height: " + height );

	interval = setInterval( "process()", delay );
}

function process()
{
	index = 0;

	while( index < resource.length )
	{
		var position = parseInt( resource[ index ].style.left );

		if( position > width - resource[ index ].width )
		{
			resource[ index ].style.left = ( position - width + speed ) + unit;
		}
		else
		{
			resource[ index ].style.left = ( position + speed ) + unit;
		}

		index++;
	}
}

function stop()
{
	clearInterval( interval );
}