var prefsLoaded = false;
var defFontSize = 1.3;
var minFontSize = .8;
var maxFontSize = 1.8;
var smallWidth = 950;
var varWidth = 95;
var defWidth = varWidth;

var currentWidth = defWidth;
var currentFontSize = defFontSize;

function changeFontSize(sizeDifference){
	currentFontSize = parseFloat(currentFontSize) + parseFloat(sizeDifference);

		if(currentFontSize > maxFontSize){
			currentFontSize = maxFontSize;
		}else if(currentFontSize < minFontSize){
			currentFontSize = minFontSize;
		}
	setFontSize(currentFontSize);
	saveSettings();
};

function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('contentbody') : document.all('contentbody');
	var stObj2 = (document.getElementById) ? document.getElementById('global_footer_wrapper') : document.all('global_footer_wrapper');
	stObj.style.fontSize = stObj2.style.fontSize = fontSize.toString().substr(0,3) + 'em';
	

};
function revertStyles(){
	currentWidth = defWidth;
	setWidth(defWidth);

	currentFontSize = defFontSize;
	changeFontSize(0);

}

function toggleWidth(){
	currentWidth = parseInt(currentWidth);
	var newWidth = defWidth;
	switch(currentWidth)
	{ case smallWidth:
	    newWidth = varWidth;
	    break;
	  case varWidth:
	    newWidth = smallWidth;
	    break;
	  default:
	    newWidth = defWidth;
	    break;
	}
	currentWidth = newWidth;
	setWidth(newWidth);
}

function setWidth(width){
	var stObj = (document.getElementById) ? document.getElementById('contentbody') : document.all('contentbody');
	var stObj2 = (document.getElementById) ? document.getElementById('global_footer_wrapper') : document.all('global_footer_wrapper');
	width = parseFloat(width);
	switch(width)
	{ case smallWidth:
	    stObj.style.width = width + 'px';
	    stObj2.style.width = width + 'px';
	    break;
	  default:
	    stObj.style.width = varWidth + '%';
	    stObj2.style.width = varWidth + '%';
	    break;
	}
	saveSettings();
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
};

function setUserOptions(){
	if(!prefsLoaded){
		cookie = readCookie("pageWidth");
		currentWidth = cookie ? cookie : defWidth;
		
		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defFontSize;

//		setWidth(currentWidth);
//		setFontSize(currentFontSize);
		prefsLoaded = true;
	}

}

function saveSettings()
{
    createCookie("pageWidth", currentWidth, 365);
    createCookie("fontSize", currentFontSize.toString().substr(0,3), 365);
}

//window.onunload = saveSettings;
