var prefsLoaded = false;
var defaultFontSize = 13;
var currentFontSize = defaultFontSize;

function revertStyles(){

	currentFontSize = defaultFontSize;
	changeFontSize(0);

}

function toggleColors(){
	if(currentStyle == "White"){
		setColor("Black");
	}else{
		setColor("White");
	}
}

function changeFontSize(sizeDifference){
//	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference);
	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('contentwrapper') : document.all('contentwrapper');
	stObj.style.fontSize = fontSize + 'px';
	
};


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;
};

window.onload = init;

function init() {
 setUserOptions(); 
 var qs = location.search.substring(1);
 var nv = qs.split('&');
 var url = new Object();
 for(i = 0; i < nv.length; i++)
 {
  eq = nv[i].indexOf('=');
  url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
 }
 if(document.getElementById(url['par'])) {
  toggle(url['par']);
 } 
 var hlli = "li_" + url['clipid'];
 if(document.getElementById(hlli)) {
  highlight(hlli);
 }
}

function setUserOptions(){
	if(!prefsLoaded){

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defaultFontSize;
		setFontSize(currentFontSize);
		
		prefsLoaded = true;
	}

}

window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
}

function toggle(lyr)
{
 if (document.getElementById)
 {
  var style2 = document.getElementById(lyr).style;
	var icon = document.getElementById("i_" + lyr);
  style2.display = style2.display ? "" :"block";
	if(icon.src == "http://zeitzeugengeschichte.de/images/icons/textincrease.gif") {
	 icon.src = "http://zeitzeugengeschichte.de/images/icons/textdecrease.gif" 
	 } else { 
	 icon.src = "http://zeitzeugengeschichte.de/images/icons/textincrease.gif";
	}  
 }
}

function highlight(hlli) {
 if (document.getElementById)
 {
  var hl = document.getElementById(hlli);
	hl.style.backgroundColor = "#A5CCCC";
	hl.style.color = "#ffffff";
 }
}
