function initMenus() {
	$('ul.navmenu ul').hide();
	$.each($('ul.navmenu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.navmenu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}

function initHover() {
	$('div.subArticle').mouseover(
		function() {
			$('a#mainHeadingLink').attr('href', $('#' + this.id + ' a.headingLink').attr('href'));
			$('a#mainHeadingLink').text($('#' + this.id + ' h4').text());
			
			$('div#mainText').html($('#' + this.id + ' span.hideme').clone());
			
			$('a#mainMoreLink').attr('href', $('#' + this.id + ' a.moreLink').attr('href'));
			$('p#mainMore').html($('#' + this.id + ' p.more').clone());
			
			// First, load the original image into the 'big spot' as a temporary update
			var origImageSrc = $('#' + this.id + ' img').attr('src');
			var newImageSrc = origImageSrc.replace("articles/","articles/big/");
			
			if ($('img#mainImg').attr('src') != newImageSrc) {
				$('img#mainImg').attr('src', origImageSrc);
			}
			
			// Then, start loading the bigger image into the 'big spot'
			
			$('img#mainImg').attr('src', newImageSrc);
			$('img#mainImg').attr('alt', $('#' + this.id + ' img').attr('alt'));
			$('a#mainImgLink').attr('href', $('#' + this.id + ' a.imageLink').attr('href'));
		}
	);
}

$(document).ready(function() {
	initMenus();
	// Temporarily removed the hover functionality to make the lead article static.
	// Testing to see if it makes a difference to click throughs... - 27th March 2009
	//initHover();
	var origImageSrc = $('img#mainImg').attr('src');
	
	if(origImageSrc) {
		var newImageSrc = origImageSrc.replace("articles/","articles/big/");

		if ($('img#mainImg').attr('src') != newImageSrc) {
			$('img#mainImg').attr('src', origImageSrc);
		}
			
		// Then, start loading the bigger image into the 'big spot'
			
		$('img#mainImg').attr('src', newImageSrc);
	}
});

function hideGoogle(){
	var google = document.getElementById("google").value;
	if (google == "Google Search"){
		document.getElementById("google").value = "";
	}
}

function showGoogle(){
	var google = document.getElementById("google").value;
	if (google == ""){
		document.getElementById("google").value = "Google Search";
	}
}