// 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 18276 2011-07-18 13:37:14Z mfischer $
 */

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;
				}
			} // }}}
		} // }}}
	}, // }}}
	getPageSize : function (){ // {{{

		// getPageSize()
		// by Lokesh Dhakar - http://www.huddletogether.com
		// Returns array with page width, height and window width, height
		// Core code from - quirksmode.org
		// Edit for Firefox by pHaez
		//
		
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}


		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
		
	} // }}}
} // }}}

