/*CUSTOM*/

// Searches for existance of cookie
var starter = document.cookie.indexOf("TEXTSIZE=");
var ender = document.cookie.indexOf("ENDTEXTSIZE");
var size = document.cookie.substring(starter+9,ender);

var contraststarter = document.cookie.indexOf("CONTRAST=");
var contrastender = document.cookie.indexOf("ENDCONTRAST");
var contrast = document.cookie.substring(contraststarter+9,contrastender);

var graphicsstarter = document.cookie.indexOf("GRAPHICS=");
var graphicsender = document.cookie.indexOf("ENDGRAPHICS");
var graphics = document.cookie.substring(graphicsstarter+9,graphicsender);


$(function() {
	/*if the cookie wasn't found (text sizing never having been done before), 
	output the bog-standard stylesheet html tag  */
	if (starter < 0 || size == "") {
		$('#sizecss').remove();
		$('<link rel="stylesheet" type="text/css" href="/css/front/bodysize.css" id="sizecss" />').insertAfter('#importcss');
	}
	/*Otherwise, if the cookie IS found, load the correct size.*/
	else {
		$('#sizecss').remove();
		$('<link rel="stylesheet" type="text/css" href="/css/front/bodysize'+size+'.css" id="sizecss" />').insertAfter('#importcss');
	}
	
	/*if the cookie wasn't found (contrast change never having been done before), 
		output the bog-standard stylesheet html tag  */
	if (contraststarter < 0) {
		$('#contrastcss').remove();
	}
	/*Otherwise, if the cookie IS found, load the correct contrast.*/
	else {
		$('#contrastcss').remove();
		if (contrast != "") {
			//document.getElementById('themecss').href='/css/front/highcontrast.css';
			$('<link rel="stylesheet" type="text/css" href="/css/front/contrast'+contrast+'.css" id="contrastcss" />').insertAfter('#importcss');
		}
	}
	
	if (graphicsstarter < 0) {
		$('#graphicscss').remove();
	}
	/*Otherwise, if the cookie IS found, load the correct contrast.*/
	else {
		$('#graphicscss').remove();
		if (graphics != "") {
			//document.getElementById('themecss').href='/css/front/highcontrast.css';
			$('<link rel="stylesheet" type="text/css" href="/css/front/graphics'+graphics+'.css" id="graphicscss" />').insertAfter('#importcss');
		}
	}
	
});

function textsizer(the_size){	
	if (contraststarter < 0) {
		contrast = "";
	}
	if (graphicsstarter < 0) {
		graphics = "";
	}
	
	//if there is no size specified, set small cookie
	if(the_size==""){
	var the_cookie ="TEXTSIZE=ENDTEXTSIZE+CONTRAST=" + contrast + "ENDCONTRAST+GRAPHICS="+graphics + "ENDGRAPHICS; path=/";
	document.cookie = the_cookie;
	//document.getElementById('sizecss').href='/css/front/bodysize.css';
	window.location.reload( true );
	}
	
	if (the_size=="med"){
		//set medium cookie
		var the_cookie ="TEXTSIZE=medENDTEXTSIZE+CONTRAST=" + contrast + "ENDCONTRAST+GRAPHICS="+graphics + "ENDGRAPHICS; path=/";
		document.cookie = the_cookie;
		//document.getElementById('sizecss').href='/css/front/bodysizemed.css';
		window.location.reload( true );
	}
	
	if (the_size=="lrg"){
		//set large cookie
		var the_cookie ="TEXTSIZE=lrgENDTEXTSIZE+CONTRAST=" + contrast + "ENDCONTRAST+GRAPHICS="+graphics + "ENDGRAPHICS; path=/";
		document.cookie = the_cookie;
		//document.getElementById('sizecss').href='/css/front/bodysizelrg.css';
		window.location.reload( true );
	}
}

function contrastchanger(the_contrast){
	if (starter < 0) {
		size = "";
	}
	
	// contrast stuff
	var the_cookie ="TEXTSIZE=" + size + "ENDTEXTSIZE+CONTRAST="+the_contrast+"ENDCONTRAST; path=/";
	document.cookie = the_cookie;
	window.location.reload( true );
}

function graphicschanger(thegraphicmode){
	
	if (starter < 0) {
		size = "";
	}
	
	// contrast stuff
	var the_cookie ="TEXTSIZE=" + size + "ENDTEXTSIZE+GRAPHICS="+thegraphicmode+"ENDGRAPHICS; path=/";
	document.cookie = the_cookie;
	window.location.reload( true );
}

