function styleSet(title) {
	StyleSwitcherAltGrouped.activate(title);
	styleButtonSet(title);
	return false;
}
function styleButtonSet(title) {
	switch (title) {
		case "txtNormal":
			Element.hide("a_txtNormal");
			Element.show("a_txtMedium");
			Element.hide("a_txtLarge");
			break;
		case "txtMedium":
			Element.hide("a_txtNormal");
			Element.hide("a_txtMedium");
			Element.show("a_txtLarge");
			break;
		case "txtLarge":
			Element.show("a_txtNormal");
			Element.hide("a_txtMedium");
			Element.hide("a_txtLarge");
			break;
		case "layFixed":
			Element.hide("a_layFixed");
			Element.show("a_layLiquid");
			break;
		case "layLiquid":
			Element.show("a_layFixed");
			Element.hide("a_layLiquid");
			break;
	}
}

/*========================================================================
 * Cookies object
/*======================================================================*/
var Cookies = {
	/*-------------------------------------------------------------------
	 * deleteCookie(String[, String, String]) : return Boolean
	 *  Deletes the specified cookie.
	/*-----------------------------------------------------------------*/
	deleteCookie: function(psName, psPath, psDomain) {
		if (this.getCookie(psName)) {
			var d = new Date(1000);
			document.cookie = psName + "=" +
				((psPath) ? "; path=" + psPath : "") +
				((psDomain) ? "; domain=" + psDomain : "") +
				"; expires=" + d.toGMTString();
			return true;
		}
		return false;
	},
	/*-------------------------------------------------------------------
	 * getCookie(String) : return String
	 *  Gets the value of the specified cookie.
	 *  Returns null if name not found.
	/*-----------------------------------------------------------------*/
	getCookie: function(psName) {
		var sCookie = document.cookie;
		var sPrefix = psName + "=";
		var nBegin = sCookie.indexOf("; " + sPrefix);
		if (nBegin == -1) {
			nBegin = sCookie.indexOf(sPrefix);
			if (nBegin != 0) { return null; }
		} else {
			nBegin += 2;
		}
		var nEnd = document.cookie.indexOf(";", nBegin);
		if (nEnd == -1) {
			nEnd = sCookie.length;
		}
		return unescape(sCookie.substring(nBegin + sPrefix.length, nEnd));
	},
	/*-------------------------------------------------------------------
	 * isSupported([String]) : return Boolean
	 *  Tests whether the client supports cookies.
	/*-----------------------------------------------------------------*/
	isSupported: function(psPath) {
		var sKey = "__TESTCOOKIE";
		this.setCookie(sKey, "1", null, psPath);
		return this.deleteCookie(sKey, psPath);
	},
	/*-------------------------------------------------------------------
	 * setCookie(String, String[, Date, String, String, Boolean]) : return String
	 *  Sets the value and expiration of the specified cookie.
	/*-----------------------------------------------------------------*/
	setCookie: function(psName, psValue, pdExpires, psPath, psDomain, pbSecure) {
		var sCookie = psName + "=" + escape(psValue) +
			((pdExpires) ? "; expires=" + pdExpires.toGMTString() : "") +
			((psPath) ? "; path=" + psPath : "") +
			((psDomain) ? "; domain=" + psDomain : "") +
			((pbSecure) ? "; secure" : "");
		document.cookie = sCookie;
		return sCookie;
	}
};

/*========================================================================
 * StyleSwitcherAltGrouped object
/*======================================================================*/
var StyleSwitcherAltGrouped = {
	prefixLen: 3,
	cookieName: "USER_STYLESHEET",
	expirePeriod: (365*24*60*60*1000),
	getActives: function() {
		var actives = "";
		var aLinks = document.getElementsByTagName("link");
		for (var s, i = 0; (s = aLinks[i]); i++) {
			if (s.getAttribute("rel").indexOf("style") != -1
					&& s.getAttribute("rel").indexOf("alt") != -1
					&& s.getAttribute("title")
					&& !s.disabled) {
				actives = (actives.length ? actives + "," : actives) + s.getAttribute("title");
			}
		}
		return actives;
	},
	activate: function(title) {
		if (!title) { return; }
		var prefix = title.substr(0, this.prefixLen);
		var aLinks = document.getElementsByTagName("link");
		for (var s, i = 0; (s = aLinks[i]); i++) {
			if (s.getAttribute("rel").indexOf("style") != -1
					&& s.getAttribute("rel").indexOf("alt") != -1
					&& s.getAttribute("title")) {
				if (s.getAttribute("title").substr(0, this.prefixLen) == prefix) {
					s.disabled = !(s.getAttribute("title") == title);
				}
//debug("l: " + s.getAttribute("title") + " " + s.disabled);
			}
		}
		this.setChoices(this.getActives());
		return false;
	},
	getChoices: function() {
		if (!Cookies) { return ""; }
		return Cookies.getCookie(this.cookieName) || "";
	},
	setChoices: function(titles) {
//debug("sc: " + titles);
		if (!Cookies) { return false; }
		var exp = new Date();
		exp.setTime(exp.getTime()+this.expirePeriod);
		Cookies.setCookie(this.cookieName, titles, exp);
		return false;
	},
	activateChoices: function(defaultTitles) {
		var titles = this.getChoices() || defaultTitles;
//debug("ac: " + titles);
//		var aTitles = titles.split(",");
		var aLinks = document.getElementsByTagName("link");
		for (var s, i = 0; (s = aLinks[i]); i++) {
			if (s.getAttribute("rel").indexOf("style") != -1
					&& s.getAttribute("rel").indexOf("alt") != -1
					&& s.getAttribute("title")) {
				s.disabled = true;	// IE requires this
				s.disabled = !(titles.indexOf(s.getAttribute("title")) != -1);	// TODO this is open to bugs, needs a better match
//debug("l: " + s.getAttribute("title") + " " + s.disabled);
			}
		}
		return false;
	}
};
