var currSelectedSizeImg;
var smallBttn;
var fontCookieName = "fontSizer";
var BUTTON_IMAGE_SPACE = 3;

function adjustFontSize(fontSize, isOnLoad) {
	var contentDiv = document.getElementById('content');
	contentDiv.className = "content_fontSize_"+fontSize;
		
	if(!isOnLoad) {
		setCookie(fontCookieName, fontSize, "/");
		moveSelectedIndicator(fontSize);
	}
}


function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function setCookie(cookieName,cookieValue, cookiePath) {
	document.cookie = cookieName + "=" + escape(cookieValue) + ";path=" + cookiePath;
	// no time expiry set up, will remove upon exiting browser
}

function checkFontCookie() {
	var fontSize = 0;
	var numFontSize;
	fontSize=getCookie(fontCookieName);
	numFontSize = Number(fontSize);
	if(numFontSize > 0) {
		moveSelectedIndicator(numFontSize);
	}
	if (fontSize!=null && fontSize!="" && fontSize != "1" && fontSize!=0) {
		adjustFontSize(fontSize, true);
	}
}

function moveSelectedIndicator(numFontSize) {
	smallBttn = document.getElementById('bttnSmallFont') || 0;
	currSelectedSizeImg = document.getElementById('currSelectedFontSize') || 0;
	
	if(smallBttn) {
		var xOffset = (numFontSize * (smallBttn.width + BUTTON_IMAGE_SPACE)) - (currSelectedSizeImg.width) + 1;			
		currSelectedSizeImg.style.marginLeft = xOffset + "px";
	}
}