// JavaScript Document

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		try {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) {
					a.disabled = false;
				}
			}
		} catch (ex) {}
	}
	var expiresDate = new Date();
	expiresDate.setDate(expiresDate.getDate()+1);	//expires tomorrow
	xSetCookie("switchersheet", title, expiresDate, "/");
}

function cookieStyleSheet() {
	var sheet = xGetCookie("switchersheet");
	if (sheet) {
		if (sheet.length > 0) {
			setActiveStyleSheet(sheet);
		}
	}
}

function setSmallFonts() {
	setActiveStyleSheet('smallfonts');
	return null;
}

function setNormalFonts() {
	setActiveStyleSheet('default');
	return null;
}

function setLargeFonts() {
	setActiveStyleSheet('largefonts');
	return null;
}

function injectBehaviours() {
	var smallSwitch, normalSwitch, largeSwitch;
	try {
		smallSwitch=$('styleswitchsmall');
	} catch(ex) {}
	try {
		normalSwitch=$('styleswitchnormal');
	} catch(ex) {}
	try {
		largeSwitch=$('styleswitchlarge');
	} catch(ex) {}
	if (smallSwitch) {
		addEvent(smallSwitch, 'click', setSmallFonts);
	}
	if (normalSwitch) {
		addEvent(normalSwitch, 'click', setNormalFonts);
	}
	if (largeSwitch) {
		addEvent(largeSwitch, 'click', setLargeFonts);
	}
}

addEvent(window, 'load', cookieStyleSheet);
addEvent(window, 'load', injectBehaviours);