var curStyleIndex = 0;
var styleArray = new Array();
styleArray[0] = "Text small";
styleArray[1] = "Text medium";
styleArray[2] = "Text large";
styleArray[3] = "Text extra-large";

$(function() {
	checkStylesheet();
	checkBoundaries(curStyleIndex);
});

function checkStylesheet()
{
	cookieStyleIndex = readCookie("text_style");

	if (cookieStyleIndex != null) {
		setStylesheet(cookieStyleIndex);
		curStyleIndex = cookieStyleIndex;
	}
}

function doStyle(cookieName, styleIndex)
{
	if ((styleIndex >= 0) && (styleIndex < styleArray.length))
	{
		setStylesheet(styleIndex);
		createCookie(cookieName, styleIndex, 365);
		curStyleIndex = styleIndex;
	}
	checkBoundaries(styleIndex);
}

function setStylesheet(styleIndex) {
	$("link[rel*='style'][title]").each(function() {
		this.disabled = true;
	});
	$("link[rel*='style'][title=" + styleArray[styleIndex] + "]").get(0).disabled = false;
}

function checkBoundaries(styleIndex) {
	$("#text_larger, #text_smaller").removeClass("disabled");
	if (styleIndex >= styleArray.length - 1) $("#text_larger").addClass("disabled");
	else if (parseInt(styleIndex) <= 0) $("#text_smaller").addClass("disabled");
}