var g_PrefsLoaded = false;
var g_DefaultFontSize = 100;
var g_CurrentFontSize = g_DefaultFontSize;


function revertStyles()
{
	g_CurrentFontSize = g_DefaultFontSize;
	changeFontSize(0);
	g_CurrentColorScheme = g_DefaultColorScheme;
	setColorScheme(0);
}


function changeFontSize (_sizeDifference)
{
	g_CurrentFontSize = parseInt(g_CurrentFontSize) + parseInt(_sizeDifference * 5);

	if (g_CurrentFontSize > 220)
	{
		g_CurrentFontSize = 220;
	}
	else if (g_CurrentFontSize < 60)
	{
		g_CurrentFontSize = 60;
	}

	setFontSize(g_CurrentFontSize);
}


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

	// Fix for IE6: Set additional styles
	if (node = document.getElementById('page')) node.style.fontSize = _fontSize + '%';
	//if (document.getElementById('infobox_text')) document.getElementById('infobox_text').style.fontSize = _fontSize + '%';

	//alert (document.body.style.fontSize);
}

function setColorScheme (_color)
{
	if (_color != g_CurrentColorScheme)
	{
		g_CurrentColorScheme = _color;

		// Force reload to apply new settings
		self.location.reload();
		
		return false;
	}


	// Array with all image id's which have to be exchanged (image file names see ImageURI)
	var ImageID
		=	Array(
					'imgid_logo', 'imgid_logo_regio', 'imgid_sm', 'imgid_lg', 'imgid_ctdown', 'imgid_ctup',
					'imgid_up', 'imgid_back' 
			);

	// Array with all filenames for the images to exchange (corresponding to ImageID)
	var ImageURI
		=	Array(
					'logo', 'logo_regionalagenturen_nrw', 'bt_smaler', 'bt_lager', 'bt_contrastdown', 'bt_contrastup',
					'bt_oben', 'bt_zurueck'
			);

	if (_color == 1)
	{
		imgPath = '/httpdocs/templates/ra_el/images/negativ/';
		imgSuffix = '_black.gif';
	}
	else
	{
		imgPath = '/httpdocs/templates/ra_el/images/';
		imgSuffix = '.gif';
	}

	// ---------- Images ----------

	// Replace all images
	for (i=0; i < ImageID.length; ++i)
	{
		imgNode = window.document.images[ImageID[i]];
		if (imgNode) imgNode.src = imgPath + ImageURI[i] + imgSuffix;
	}

	return true;

}	// function setColorScheme (_color)


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 setUserOptions()
{
	if (! g_PrefsLoaded)
	{
		cookie = readCookie("fontSize");
		g_CurrentFontSize = cookie ? cookie : g_DefaultFontSize;
		setFontSize(g_CurrentFontSize);

		cookie = readCookie("colorScheme");
		g_CurrentColorScheme = cookie ? cookie : g_DefaultColorScheme;
		setColorScheme(g_CurrentColorScheme);

		g_PrefsLoaded = true;
	}
}


function saveSettings()
{
	createCookie("fontSize", g_CurrentFontSize, 365);
	createCookie("colorScheme", g_CurrentColorScheme, 365);
}


window.onload = setUserOptions;
window.onunload = saveSettings;

