// vim: set fdm=marker encoding=utf-8 :

/**
 * NSF
 *
 * LICENSE
 *
 * Dr. Maté GmbH License ?
 *
 * @category	Nsf
 * @package		Nsf.Utils
 * @copyright	(c) 2007 by Dr. Maté GmbH
 * @license		http://www.netdoktor.at/license/
 * @author		Thomas Subera <thomas.subera@gmail.com>
 * @version		$Id: nsf.utils.js 8790 2009-03-09 10:47:38Z soestreicher $
 */

if (!window.nsf) {
	nsf = {
	}
}

/**
 * nsf Utils Class
 */
nsf.Utils = { // {{{
	/*
	 * Font Size Changer
	 * Package everything related to changing the font size together
	 */
	FontSizeChanger : { // {{{
		/**
		 * WARNING: This is the simple version which directly changes the
		 * fontSize of the body-Element.  This version doesn't support setting
		 * a custom CSS class on e.g. the body Element.
		 *
		 * How to use:
		 * * connect nsf.Utils.FontSizeChanger.Simple.eventSmaller
		 * * connect nsf.Utils.FontSizeChanger.Simple.eventBigger
		 * * include a call to nsf.Utils.FontSizeChanger.Simple.applyCookieFontsize right after the opening of the body Element
		 */
		Simple : { // {{{
			iCurrentValuePos : 1,
			sValueUnit : '%',
			aFontSizeValues : [60, 70, 80, 100],
			/**
			 * Call this function from the element which triggers scaling the font down.
			 */
			eventSmaller : function() { // {{{
				nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos--;
				if (nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos < 0) {
					nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos = 0;
					return false;
				}
				document.getElementsByTagName('body')[0].style.fontSize = nsf.Utils.FontSizeChanger.Simple.aFontSizeValues[ nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos ] + nsf.Utils.FontSizeChanger.Simple.sValueUnit;
				nsf.cookie.set('fontsize', nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos, 30, '/');
				return false;
			}, // }}}
			/**
			 * Call this function from the element which triggers scaling the font up.
			 */
			eventBigger : function() { // {{{
				nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos++;
				if (nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos >= nsf.Utils.FontSizeChanger.Simple.aFontSizeValues.length) {
					nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos = nsf.Utils.FontSizeChanger.Simple.aFontSizeValues.length - 1;
					return false;
				}
				document.getElementsByTagName('body')[0].style.fontSize = nsf.Utils.FontSizeChanger.Simple.aFontSizeValues[ nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos ] + nsf.Utils.FontSizeChanger.Simple.sValueUnit;
				nsf.cookie.set('fontsize', nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos, 30, '/');
				return false;
			}, // }}}
			/**
			 * Call this function as soon as the body-Element has been parsed,
			 * e.g. right after the opening body Element.
			 */
			applyCookieFontsize : function() { // {{{
				// get cookie value
				var pos = nsf.cookie.get('fontsize');
				if (pos == null) {
					return;
				}
				if (pos >= 0 && pos < nsf.Utils.FontSizeChanger.Simple.aFontSizeValues.length) {
					nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos = pos;
					// if not present, use default
					document.getElementsByTagName('body')[0].style.fontSize = nsf.Utils.FontSizeChanger.Simple.aFontSizeValues[ nsf.Utils.FontSizeChanger.Simple.iCurrentValuePos ] + nsf.Utils.FontSizeChanger.Simple.sValueUnit;
				}
			} // }}}
		} // }}}
	} // }}}
} // }}}
