/*global window, localStorage, fontSizeTitle, bigger, reset, smaller, biggerTitle, resetTitle, smallerTitle, Cookie */
var prefsLoaded = false;
var defaultFontSize = 100;
var currentFontSize = defaultFontSize;
var fontSizeTitle;
var bigger;
var smaller;
var reset;
var biggerTitle;
var smallerTitle;
var resetTitle;

/*
Object.append(Browser.Features, {
	localstorage: (function() {
		return ('localStorage' in window) && window.localStorage !== null;
	})()
});
*/

function setFontSize(fontSize)
{
	document.body.style.fontSize = fontSize + '%';
	adjustMenu();
}

function changeFontSize(sizeDifference)
{
	currentFontSize = parseInt(currentFontSize, 10) + parseInt(sizeDifference * 5, 10);
	if (currentFontSize > 130) {
		currentFontSize = 130;
	} else if (currentFontSize < 80) {
		currentFontSize = 80;
	}
	setFontSize(currentFontSize);
}

function revertStyles()
{
	currentFontSize = defaultFontSize;
	changeFontSize(0);
}

function writeFontSize(value)
{
	if (Browser.Features.localstorage) {
		localStorage.fontSize = value;
	} else {
		Cookie.write("fontSize", value, {duration: 180});
	}
}

function readFontSize()
{
	if (Browser.Features.localstorage) {
		return localStorage.fontSize;
	} else {
		return Cookie.read("fontSize");
	}
}

function setUserOptions()
{
	if (!prefsLoaded) {
		var size = readFontSize();
		currentFontSize = size ? size : defaultFontSize;
		setFontSize(currentFontSize);
		prefsLoaded = true;
	}
}

/*
function addControls()
{
	var container = document.id('font-size');
	var content = '<a href="index.php" title="Text größer" onclick="changeFontSize(2); return false;"><img src="images/font-bigger.png" /></a>' +
		 '<a href="index.php" title="Text kleiner" onclick="changeFontSize(-2); return false;"><img src="images/font-smaller.png" /></a>' +
		 '<a href="index.php" title="Standard Text" onclick="revertStyles(); return false;"><img src="images/font-reset.png" /></a>';
	container.set('html', content);
}
*/

function saveSettings()
{
	writeFontSize(currentFontSize);
}

window.addEvent('domready', setUserOptions);
/* window.addEvent('domready', addControls); */
window.addEvent('unload', saveSettings);

