function AddScriptToOnLoad(script)
{
	var func = '';
	var evt = window.onload;
	if( typeof(evt) == 'function' )
	{
		func = evt.toString();
		func = func.substring(func.indexOf('{') + 1, func.lastIndexOf('}'));
	}
	window.onload = new Function(func + script);
}
function PreloadImages()
{
	var d = document;
	if( d.images )
	{  
		if( !d.imgt ) d.imgt = new Array();
		for( var i=1; i <= TOP_COUNT; i++ ) 
		{
			d.imgt[i] = new Image;
			d.imgt[i].src = IMAGE_URL_PATH + 'top' + i + '.gif';
		}
		if( !d.imgb ) d.imgb = new Array();
		for( var i=1; i <= BOTTOM_COUNT; i++ ) 
		{
			d.imgb[i] = new Image;
			d.imgb[i].src = IMAGE_URL_PATH + 'bottom' + i + '.gif';
		}
	}
}
function TimedCubeUpdate()
{
	ShowRandomImage(_switchTop);
	_switchTop = !_switchTop;
	setTimeout("TimedCubeUpdate()", SWITCH_RATE);
}

function ShowRandomImage(top)
{
	var img, a, max;
	if( top )
	{
		img = document.getElementById('imgCubeTop');
		a = document.imgt;
		max = TOP_COUNT;
	}
	else
	{
		img = document.getElementById('imgCubeBottom');
		a = document.imgb;
		max = BOTTOM_COUNT;
	}
		
	if( !img ) return;
	if( !a ) return;
	if( max <= 1 ) return;
	
	var index;
	do
	{
		index = Math.floor(Math.random() * max) + 1;
	}
	while( img.src == a[index].src );
	
	img.src = a[index].src;
}