// Modified from Bill Dortch's Cookie Functions (hidaho.com) 
// (found in JavaScript Bible)
function setCookie(name,value,days,path,domain,secure) {
  var expires, date;
  if (typeof days == "number") {
    date = new Date();
    date.setTime( date.getTime() + (days*60*60*24*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

// Modified from Jesse Chisholm or Scott Andrew Lepera ?
// (found at both www.dansteinman.com/dynapi/ and www.scottandrew.com/junkyard/js/)
function getCookie(name) {
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

// from Bill Dortch's Cookie Functions (hidaho.com) 
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

var cssRules = false;
var maxSize=7;
var minSize=-2;
var aktSize=0;

function setSize(int){
	aktSize+=int;

	if(aktSize>maxSize){
		aktSize=maxSize;
		return;
	}
	if(aktSize<minSize){
		aktSize=minSize;
		return;
	}

	if(aktSize==0) deleteCookie("fontSize","/");
	else setCookie("fontSize",aktSize,180, "/");

	if(!cssRules){
		cssRules=new Array();
		if (document.styleSheets[0].cssRules)
			cssRules = document.styleSheets[0].cssRules;
		else if (document.styleSheets[0].rules)
			cssRules = document.styleSheets[0].rules;
		else cssRules=false;
	}

	if(cssRules && cssRules.length>0){
		for(var i=0;i<cssRules.length;i++){
			if(cssRules[i].style.fontSize){
				var pos=cssRules[i].style.fontSize.indexOf('pt');
				if(pos>0){
					var size=Number(cssRules[i].style.fontSize.substr(0,pos))+int;
					cssRules[i].style.fontSize=size+'pt';
				}
			}
		}
	}
}

function initCSS() {
    if ( !document.body || !document.getElementById ) return;
    var size = Number(getCookie("fontSize"));
	if(size!=0 && !isNaN(size)) setSize(size);
}
