// GroundVision JavaScript functions
// Copyright GroundVision Enterprises 2010

var groundVisionFrame = 1;

function cacheImages()
{
	(new Image(400, 64)).src = 'images/groundvision.gif';
	(new Image(400, 64)).src = 'images/groundvision.bmp';

	(new Image(128, 32)).src = 'images/buttonimaginewhite.bmp';
	(new Image(128, 32)).src = 'images/buttonimpactwhite.bmp';
	(new Image(128, 32)).src = 'images/buttonimpresswhite.bmp';
	(new Image(128, 32)).src = 'images/buttoninformwhite.bmp';
	(new Image(128, 32)).src = 'images/buttoninvolvewhite.bmp';
	(new Image(128, 32)).src = 'images/buttoninnovatewhite.bmp';
	(new Image(128, 32)).src = 'images/buttongallerywhite.bmp';
	(new Image(128, 32)).src = 'images/buttonfounderwhite.bmp';
	(new Image(128, 32)).src = 'images/buttoncontactwhite.bmp';

	(new Image(128, 32)).src = 'images/buttonimaginepurple.bmp';
	(new Image(128, 32)).src = 'images/buttonimpactpurple.bmp';
	(new Image(128, 32)).src = 'images/buttonimpresspurple.bmp';
	(new Image(128, 32)).src = 'images/buttoninformpurple.bmp';
	(new Image(128, 32)).src = 'images/buttoninvolvepurple.bmp';
	(new Image(128, 32)).src = 'images/buttoninnovatepurple.bmp';
	(new Image(128, 32)).src = 'images/buttongallerypurple.bmp';
	(new Image(128, 32)).src = 'images/buttonfounderpurple.bmp';
	(new Image(128, 32)).src = 'images/buttoncontactpurple.bmp';

	var image = $('image');
	if (image != null)
		(new Image(288, 488)).src = image.src;
	
	if (pageButton == 'gallery')
	{
		(new Image(452, 8)).src = 'images/blueabovewide.bmp';
		(new Image(452, 12)).src = 'images/bluebelowwide.bmp';
		(new Image(452, 16)).src = 'images/bluewide.bmp';
	}
	else
	{
		(new Image(320, 8)).src = 'images/blueabove.bmp';
		(new Image(320, 12)).src = 'images/bluebelow.bmp';
		(new Image(320, 16)).src = 'images/blue.bmp';
	}
	
	(new Image(128, 32)).src = 'images/buttonmorewhite.bmp';
	(new Image(128, 32)).src = 'images/buttonmoreblue.bmp';
	
	for (var tagNum = 1; tagNum <= numTags; tagNum++)
		(new Image()).src = $('tag' + tagNum + 'img').src;
}

function initialise()
{
	// GroundVision
	
	var animationDelay = 0;
	
	/*
	GroundVision animation removed because it only works well under Firefox and makes pages slow to appear
	
   if (document.all)  // IE, alas
	{
		// GIF animation is too slow or doesn't work at all under IE so don't show
		animationDelay = 0;
	}
	else
	{
		// GIF animation works under other browsers so show
		cacheImages();  // cache all images before starting GIF animation to give it a better chance of working smoothly
		$('groundvisiongif').show();  // show GIF animation
		$('groundvisiongif').src = 'images/groundvision.gif';  // GIF animation sometimes fails to start without this line
		animationDelay = 18 / 25;  // GIF animation is 18 frames at 25 frames per second
	}
	new Effect.Appear('groundvisionbmp', { delay: animationDelay, duration: 0.5, afterFinish: function() { $('groundvisiongif').hide(); } });
	*/
	
	// Tags and content
	
	var contentAppearDelay;
	var contentAppearDuration = 1.5;
	
	var image = $('image');
	
	if (numTags == 0)
	{
		contentAppearDelay = animationDelay;
		
		new Effect.Appear('buttons', { delay: contentAppearDelay, duration: contentAppearDuration });
		if (image != null)
			new Effect.Appear(image, { delay: contentAppearDelay, duration: contentAppearDuration });
		new Effect.Appear('content', { delay: contentAppearDelay, duration: contentAppearDuration });
	}
	else
	{
		var tagAppearDelay = animationDelay + 0.25;
		var tagAppearDuration = 1;
		var tagFadeDelayAdjust = -0.5;
		var tagFadeStagger = 0.25;

		var tagFadeDelay = tagReadTime * numTags + tagFadeDelayAdjust;
		var tagFadeDelayDelta = tagFadeStagger - tagReadTime;
		
		// Content starts appearing at the same time as last tag starts fading
		contentAppearDelay = tagAppearDelay + tagReadTime * (numTags - 1) + tagAppearDuration + tagFadeDelay + tagFadeDelayDelta * (numTags - 1);
		
		new Effect.Appear('tag1', { delay: tagAppearDelay, duration: tagAppearDuration,
			afterFinish: function()
			{
				new Effect.Opacity('tag1', { delay: tagFadeDelay, duration: 1.0, from: 1.0, to: 0.0,
					afterFinish: function()
					{
						$('tag1').hide();
					}
				});
			}
		});

		new Effect.Appear('tag2', { delay: tagAppearDelay + tagReadTime, duration: tagAppearDuration,
			afterFinish: function()
			{
				new Effect.Opacity('tag2', { delay: tagFadeDelay + tagFadeDelayDelta, duration: 1.0, from: 1.0, to: 0.0,
					afterFinish: function()
					{
						$('tag2').hide();
					}
				});
			}
		});
		
		if (numTags == 3)
		{
			new Effect.Appear('tag3', { delay: tagAppearDelay + tagReadTime * 2, duration: tagAppearDuration,
				afterFinish: function()
				{
					new Effect.Opacity('tag3', { delay: tagFadeDelay + tagFadeDelayDelta * 2, duration: 1.0, from: 1.0, to: 0.0,
						afterFinish: function()
						{
							$('tag3').hide();
						}
					});
				}
			});
		}
		
		if (image != null)
			new Effect.Appear(image, { duration: contentAppearDelay + contentAppearDuration });
		new Effect.Appear('buttons', { delay: contentAppearDelay, duration: contentAppearDuration });
		new Effect.Appear('content', { delay: contentAppearDelay, duration: contentAppearDuration });
	}
	
	// Buttons
	
	$('buttonimagine' ).src = 'images/buttonimaginewhite.bmp';
	$('buttonimpact'  ).src = 'images/buttonimpactwhite.bmp';
	$('buttonimpress' ).src = 'images/buttonimpresswhite.bmp';
	$('buttoninform'  ).src = 'images/buttoninformwhite.bmp';
	$('buttoninvolve' ).src = 'images/buttoninvolvewhite.bmp';
	$('buttoninnovate').src = 'images/buttoninnovatewhite.bmp';
	$('buttongallery' ).src = 'images/buttongallerywhite.bmp';
	$('buttonfounder' ).src = 'images/buttonfounderwhite.bmp';
	$('buttoncontact' ).src = 'images/buttoncontactwhite.bmp';
	if (pageButton != '')
		$('button' + pageButton).src = 'images/button' + pageButton + 'purple.bmp';
}
function highlightButton(button)
{
	if (button.id == 'button' + pageButton)
		return;
	$(button.id).src = 'images/' + button.id + 'purple.bmp';
}
function unhighlightButton(button)
{
	if (button.id == 'button' + pageButton)
		return;
	$(button.id).src = 'images/' + button.id + 'white.bmp';
}
