var prefsLoaded = false;
var currentFontSize = 13;
var currentFontType = 1;
var currentWidth = 1200;

setUserOptions();

function setUserOptions(){
	if(!prefsLoaded){
		
		currentWidth = 1200;
		setWidth(currentWidth);
		
		cookie = readCookie("fontFace");
		currentFontType = cookie ? cookie : 1;
		setFontFace(currentFontType);

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : 13;
		setFontSize(currentFontSize);
		
		prefsLoaded = true;
	}
};

function revertStyles(){
	currentFontType = 1;
	setFontFace(1);
	
	currentFontSize = 13;
	changeFontSize(0);
	
	currentWidth = 1200;
	setWidth(1200);
};

function toggleWidth(){
	setWidth(1200);
	currentWidth = 1200;
};

function setWidth(width){
	var website = document.getElementById('outer');
	var content = document.getElementById('centrecontent');
	website.style.width = '1015px';
	content.style.width = '81%';	
};

function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference);

	if(currentFontType == 1){
		if(currentFontSize > 20){
			currentFontSize = 20;
		}else if(currentFontSize < 8){
			currentFontSize = 8;
		}
	}else{
		if(currentFontSize > 22){
			currentFontSize = 22;
		}else if(currentFontSize < 8){
			currentFontSize = 8;
		}
	}
	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
	var font =  document.getElementById('outer');
	var font2 = document.getElementById('listMenuWrapper');
	font.style.fontSize = fontSize + 'px';
	font2.style.fontSize = fontSize - 1 + 'px';
};

function toggleSerif(){
	currentFontType = parseInt(currentFontType);
	if(currentFontType == 1){
		currentFontType = 2;
	}else{
		currentFontType = 1;
	}
	setFontFace(currentFontType);
};

function setFontFace(fontType){
	if(fontType == 2){
		document.getElementById('outer').style.fontFamily = 'Cambria, times new roman, times, georgia, serif';
		changeFontSize(1);
	}
	else{
		document.getElementById('outer').style.fontFamily = 'Candara, Verdana, Arial, Helvetica, sans-serif';
		changeFontSize(-1);
	}
};

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+"movie="+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;
};

window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
  createCookie("fontFace", currentFontType, 365);
  createCookie("pageWidth", currentWidth, 365);
};