/*==================================================================+
|   Program: Fire and Lightning Page-Builder                        |
+===================================================================+
|  Language: JavaScript                                             |
|   Version: 1.3                                                    |
|      Date: 2005-12-01                                             |
|    Author: Iain Gardiner (http://www.firelightning.com)           |
|    E-mail: iain at firelightning.com                              |
| Copyright: (c) 2005 Iain Gardiner. All rights reserved.           |
+------------------------------------------------------------------*/

var buildPage =
{
	initialise: function()
	{
		buildPage.contentDivision = document.getElementById('content');

		if (buildPage.contentDivision)
		{
			buildPage.buildHeader();
			buildPage.buildNavigation();
			buildPage.buildFooter();
			buildPage.addDivisions(buildPage.contentDivision);
			buildPage.wrapItUp();
		}
	},

	buildHeader: function()
	{
		buildPage.headerDivision = document.createElement('div');
		buildPage.headerDivision.id = 'header';
	},

	buildNavigation: function()
	{
		var navigationList = document.getElementById('navigationList');

		if (navigationList)
		{ 
			buildPage.navigationDivision = document.createElement('div');
			buildPage.navigationDivision.id = 'navigation';
			buildPage.navigationDivision.appendChild(navigationList);
			buildPage.addDivisions(buildPage.navigationDivision);
		}
	},

	buildFooter: function()
	{
		var pageCopyright = document.getElementById('copyrightInfo');

		if (pageCopyright)
		{
			buildPage.footerDivision = document.createElement('div');
			buildPage.footerDivision.id = 'footer';
			buildPage.footerDivision.appendChild(pageCopyright);
			buildPage.addDivisions(buildPage.footerDivision);
		}
	},

	addDivisions: function(obj)
	{
		// Local variables for this function:
		var topDivision, bottomDivision;
		// Create and insert the top division:
		topDivision = document.createElement('div');
		topDivision.className = 'top';
		obj.insertBefore(topDivision, obj.firstChild);
		// Ditto for the bottom one:
		bottomDivision = document.createElement('div');
		bottomDivision.className = 'bottom';
		obj.appendChild(bottomDivision);
	},

	// Place everything in a wrapper for easier styling:
	wrapItUp: function()
	{
		var wrapperDivision = document.createElement('div');
		wrapperDivision.id = 'wrapper';

		// Check each previous method has been successful:
		if (buildPage.headerDivision)
		{
			wrapperDivision.appendChild(buildPage.headerDivision);
			buildPage.headerDivision.onclick = function() { window.location = 'http://' + window.location.hostname; }
		}

		if (buildPage.navigationDivision) wrapperDivision.appendChild(buildPage.navigationDivision);

		if (buildPage.contentDivision) wrapperDivision.appendChild(buildPage.contentDivision);

		if (buildPage.footerDivision) wrapperDivision.appendChild(buildPage.footerDivision);

		// Insert the wrapper into the document:
		document.body.appendChild(wrapperDivision);
	}
}