/*

	filename:	/js/changeFontsize.js
	version:	1.1 - 2007-03-01 - mkr

	author:		martin (dot) krause (at) gpm (dot) de 

	changes fontsize,
	fontsize.change([element1,element2],direction)
	dependencies: cookie();
	
	1.1 - mkr: fixed calculation bug at change()
	
*/

if (!fontsize) { 
	function fontsize () {
		if (!self) { this.self = this;}
		self._minFs = 85;
		self._defFs = 100;
		self._maxFs = 165;
		self._step = 5;
		this.cookie = 'merzfs';
	}; 
}

/*!
@function fontsize.init([id...])
@param array with elements or id whose sizes should be adjusted
@abstract sets fontsize on page load
	depends on : cookie.getCookie()
*/
fontsize.prototype.init = function() {
	var _fs = cookie.getCookie(fontsize.cookie) || self._defFs;
	fontsize.setSize(arguments[0],_fs);
}

/*!
@function fontsize.change([id...],direction)
@param array with elements or id whose sizes should be adjusted and the direction (-1|0|+1), saves new fontsize inside specified cookie
@abstract calculates fontsize changes
	depends on : cookie.setCookie()
*/
fontsize.prototype.change = function() {
		var _fs = cookie.getCookie(fontsize.cookie) || self._defFs;
		var _d = arguments[1];

		if (isNaN(_fs) || _d == '0') { _fs = self._defFs;}
		if ( (_fs <= self._minFs) ) { _fs = self._minFs}
		if ( (_fs >= self._maxFs) ) { _fs = self._maxFs}
		
		_fs = (parseInt(_d) < 0) ? (parseInt(_fs)-self._step) : ( (parseInt(_d) > 0) ? (parseInt(_fs)+self._step) : parseInt(_fs) );

		cookie.setCookie(fontsize.cookie,_fs,'360');
		fontsize.setSize(arguments[0],_fs)
}

/*!
@function fontsize.setSize([id...],direction)
@param array with elements or id whose sizes should be adjusted and the fontsize 
@abstract set fontsize
*/
fontsize.prototype.setSize = function() {
		var _n = arguments[0].length;
		var _fs = arguments[1];
		while (_n --)
		{
			var _el = (typeof(arguments[0][_n]) == 'string') ? document.getElementById(arguments[0][_n]) : arguments[0][_n];
//			var _el = document.getElementById(arguments[0][_n]);
			_el.style.fontSize = _fs+'%';
		}
}

var fontsize = new fontsize();