/***
	* FontSwitcher v0.1
	* Copyright (c) 2007 Pavol Biely
	* http://pabi3.com/
	*
	* This program is free software; you can redistribute it and/or
	* modify it under the terms of the GNU General Public License
	* as published by the Free Software Foundation; either version 2
	* of the License, or (at your option) any later version.
	*
	* This program is distributed in the hope that it will be useful,
	* but WITHOUT ANY WARRANTY; without even the implied warranty of
	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	* GNU General Public License for more details.
	*
	* You should have received a copy of the GNU General Public License
	* along with this program; if not, write to the Free Software
	* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/

// jednotka, v ktorej sa mĂˇ meniĹĄ veÄľkosĹĄ pĂ­sma
var unit    = 'px';

// aktuĂˇlna veÄľkosĹĄ pĂ­sma, od ktorej sa zaÄŤne odÄŤĂ­tavaĹĄ alebo priÄŤĂ­tavaĹĄ
var size    = 16;

// implicitnĂˇ veÄľkosĹĄ pĂ­sma
var defsize = 16;

// aktuĂˇlne pouĹľitĂ© pĂ­smo
var font    = 'Times New Roman';

// implicitne pouĹľitĂ© pĂ­smo
var deffont = 'Times New Roman';

// elementy, v ktorĂ˝ch sa mĂˇ meniĹĄ typ pĂ­sma a jeho veÄľkosĹĄ
var element = document.getElementsByTagName('p');

// prefix pre cookies; prvĂˇ cookie sa volĂˇ -family, druhĂˇ -size
var cookiename = 'font';

// doba platnosti cookies v dĹ�och
var cookiedays = 1;

// udalosĹĄ onload; po naÄŤĂ­tanĂ­ strĂˇnky sa vykonĂˇ JS kĂłd
// copyright (c) Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
addLoadEvent(setFontFromCookies);

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if(typeof window.onload != 'function')
	{
	  window.onload = func;
	} else {
	  window.onload = function()
		{
	    oldonload();
	    func();
	  }
	}
}

// odoĹˇle cookie
// http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = '; expires=' + date.toGMTString();
	}
	else var expires = '';
	document.cookie = name+'='+value+expires+'; path=/';
}

// preÄŤĂ­ta cookie
// http://www.quirksmode.org/js/cookies.html
function readCookie(name)
{
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// nastavĂ­ pĂ­smo a jeho veÄľkosĹĄ + odoĹˇle cookies
function setFont()
{
	if(!(document.getElementById || document.all || document.layers)) return;

	createCookie(cookiename + '-family',font,cookiedays);
	createCookie(cookiename + '-size',size,cookiedays);

	for(var i = 0; i < element.length; i++)
	{
		element[i].style.fontFamily = font;
		element[i].style.fontSize   = size + unit;
	}
}

// obnovĂ­ pĂ´vodnĂ© pĂ­smo a jeho veÄľkosĹĄ + zruĹˇĂ­ cookies
function setFontDefault()
{
	createCookie(cookiename + '-family','',-1);
	createCookie(cookiename + '-size','',-1);

	font = deffont;
	size = defsize;

	setFont();
}

// nastavĂ­ typ pĂ­sma
function setFontFamily(param)
{
	font = param;
	setFont();
}

// nastavĂ­ veÄľkosĹĄ pĂ­sma
function setFontSize(param)
{
	if(param == 0) size = defsize;
	else size = parseInt(size)+parseInt(param);
	setFont();
}

// nastavĂ­ typ pĂ­sma a jeho veÄľkosĹĄ za pomoci cookies
function setFontFromCookies()
{
	var tmp_font = readCookie(cookiename + '-family');
	var tmp_size = readCookie(cookiename + '-size');

	if(tmp_font != null) font = tmp_font;
	if(tmp_size != null) size = tmp_size;

	setFont();
}