// Initially hide the body to stop FOUC
document.write('<style type="text/css">body{display:none}</style>');

// Check when document has loaded
$(function() {

// Show body again
$('body').css('display','block');

// functions to check whether the ID we wish to append/prepend exists
function fnAppendIfExists( id_to_check, id_to_append_to ) {
	if ($(id_to_check).length != 0) {
		$(id_to_check).appendTo(id_to_append_to);
	 }
}

function fnPrependIfExists( id_to_check, id_to_prepend_to ) {
	if ($(id_to_check).length != 0) {
		$(id_to_check).prependTo(id_to_prepend_to);
	 }
}

// ***************************************************
// layout routines 
// ***************************************************

// Column options are:

// left | center | right
// left | right-wide


// Home page *************************************

// Check the body tag
if ($('body#homepage').length != 0) {

	// create columns
	$('<div id="left"></div>').appendTo('#content'); 
	$('<div id="center"></div>').appendTo('#content');
	$('<div id="right"></div>').appendTo('#content');

	// assign sections to columns
	fnAppendIfExists('#sitenavigation', '#left');
	fnAppendIfExists('#bodytext', '#center');
	fnAppendIfExists('#latestnews', '#right');

}

// Standard page *************************************

// Check the body tag
if ($('body#contentpage').length != 0) {

	// create columns
	$('<div id="left"></div>').appendTo('#content');
	$('<div id="right-wide"></div>').appendTo('#content');

	// assign sections to columns
	fnAppendIfExists('#secondarynav', '#left');
	fnAppendIfExists('#bodytext', '#right-wide');

}


});