$(document).ready(function()
{
$('body').before().append('<div id="overlay">\n</div>\n');

$('#overlay').css('opacity' , '0.3');
var offset = $('#container').offset();

$('div.biography').hide();

$('p.biography a').toggle(function()
	{
	$(this).text('Hide biography');
	$('div.biography').slideDown("slow");
	return false;
	},
	function()
	{
	$(this).text('Show biography');
	$('div.biography').slideUp("slow");
	return false;
	});

// update this url when live - for right hand column latest news
$('#news-feed #latest').load("/news-and-resources/news/ .content-box:nth(0) p:nth(0)");

// generic function used for the expanding sections
$('.expand').next().addClass('hidden separator').prev().toggle(function()
	{
		$(this).next().slideDown();
	},function()
	{
		$(this).next().slideUp();
	});

$('.expand:last').next().removeClass('separator');

// population of each of the newsletter sections

$('#insight h2').each(function()
	{
		$(this).after('\n<div class="html-loader"><p class="close"><a href="#">close</a></p>\n<div class="insight-content">\n</div>\n</div>');
		$(this).next().hide();
	});

$('#insight h2 a').click(function()
	{
		insightUrl= $(this).attr('href');
		$(this).parent().next().fadeIn().find('p.close').next().load(insightUrl);
		$('#overlay').show();
		return false;
	});

$('.html-loader p:first-child').click(function()
	{
		$('.html-loader').slideUp('100');
		$('#overlay').hide();
		return false;
	});

$('.popup').each(function()
	{
		$(this).after('\n<div class="html-loader"><p class="close"><a href="#">close</a></p>\n<div class="insight-content">\n</div>\n</div>');
		$(this).next().hide();
	});

$('.popup a').click(function()
	{
		htmlUrl= $(this).attr('href');
		$(this).parent().next().fadeIn().find('p.close').next().load(htmlUrl);
		$('#overlay').show();
		return false;
	});

$('#right-column .html-loader').css('left' , offset.left+100 + 'px').css('margin' , '0');

$('.html-loader p:first-child').click(function()
	{
		$('.html-loader').slideUp('100');
		$('#overlay').hide();
		return false;
	});

$('#content-navigation a[@href^="http://"]').find('>span').append('<img src="/images/layout/external.gif" alt="external link" />');

$('a[@href^="http://"]').attr('target' , '_blank');

$('#sitemap a[@href^="http://"]').append('<img src="/images/layout/external-sitemap.gif" alt="external link" />');

});




