var loading = '<div id="loadingBlack"></div>';

window.addEvent('domready', function()
	{
		
		// Page Load Animation
		var logoFx = new Fx.Morph ('logo', {duration: 2800, transition: Fx.Transitions.Elastic.easeOut, wait:false});
		var aboutButtonFx = new Fx.Morph('aboutButton', {duration:200, wait:false});
		var clientsButtonFx = new Fx.Morph('clientsButton', {duration:200, wait:false});
		var printCollateralButtonFx = new Fx.Morph('printDesignButton', {duration:200, wait:false});
		var advertisingButtonFx = new Fx.Morph('advertisingButton', {duration:200, wait:false});
		var identityButtonFx = new Fx.Morph('identityButton', {duration:200, wait:false});
		var interactiveWebButtonFx = new Fx.Morph('interactiveWebButton', {duration:200, wait:false});
		var publicationButtonFx = new Fx.Morph('publicationButton', {duration:200, wait:false});

		logoFx.start ({'left': [-100,38]});
		
		aboutButtonFx.start ({'opacity': [0, 1]}).chain(function(){
		clientsButtonFx.start ({'opacity': [0, 1]}).chain(function(){
		printCollateralButtonFx.start ({'opacity': [0, 1]}).chain(function(){
		advertisingButtonFx.start ({'opacity': [0, 1]}).chain(function(){
		identityButtonFx.start ({'opacity': [0, 1]}).chain(function(){
		interactiveWebButtonFx.start ({'opacity': [0, 1]}).chain(function(){
		publicationButtonFx.start ({'opacity': [0, 1]});
		});
		});
		});
		});
		});
		});

		// Make the logo a home page button.
		$('logo').addEvent('click', function()
		{
		link('content/home/index.php');
		});

		var bodyElement = $$('body')[0]; 
		var bodyFx = new Fx.Morph (bodyElement, {duration: 4000, transition: Fx.Transitions.Elastic.easeOut, wait:false});
		var list = $$('div.button');
		
		list.each(function(element)
		{
			var fx = new Fx.Morph(element, {duration:2000, transition: Fx.Transitions.Elastic.easeOut, wait:false});
			element.addEvent('mouseenter', function()
			{
			fx.start({'margin-right': 32});
			bodyFx.start ({'background-color': '#000000'});
			});

			element.addEvent('mouseleave', function()
			{
			fx.start({'margin-right': 4});
			bodyFx.start ({'background-color': '#000000'});
			});
		});
		link('content/home/index.php');
	}
);

function link(url)
{	
	$('content').setStyle('height','266px');
	// Set up vars if initial page load.	
	$('content').set('html', loading);
	var req = new Request.HTML({
		url: url,
		update: $('content'),
		onSuccess: function(html)
		{
			newHeight = $('content').scrollHeight;
			var contentFx = new Fx.Morph('content', {duration:400, wait:false});
			contentFx.start ({'height':newHeight});
		},
		onFailure: function()
		{
			$('content').set('text', 'The page failed to load. Please try again.');
		}
	});
	req.send();
};

function changeColors(color)
{	
	var currentContentBackground = $('content').getStyle('background-color');
	
	if (color === 'black' && currentContentBackground != '#000000')
		{
			var contentFx = new Fx.Morph('contentFrame', {duration:1200, wait:false});
			contentFx.start ({'background-color':'#000000'});
			
			$('content').setStyle('background-color','#000000');
			loading = '<div id="loadingBlack"></div>';
		}
	if (color === 'white' && currentContentBackground != '#000000')
		{
			var contentFx = new Fx.Morph('contentFrame', {duration:1200, wait:false});
			contentFx.start ({'background-color':'#eeeeee'});
			
			$('content').setStyle('background-color','#000000');
			loading = '<div id="loadingWhite"></div>';
		}
	
};