/**
 * Copyright (C) 2007, ..... All rights reserved.
 *
 * THIS SOURCE CODE MAY BE USED FREELY PROVIDED THAT
 * IT IS NOT MODIFIED OR DISTRIBUTED, AND IT IS USED
 * ON A PUBLICLY ACCESSIBLE INTERNET WEB SITE.
 * 
 * .... JavaScript Module: Font size handling class
 *
 * Feel free to use this script. Because it is licensed free of charge, 
 * there is NO WARRANTY, it is provided AS IS. The author can not be held 
 * liable for any damage that might arise from the use of this software. 
 * Use it at your own risk.
 */

function UNI_Fontsize()
{
	// Expire date for fontsize cookie, in min 
	this.font_size_cookie_exp = 60 * 24 * 365;
	// default font size in %, if nothing set 
	this.font_size_default = 100;
	// maximum font-size in %, 0 = unlimited 
	this.font_size_max = 144;
	// minimum font-size in %, 0 = unlimited 
	this.font_size_min = 72;
	// steps for chnaging font size in %  
	this.font_size_step = 6;
	// current font size 
	this.font_size_curr;
	// original font size 
	this.font_size_orig;
	// font size cookie 
	this.font_size_cookie;
	
	/**
	* Init font size for the whole document,
	* read it from cookie, if there's no cookie,
	* set it to default
	*/
	this.init = function ()
	{
		this.font_size_cookie = new CJL_CookieUtil('font_size_cookie', this.font_size_cookie_exp, '/');
		this.font_size_curr = this.font_size_cookie.getSubValue('font_size_curr') * 1;
		this.font_size_orig = this.font_size_cookie.getSubValue('font_size_orig') * 1;
		if (!this.font_size_curr)
		{
			this.font_size_curr = this.font_size_default;
		}
		if (!this.font_size_orig)
		{
			this.font_size_orig = this.font_size_default;
		}
		document.body.style.fontSize = this.font_size_curr + "%";
		this.font_size_cookie.setSubValue('font_size_curr', this.font_size_curr);
		this.font_size_cookie.setSubValue('font_size_orig', this.font_size_orig);
	}
	
	/* Reset font size to original value, get it from cookie or default */
	this.reset = function ()
	{
		this.font_size_curr = this.font_size_orig;
		document.body.style.fontSize = this.font_size_curr + "%";
		this.font_size_cookie.setSubValue('font_size_curr', this.font_size_curr);
		return void(0);
	}
	
	/* Increase font size in steps to maximum value */
	this.increase = function ()
	{
		var font_size_tmp = this.font_size_curr + this.font_size_step;
		if (!this.font_size_max || (this.font_size_max && (font_size_tmp <= this.font_size_max)))
		{
			this.font_size_curr = font_size_tmp;
			document.body.style.fontSize = this.font_size_curr + "%";
			this.font_size_cookie.setSubValue('font_size_curr', this.font_size_curr);
		}
		return void(0);
	}
	
	/* Increase font size in steps to minimum value */
	this.decrease = function ()
	{
		var font_size_tmp = this.font_size_curr - this.font_size_step;
		if (!this.font_size_min || (this.font_size_min && (font_size_tmp >= this.font_size_min)))
		{
			this.font_size_curr = font_size_tmp;
			document.body.style.fontSize = this.font_size_curr + "%";
			this.font_size_cookie.setSubValue('font_size_curr', this.font_size_curr);
		}
		return void(0);
	}
}

fs = new UNI_Fontsize();