// Usage: <IMG alt='' src='/directory/image.gif' align=absMiddle border=0 onMouseOver=RollOver(this) onMouseOut=RollOut(this) onLoad=RollInit(this,'/directory/image_rollover.gif','1234','##Web Page ID##')>

function RollInit( imageObject, imageSrc, pageID, currentPageID )
{
	if( imageObject==null || imageSrc==null ) return;

	// If image does not have a id, generate one
	if( imageObject.id == '' )
	{
		if( document.idCounter==null ) document.idCounter = 0;
		document.idCounter++;
		imageObject.id = "RollOver_" + document.idCounter;
	}

	// Check we haven't already put this image into the array
	if( document.preloadArray==null ) document.preloadArray = new Array();
	if( document.preloadArray[imageObject.id]==null )
	{
		// Add image rollover to array
		document.preloadArray[imageObject.id] = new Array();
		
		// Check if this rollover should be sticky
		if( pageID!=null && currentPageID!=null && pageID==currentPageID ) imageObject.src = imageSrc;
		
		document.preloadArray[imageObject.id][1] = new Image();
		document.preloadArray[imageObject.id][1].src = imageObject.src;
		document.preloadArray[imageObject.id][2] = new Image();
		document.preloadArray[imageObject.id][2].src = imageSrc;
	}

}

function RollOver( imageObject )
{
	if( imageObject==null ) return;

	// Check image exists in the array
	if( document.preloadArray!=null && document.preloadArray[imageObject.id] )
	{
		// Check image isn't sticky
		if( document.preloadArray[imageObject.id][1].src != document.preloadArray[imageObject.id][2].src )
		{
			// Check image is loaded
			if( document.preloadArray[imageObject.id][2].complete )
			{
				// Swap image
				imageObject.src = document.preloadArray[imageObject.id][2].src;
			}
		}
	}
}

function RollOut( imageObject )
{
	if( imageObject==null ) return;

	if( document.preloadArray!=null && document.preloadArray[imageObject.id] )
	{
		// Check image isn't sticky
		if( document.preloadArray[imageObject.id][1].src != document.preloadArray[imageObject.id][2].src )
		{
			imageObject.src = document.preloadArray[imageObject.id][1].src;
		}
	}
}
