
/*
	efa_increment = percentage by which each click increases/decreases size
	efa_bigger = array of properties for 'increase font size' link
	efa_reset = array of properties for 'reset font size' link
	efa_smaller = array of properties for 'decrease font size' link

	properties array format:
		['before HTML',
		 'inside HTML',
		 'title text',
		 'class text',
		 'id text',
		 'name text',
		 'accesskey text',
		 'onmouseover JavaScript',
		 'onmouseout JavaScript',
		 'on focus JavaScript',
		 'after HTML'
		 ]
*/

var efa_default = 70;											//default text size as percentage of user default
var efa_increment = 11;											//percentage to increase/decrease font size

var efa_bigger = ['',		//HTML to go before 'bigger' link
			'<span style="font-size:14px">A</span>',				//HTML to go inside 'bigger' anchor tag
			'Schrift gr&ouml;sser stellen',				//title attribute
			'efa',											//class attribute
			'',											//id attribute
			'',											//name attribute
			'',											//accesskey attribute
			'',											//onmouseover attribute
			'',											//onmouseout attribute
			'',											//onfocus attribute
			'',											//HTML to go after 'bigger' link
			'text-decoration:none;'
			]

var efa_reset = [' • ',
			'<span style="font-size:12px">A</span>',				//HTML to go before 'reset' link
			'Schriftgr&ouml;&szlig;e normal',	//HTML to go inside 'reset' anchor tag
			'efa',		//class attribute
			'',		//id attribute
			'',		//name attribute
			'',		//accesskey attribute
			'',		//onmouseover attribute
			'',		//onmouseout attribute
			'',		//onfocus attribute
			' • ',		//HTML to go after 'reset' link
			'text-decoration:none;'
			]

var efa_smaller = ['',
			'<span style="font-size:10px">A</span>',				//HTML to go before 'smaller' link
			'Schrift kleiner stellen',							//HTML to go inside 'smaller' anchor tag
			'efa',		//class attribute
			'',		//id attribute
			'',		//name attribute
			'',		//accesskey attribute
			'',		//onmouseover attribute
			'',		//onmouseout attribute
			'',		//onfocus attribute
			'',		//HTML to go after 'smaller' link
			'text-decoration:none;'
			]

function Efa_Fontsize(increment,bigger,reset,smaller,def) {
	// check for the W3C DOM
	this.w3c = (document.getElementById);
	// check for the MS DOM
	this.ms = (document.all);
	// get the userAgent string and normalize case
	this.userAgent = navigator.userAgent.toLowerCase();
	// check for Opera and that the version is 7 or higher; note that because of Opera's spoofing we need to
	// resort to some fancy string trickery to extract the version from the userAgent string rather than
	// just using appVersion
	this.isOldOp = ((this.userAgent.indexOf('opera') != -1)&&(parseFloat(this.userAgent.substr(this.userAgent.indexOf('opera')+5)) <= 7));
	// check for Mac IE; this has been commented out because there is a simple fix for Mac IE's 'no resizing
	// text in table cells' bug--namely, make sure there is at least one tag (a <p>, <span>, <div>, whatever)
	// containing any content in the table cell; that is, use <td><p>text</p></td> or <th><span>text</span></th>
	// instead of <td>text</td> or <th>text</th>; if you'd prefer not to use the workaround, then uncomment
	// the following line:
	// this.isMacIE = ((this.userAgent.indexOf('msie') != -1) && (this.userAgent.indexOf('mac') != -1) && (this.userAgent.indexOf('opera') == -1));
	// check whether the W3C DOM or the MS DOM is present and that the browser isn't Mac IE (if above line is
	// uncommented) or an old version of Opera
	if ((this.w3c || this.ms) && !this.isOldOp && !this.isMacIE) {
		// set the name of the function so we can create event handlers later
		this.name = "efa_fontSize";
		// set the cookie name to get/save preferences
		this.cookieName = 'efaSize';
		// set the increment value to the appropriate parameter
		this.increment = increment;
		//default text size as percentage of user default
		this.def = def;
		//intended default text size in pixels as a percentage of the assumed 16px
		this.defPx = Math.round(16*(def/100))
		//base multiplier to correct for small user defaults
		this.base = 1;
		// call the getPrefs function to get preferences saved as a cookie, if any
		this.pref = this.getPref();
		// stuff the HTML for the test <div> into the testHTML property
		this.testHTML = '<div id="efaTest" style="position:absolute;visibility:hidden;line-height:1em;">&nbsp;</div>';
		// get the HTML for the 'bigger' link
		this.biggerLink = this.getLinkHtml(1,bigger);
		// get the HTML for the 'reset' link
		this.resetLink = this.getLinkHtml(0,reset);
		// get the HTML for the 'smaller' link
		this.smallerLink = this.getLinkHtml(-1,smaller);
		// set up an onlunload handler to save the user's font size preferences
	} else {
		// set the link html properties to an empty string so the links don't show up
		// in unsupported browsers
		this.smallerLink = '';
		this.resetLink = '';
		this.biggerLink = '';
		// set the efaInit method to a function that only returns true so
		//we don't get errors in unsupported browsers
		this.efaInit = new Function('return true;');
	}
	// concatenate the individual links into a single property to write all the HTML
	// for them in one shot
	this.allLinks = this.smallerLink + this.resetLink + this.biggerLink ;
}

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

Efa_Fontsize.prototype.getLinkHtml = function(direction,properties) {
	var html = properties[0] + '<a href="#" onclick="efa_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] + '"' : '';
	html += (properties[11]) ? 'style="' + properties[11] + '"' : '';
	return html += '>'+ properties[1] + '</a>' + properties[10];
}

Efa_Fontsize.prototype.getPref = function() {
	var pref = this.getCookie(this.cookieName);
	if (pref) return parseInt(pref);
	else return this.def;
}

Efa_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) + '%';
}

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

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

var  efa_fontSize = new Efa_Fontsize(efa_increment,efa_bigger,efa_reset,efa_smaller,efa_default);

