
// Array to hold all the images
var g_Images = new Array()

// Retrieve an image that has already
//   been registered
function GetImage( ObjectId )
{
	return( g_Images[ ObjectId ] );
}

// Retrieve the array of images
function GetImageArray()
{
	return( g_Images );
}

// Load a non cached image
function LoadImage( Image, sSrc, iHeight, iWidth )
{
	Image = document.getElementById(Image);
	// If there was no source return
	if( !sSrc || !Image )
		return( "" );
		
	// Cache the image if the image hasn't
	//   been cached
	if( !g_Images[ sSrc ] )
	{
		g_Images[ sSrc ] = document.createElement("img");
		g_Images[ sSrc ].src = sSrc;
	}
		
	// If there is a height specified
	//   set the image's height
	if( iHeight )
	{
		g_Images[ sSrc ].height = iHeight;
		Image.height = iHeight;
	}
	
	// If there is a width specified
	//   set the image's width
	if( iWidth )
	{
		g_Images[ sSrc ].width = iWidth;
		Image.width = iWidth;
	}
		 
	// Update the image tag
	Image.src = g_Images[ sSrc ].src;
		
	return( sSrc );
}

// Register an image into the array
function RegisterImage( ObjectId, sSrc, iHeight, iWidth )
{
	// Create an image in the array if
	//   there isn't one already
	if( !g_Images[ ObjectId ] )
		g_Images[ ObjectId ] = document.createElement("img");
	
	// If there is a height specified
	//   set the image's height
	if( iHeight )
		g_Images[ ObjectId ].height = iHeight;
		
	// If there is a width specified
	//   set the image's width
	if( iWidth )
		g_Images[ ObjectId ].width = iWidth;
		
	// If there is a source specified
	//   set the image's source
	if( sSrc )
		g_Images[ ObjectId ].src = sSrc;
}

// Update an image tag's source with the
//   source of the specified image object
function UpdateImage( Image, ObjectId, iWidth, iHeight )
{
	Image = document.getElementById(Image);
	// If there is a height specified
	//   set the image's height
	if( !Image )
		return;
		
	if( iHeight )
	{
		g_Images[ ObjectId ].height = iHeight;
		Image.height = iHeight;
	}
		
	// If there is a width specified
	//   set the image's width
	if( iWidth )
	{
		g_Images[ ObjectId ].width = iWidth;
		Image.width = iWidth;
	}
		
	// If the image object and the image
	//   tag exists then update the sources
	if( g_Images[ ObjectId ] && Image )
		Image.src = g_Images[ ObjectId ].src;
}



// Update an element's visibilty
function UpdateVisibility(layer, state)
{
	document.getElementById( layer ).style.visibility = state;
}


// Launch new window, centered on screen
function CenteredWindow( url, name, height, width )
{
  var windowHeightCenter = Math.round(( screen.height / 2 ) - ( height / 2 ));
  var windowWidthCenter = Math.round(( screen.width / 2 ) - ( width / 2 ));
  
  window.open( url, name, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=auto,resizable=0,top=' + windowHeightCenter + ',left=' + windowWidthCenter );
}


// Centers an element in the window
function CenterElement( ID, iElementHeight, iElementWidth )
{
	if (self.innerHeight)
	{
		var iWindowHeight = self.innerHeight;
		var iWindowWidth = document.body.clientWidth;
	}
	else 
	{
		var iWindowHeight = document.body.clientHeight;
		var iWindowWidth = document.body.clientWidth;
	}
	var elementLayer = document.getElementById( ID );
	elementLayer.style.left = ( ( iWindowWidth - iElementWidth ) / 2 ) + "px";
	elementLayer.style.top = ( ( iWindowHeight - iElementHeight ) / 2  ) + "px";
}



