/**
 * @author Ted
 */

$(document).ready( prepPage );
$(window).resize( placeWatermark );

function prepPage()
{
	centerMenu();
	placeWatermark();
	roundMenubar();
}
/**
 * Assuming menu has style margin:auto applied to left and right, centers the menu on the page
 */
function centerMenu()
{
	var childCount = $('.menu > ul > li').length; // number of top-level children the menu has
	var width = $('.menu li').css('width').replace('px' , '') * childCount;
	$('.menu ul.root').css('width' , width + 'px').css('padding-left' , '0px');
	$('.menu').css('padding-left' , '0px');
}

function placeWatermark()
{
	var ptOffset = $('#page_title').get(0).offsetLeft;
	
	var leftOffset = null;
	if(ptOffset == 40) leftOffset = $('#content').get(0).offsetLeft + 52;
	else leftOffset = ptOffset + 10 - $('#content').css('padding-left').replace('px' , '');
	
	var topOffset = null;
	if(ptOffset == 40) topOffset = 210;
	else topOffset = $('#content').get(0).offsetTop + 200;
	$(document.body).css('background-position' , leftOffset + 'px ' + topOffset + 'px');
}

function roundMenubar()
{
	$('.menu .root > li:first').addClass('first');
	$('.menu .root > li:last').addClass('last');
}
