var fontSizeDefault = 70;
var increment = 5;

var bigger = [	'<div id="widget"><span>Schriftgröße anpassen:</span>',		//HTML to go before 'bigger' link
				'<img src="images/main/icon_plus.gif" alt="Schrift größer" title="Schrift vergrößern" width="19" height="19" />',					//HTML to go inside 'bigger' anchor tag
				'Schrift vergrößern',		//title attribute
				'',							//class attribute
				'',							//id attribute
				'',							//name attribute
				'',							//accesskey attribute
				'',							//onmouseover attribute
				'',							//onmouseout attribute
				'',							//onfocus attribute
				''							//HTML to go after 'bigger' link
				]

var reset = [	'',							//HTML to go before 'reset' link
				'<img src="images/main/icon_reset.gif" alt="Schrift zurücksetzen" title="Schrift zurücksetzen" width="19" height="19" />',					//HTML to go inside 'reset' anchor tag
				'Zur ursprünglichen Größe zurücksetzen',	//title attribute
				'',							//class attribute
				'',							//id attribute
				'',							//name attribute
				'',							//accesskey attribute
				'',							//onmouseover attribute
				'',							//onmouseout attribute
				'',							//onfocus attribute
				''							//HTML to go after 'reset' link
				]

var smaller = [	'',							//HTML to go before 'smaller' link
				'<img src="images/main/icon_minus.gif" alt="Schrift kleiner" title="Schrift verkleinern" width="19" height="19" />',					//HTML to go inside 'smaller' anchor tag
				'Schrift verkleinern',		//title attribute
				'',							//class attribute
				'',							//id attribute
				'',							//name attribute
				'',							//accesskey attribute
				'',							//onmouseover attribute
				'',							//onmouseout attribute
				'',							//onfocus attribute
				'</div>'					//HTML to go after 'smaller' link
				]

function Fontsize(increment,bigger,reset,smaller,def) {
	this.w3c = (document.getElementById);
	this.ms = (document.all);
	this.userAgent = navigator.userAgent.toLowerCase();
	this.isOldOp = ((this.userAgent.indexOf('opera') != -1)&&(parseFloat(this.userAgent.substr(this.userAgent.indexOf('opera')+5)) <= 7));
	if ((this.w3c || this.ms) && !this.isOldOp && !this.isMacIE) {
		this.name = "fontSize";
		this.cookieName = 'fontSize';
		this.increment = increment;
		this.def = def;
		this.defPx = Math.round(16*(def/100))
		this.base = 1;
		this.pref = this.getPref();
		this.testHTML = '<div id="fontSizeTest" style="position:absolute;visibility:hidden;line-height:1em;">&nbsp;</div>';
		this.biggerLink = this.getLinkHtml(1,bigger);
		this.resetLink = this.getLinkHtml(0,reset);
		this.smallerLink = this.getLinkHtml(-1,smaller);
	} else {
		this.biggerLink = '';
		this.resetLink = '';
		this.smallerLink = '';
		this.fontSizeInit = new Function('return true;');
	}
	this.allLinks = this.biggerLink + this.resetLink + this.smallerLink;
}

Fontsize.prototype.fontSizeInit = function() {
		document.writeln(this.testHTML);
		this.body = (this.w3c)?document.getElementsByTagName('body')[0].style:document.all.tags('body')[0].style;
		this.fontSizeTest = (this.w3c)?document.getElementById('fontSizeTest'):document.all['fontSizeTest'];
		var h = (this.fontSizeTest.clientHeight)?parseInt(this.fontSizeTest.clientHeight):(this.fontSizeTest.offsetHeight)?parseInt(this.fontSizeTest.offsetHeight):999;
		if (h < this.defPx) this.base = this.defPx/h;
		this.body.fontSize = Math.round(this.pref*this.base) + '%';
}

Fontsize.prototype.getLinkHtml = function(direction,properties) {
	var html = properties[0] + '<a href="#" onclick="fontSize.setSize(' + direction + '); return false;" onkeypress="fontSize.setSize(' + direction + '); return false;"';
	html += (properties[2])?'title="' + properties[2] + '"':'';
	html += (properties[3])?'class="' + properties[3] + '"':'';
	html += (properties[4])?'id="' + properties[4] + '"':'';
	html += (properties[5])?'name="' + properties[5] + '"':'';
	html += (properties[6])?'accesskey="' + properties[6] + '"':'';
	html += (properties[7])?'onmouseover="' + properties[7] + '"':'';
	html += (properties[8])?'onmouseout="' + properties[8] + '"':'';
	html += (properties[9])?'onfocus="' + properties[9] + '"':'';
	return html += '>'+ properties[1] + '<' + '/a>' + properties[10];
}

Fontsize.prototype.getPref = function() {
	var pref = this.getCookie(this.cookieName);
	if (pref) return parseInt(pref);
	else return this.def;
}
Fontsize.prototype.setSize = function(direction) {
	this.pref = (direction)?this.pref+(direction*this.increment):this.def;
	this.setCookie(this.cookieName,this.pref);
	this.body.fontSize = Math.round(this.pref*this.base) + '%';
}

Fontsize.prototype.getCookie = function(cookieName) {
	var cookie = cookieManager.getCookie(cookieName);
	return (cookie)?cookie:false;
}

Fontsize.prototype.setCookie = function(cookieName,cookieValue) {
	return cookieManager.setCookie(cookieName,cookieValue);
}

function Cookiemanager(name,defaultExpiration,expirationUnits,defaultDomain,defaultPath) {
	this.name = name;
	this.defaultExpiration = this.getExpiration(defaultExpiration,expirationUnits);
	this.defaultDomain = (defaultDomain)?defaultDomain:(document.domain.search(/[a-zA-Z]/) == -1)?document.domain:document.domain.substring(document.domain.indexOf('.') + 1,document.domain.length);
	this.defaultPath = (defaultPath)?defaultPath:'/';
	this.cookies = new Object();
	this.expiration = new Object();
	this.domain = new Object();
	this.path = new Object();
	window.onunload = new Function (this.name+'.setDocumentCookies();');
	this.getDocumentCookies();
	}

Cookiemanager.prototype.getExpiration = function(expiration,units) {
	expiration = (expiration)?expiration:7;
	units = (units)?units:'days';
	var date = new Date();
	switch(units) {
		case 'years':
			date.setFullYear(date.getFullYear() + expiration);
			break;
		case 'months':
			date.setMonth(date.getMonth() + expiration);
			break;
		case 'days':
			date.setTime(date.getTime()+(expiration*24*60*60*1000));
			break;
		case 'hours':
			date.setTime(date.getTime()+(expiration*60*60*1000));
			break;
		case 'minutes':
			date.setTime(date.getTime()+(expiration*60*1000));
			break;
		case 'seconds':
			date.setTime(date.getTime()+(expiration*1000));
			break;
		default:
			date.setTime(date.getTime()+expiration);
			break;
		}
	return date.toGMTString();
	}

Cookiemanager.prototype.getDocumentCookies = function() {
	var cookie,pair;
	var cookies = document.cookie.split(';');
	var len = cookies.length;
	for(var i=0;i < len;i++) {
		cookie = cookies[i];
		while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
		pair = cookie.split('=');
		this.cookies[pair[0]] = pair[1];
		}
	}

Cookiemanager.prototype.setDocumentCookies = function() {
	var expires = '';
	var cookies = '';
	var domain = '';
	var path = '';
	for(var name in this.cookies) {
		expires = (this.expiration[name])?this.expiration[name]:this.defaultExpiration;
		path = (this.path[name])?this.path[name]:this.defaultPath;
		domain = (this.domain[name])?this.domain[name]:this.defaultDomain;
		cookies = name + '=' + this.cookies[name] + '; expires=' + expires + '; path=' + path + '; domain=' + domain;
		document.cookie = cookies;
		}
	return true;
	}

Cookiemanager.prototype.getCookie = function(cookieName) {
	var cookie = this.cookies[cookieName]
	return (cookie)?cookie:false;
	}

Cookiemanager.prototype.setCookie = function(cookieName,cookieValue,expiration,expirationUnits,domain,path) {
	this.cookies[cookieName] = cookieValue;
	if (expiration) this.expiration[cookieName] = this.getExpiration(expiration,expirationUnits);
	if (domain) this.domain[cookieName] = domain;
	if (path) this.path[cookieName] = path;
	return true;
	}

var cookieManager = new Cookiemanager('cookieManager',1,'years');

var  fontSize = new Fontsize(increment,bigger,reset,smaller,fontSizeDefault);
