addLoadEvent(function() {
	if (document.getElementById) {
		textSize();
//		firstletter();
	}
});

// Simon Willison
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// creates a cookie with the given parameters
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 {
		var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

// locates and reads the value of a cookie with a specified name
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;
}

// deletes a cookie with a specified name
function eraseCookie(name){
	createCookie(name,"",-1);
}

// text resizing
var currentTextSize = null;
var currentLineHeight = null;

// check for cookie
if (get_text_cookie('fontsize')) {
    currentTextSize = Math.round(get_text_cookie('fontsize') * 10) / 10;
    currentLineHeight = 1 + (0.35 + ((currentTextSize -1) / 10));
} else {
    currentTextSize = 1;
    createCookie('fontsize',currentTextSize,1000);
}

function textSize(dir) {
    if (dir == 'up') {
        if (currentTextSize <= 1.4) {
            currentTextSize += 0.2;
        }
    } else if (dir == 'down') {
        if (currentTextSize >= 1) {
            currentTextSize -= 0.2;
        }
    }

    currentLineHeight = 1 + (0.35 + ((currentTextSize -1) / 10));
    document.getElementById('content').style.fontSize = currentTextSize + 'em';
    document.getElementById('content').style.lineHeight = currentLineHeight + 'em';
    
    // write/rewrite cookie
    createCookie('fontsize',currentTextSize,1000);
}

function get_text_cookie (cookie_name) {
  var results = document.cookie.match (cookie_name + '=(.*?)(;|$)');
  if (results) {
    return (unescape (results[1]));
  }
  else {
  	return null;
  }
}