/*
One line Accessibility Module by Andy Barratt
For more information and instructions on usage, see http://blog.andybarratt.co.uk/?p=426
*/

function changeStyle(ID)
{
	//create cookie to store body style ID in
	var cookieName = 'bodyStyleID=';
	var cookieVal = ID;
	var date = new Date();
	date.setFullYear(date.getFullYear() + 1);	
	var cookieExpires = ';expires=' + date.toGMTString();
	document.cookie = cookieName + cookieVal + cookieExpires+';'+'path=/;';
	//set body's ID to match the chosen colour scheme.
	document.body.id=ID;

        /*The wildlife homepage requires a refresh after changing colours
          this is done with the following three lines.*/
        var url = window.location.pathname;
        var filename = url.substring(url.lastIndexOf('/')+1);
        if(filename=="wildlifehome.htm"){location.reload(true);}
}

//-----------------------------------------------------------------------------------------

function changeFontSize(percentage)
{
	//create cookie to store font size in
	var cookieName = 'fontSize=';
	var cookieVal = percentage;
	var date = new Date();
	date.setFullYear(date.getFullYear() + 1);	
	var cookieExpires = ';expires=' + date.toGMTString();
	document.cookie = cookieName + cookieVal + cookieExpires+';'+'path=/;';
	//set body's fontsize to the specified percentage.
	document.body.style.fontSize=percentage;
}

//------------------------------------------------------------------------------------------

//this is a function I was experimenting with but ultimately cause more problems than it solved
function updateForumPage(bodyStyleID, percentage)
{
	if(window.location.pathname.match("/Your-Community/Community/"))
	{
		//get current URL of the iframe
		var currentURL = document.getElementById("forum").src;

		//build new URL for the iframe
		var newURL = "http://www.taypol.co.uk/accessibility.php?bodyStyleID=" + bodyStyleID + "&percentage=" + percentage;
		//alert(newURL);
		
		//direct iframe to the new URL
		document.getElementById("forum").src = newURL;
                window.setTimeout("document.getElementById('forum').src = '" + currentURL + "'", 2000);

	}
}

//------------------------------------------------------------------------------------------

//load all the cookies that exist into an array
var cookies = document.cookie.split(';');

//create variables to store the cookie values we need in
var bodyStyleID = '';
var percentage = '';

//each cookie that we found
for(i=0;i<cookies.length;i++)
{
	//split the cookie crumbs into the bits we need
	var cookieCrumbs = cookies[i].split('=');
	var cookieName = cookieCrumbs[0].replace(/ /g, '');
	var cookieValue = cookieCrumbs[1];
	
	if(cookieName=='bodyStyleID')
	{
		bodyStyleID = cookieValue;
		document.body.id=bodyStyleID;
	}
	if(cookieName=='fontSize')
	{
		percentage = cookieValue;
		document.body.style.fontSize=percentage;
	}
}

//if no colourScheme cookie found
if(bodyStyleID=='')
{
	document.body.id='default';
}
//if no colour fontSize cookie found
if(percentage=='')
{
	document.body.style.fontSize='100%';
}

document.write('<span id="Accessibility">');
document.write('<a href="/Accessibility" Title="Click for Accessibility Information"><img style="vertical-align:middle;" alt="Accessibility Information" src="/Accessibility/icon.gif" /></a>');
document.write('&nbsp;|&nbsp;');
document.write('<a href="javascript:changeStyle(\'default\');" Title="Choose default colour scheme"><img style="vertical-align:middle;" alt="Black On White" src="/Accessibility/blackOnWhite.gif" /></a>');
document.write('<a href="javascript:changeStyle(\'whiteOnBlack\');" Title="Choose white on black colour scheme"><img style="vertical-align:middle;" alt="White On Black" src="/Accessibility/whiteOnBlack.gif" /></a>');
document.write('<a href="javascript:changeStyle(\'blackOnYellow\');" Title="Choose black on yellow colour scheme"><img style="vertical-align:middle;" alt="Black On Yellow" src="/Accessibility/blackOnYellow.gif" /></a>');
document.write('<a href="javascript:changeStyle(\'yellowOnBlack\');" Title="Choose yellow on black colour scheme"><img style="vertical-align:middle;" alt="Yellow On Black" src="/Accessibility/yellowOnBlack.gif" /></a>');
document.write('<a href="javascript:changeStyle(\'blackOnPink\');" Title="Choose black on pink colour scheme"><img style="vertical-align:middle;" alt="Black On Pink" src="/Accessibility/blackOnPink.gif" /></a>');
document.write('&nbsp;|&nbsp;');
document.write('<a style="text-decoration:none; font-size:16px;" href="javascript:changeFontSize(\'100%\');" Title="Normal Text Size">A</a>');
document.write('<a style="text-decoration:none; font-size:18px" href="javascript:changeFontSize(\'110%\');" Title="Medium Text Size">A</a>');
document.write('<a style="text-decoration:none; font-size:20px" href="javascript:changeFontSize(\'120%\');" Title="Large Text Size">A</a>');
document.write('</span>');












