/* Text changer - light version.
Let your text's font size customizable.
by Marco Rosella - http://www.centralscrutinizer.it/en/design/js-php/text-changer
                v0.2 - May 18, 2006
*/

window.onload = function(){
	textChanger.init();
}

var textChanger = {
	cpanel : 'textchanger',  //set here the id of the element (div, p) within you want to insert the control panel
	element : 'page-holder',   	 //set here the id of the element (div, p) within you want to change the text
	defaultFS : 1,         //set here the default font size in 'em'
	init: function() {
		var cpel = document.getElementById(textChanger.cpanel);
		var el = document.getElementById(textChanger.element);
		if (cpel == null || el == null) {
            //alert('The elements with the \"'+textChanger.cpanel+'\" and/or \"'+textChanger.element+'\" ID do not exist in HTML source.');
        } else {
		var u = document.createElement('ul');
		cpel.appendChild(u);
		u.innerHTML =
		'<li id="decrease"><a href="#" title="Schrift verkleinern" alt="Schrift verkleinern"><img src="/images/btn-decrease.gif" title="Schrift verkleinern" alt="Schrift verkleinern" /></a></li>'+
		'<li id="reset"><a href="#" title="Standard Schriftgröße" alt="Standard Schriftgröße"><img src="/images/btn-reset.gif" title="Standard Schriftgröße" alt="Standard Schriftgröße" /></a></li>'+
		'<li id="increase"><a href="#" title="Schrift vergrößern" alt="Schrift vergrößern"><img src="/images/btn-increase.gif" title="Schrift vergrößern" alt="Schrift vergrößern" /></a></li>'
		var sz = textChanger.getCookie();
		el.style.fontSize = sz ? sz + 'em' : textChanger.defaultFS + 'em';
		var incr = document.getElementById('increase');
		incr.onclick = function(){textChanger.changeSize(1); return false;};
		var decr = document.getElementById('decrease');
		decr.onclick = function(){textChanger.changeSize(-1); return false;};
		var reset= document.getElementById('reset');
		reset.onclick = function(){textChanger.changeSize(0); return false;};
		}
	} ,

	changeSize: function(val) {
		var el = document.getElementById(textChanger.element);

		var size = el.style.fontSize.substring(0,3);
		var fSize = parseFloat(size,10);
		if (val == 1) {
			fSize += 0.11;
			if (fSize > 1.2) fSize = 1.2;
			if(fSize > 1){
				$j('div.nav-drop').css('top', '2.366em');
			}
		}
		if (val == -1) {
			fSize -= 0.11;
			if (fSize < 0.9) fSize = 0.9;
			$j('div.nav-drop').css('top', '2.766em');
		}
		if (val == 0) {
			fSize = textChanger.defaultFS;
			$j('div.nav-drop').css('top', '2.666em');
		}
		el.style.fontSize = fSize + 'em';
		textChanger.updateCookie(fSize);
		} ,

	updateCookie: function(vl) {
		var today = new Date();
		var exp = new Date(today.getTime() + (365*24*60*60*1000)); //the cookie will expire in one year
		document.cookie = 'textChangerL=size=' + vl + ';' +'expires=' + exp.toGMTString() + ';' +'path=/';
	} ,

	getCookie: function() {
		var cname = 'textChangerL=size=';
		var start = document.cookie.indexOf(cname);
		var len = start + cname.length;
		if ((!start) && (cname != document.cookie.substring(0,cname.length))) {return null;}
		if (start == -1) return null;
		var end = document.cookie.indexOf(";",len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	}
}
