String.implement({
	parseURL: function()
	{
		// this converts all relative and absolute URLs to fully-qualified ones
		
		var currentPath = location.href.substr(0, location.href.lastIndexOf('/'));
		var fullURL = this;
		
		// replace any ./s in a path
		
		fullURL = fullURL.replace(/\.\//g, '');
		
		// absolute links
		
		if (fullURL[0] == '/')
			fullURL = location.protocol + '//' + location.hostname + fullURL;
		
		// relative links
		
		if (fullURL.slice(0, location.protocol.length) != location.protocol)
			fullURL = currentPath + '/' + fullURL;
		
		// strip off any querystring
		
		if (fullURL.indexOf('?') != -1)
			fullURL = fullURL.slice(0, fullURL.lastIndexOf('?'));
		return fullURL;
	}
});

function resizePage()
{
	// resize #page if it isn't as tall as the browser window
	
	if (el = $('page'))
	{	
		if (el.getSize().y < window.getSize().y)
			el.setStyle('height', window.getSize().y + 'px');
	};	
};

function init()
{
	var el;

	// add 'Search' label to search box

	if (el = $('searchInput'))
	{
		el.addClass('default');
		el.set('value', 'Search');
		
		el.clear = function()
		{
			this.removeClass('default');
			this.set('value', '');			
		};
		
		el.addEvent('focus', el.clear);
	};
	
	// make E-Mail link display its submenu
	
	if (el = $('emailLink'))
	{
		el.menu = $('emailMenu');
		
		el.showMenu = function()
		{
			if (this.timeout)
			{
				$clear(this.timeout);
				this.timeout = null;
			};
			
			if (this.menu.getStyle('display') == 'none')
			{			
				this.menu.setStyle('display', 'block');
				this.menu.addEvent('mouseover', this.showMenu.bind(this));
				this.menu.addEvent('mouseout', this.hideMenu.bind(this));
				this.addEvent('mouseout', this.hideMenu);
			};
		};
		
		el.hideMenu = function()
		{
			if (! this.timeout)
				this.timeout = reallyHide.delay(250, this);
			
			function reallyHide()
			{
				this.menu.setStyle('display', 'none');
			};
		};
		
		el.addEvent('mouseover', el.showMenu);
	};
	
	window.addEvent('resize', resizePage);
	resizePage();
	
	// locate ourselves in the section navigation
	
	if ($('sectionNav'))
	{
		$('sectionNav').getElements('a').each(function (i)
		{
			if (i.get('href').parseURL() == location.href.parseURL())
				i.addClass('youAreHere');
		});
	};
};

window.addEvent('domready', init);