/*------------------------------------------------------------
	Document Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
	Coded by: Taewook Kang (txkang.REMOVETHIS@hotmail.com)
	Web Site: http://txkang.com
	Script featured on Dynamic Drive (http://www.dynamicdrive.com)
	Modified by: Ásbjörn H Kristbjörnsson
	
	Please retain this copyright notice in the script.
	License is granted to user to reuse this code on 
	their own website if, and only if, 
	this entire copyright notice is included.
--------------------------------------------------------------*/

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td', 'span');

//Specify spectrum of different font sizes:
var szs = new Array( "xsmall","small","default","big","xbig","xxbig" );
var startSz = 2;


function changeStyle(inc) 
{
  var sz = startSz;
	
  if (inc == 0)
    sz = 2;
  else
  {
    sz += inc;
    if ( sz < 0 ) 
      sz = 0;
    if ( sz > 5 ) 
      sz = 5;
  }
	
  startSz = sz;
  
  setActiveStyleSheet(szs[sz]);
  setCookie("sjalfsbjorgSize",sz);	
}

function setActiveStyleSheet(title) 
{
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title)
      {
      	a.disabled = false;
      }
    }
  }
}


function loadSize()
{
	var cookieSize = getCookie("sjalfsbjorgSize");
	//alert(cookieSize);
	if ((cookieSize != null) && (cookieSize != ''))
	{
		changeStyle(parseInt(cookieSize) - 2);
	}
}


function setCookie(cookieName,cookieValue) 
{
	var today = new Date(), expires = new Date();
	// Gildir í 2 ár
	expires.setTime(today.getTime() + 3600000*24*730);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires="+expires.toGMTString() + ";path=/";
}

function getCookie(cookieName) 
{
	var cookie = document.cookie;
	var cookieStart = cookie.indexOf(cookieName + "=");
	var cookieEnd;
	
	if (cookieStart == -1) 
		return null;
		
	cookieStart = cookie.indexOf("=", cookieStart) + 1;
	cookieEnd = cookie.indexOf(";", cookieStart);
	
	if (cookieEnd == -1) 
		cookieEnd = cookie.length;
	
	return unescape(cookie.substring(cookieStart, cookieEnd));
}

