/*------------------------------------------------------------
	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)
	
	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('table','span','div','class','td','tr','a','p');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
//var szs = new Array('70%','85%','100%','140%')
// var startSz = 3;
var startSz = "d";

// global cookie name
var strCookieName = new String("SIZEPREF");
var startSz = GetCookie();

// implement the default
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return true; 
	} else { 
		return false; 
	} 
}

if (!isNaN(startSz)){
	// add the default behaviour
	addEvent(window, 'load', setDefault);

}

// this function just calls the regular one without any fuss, did this so can customize load event later
function setDefault(){
	ts('body',0);
}

function ts( trgt,inc ) {
	// exit if can't get elements by ID
	if (!document.getElementById) return
	// set variables for function
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	// set sz = global start size plus any increase 

	if(isNaN(sz)){
		sz = 1;
	}

	sz += inc;
	// keep size within contraints
	if ( sz < 0 ) sz = 0;
	if ( sz > 3 ) sz = 3;
	// reset start size
	startSz = sz;
	
	// if can't get by elementid, try by tagname, first element
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	// set font size based on array position
	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
	// set a cookie to the array position of the selected size
	SetCookie(sz);
}

/*---------------------------------
	cookie management added by WSD
---------------------------------*/
function GetCookie(){
	// pattern in which to find cookie
	var regExp = new RegExp(strCookieName + "=([^;]*)");
	// execute pattern against available cookies, returning what we need
	var sizePref = regExp.exec(document.cookie);
	// return the contents if present, else set NaN
	sizePref = (sizePref) ? unescape(sizePref[1]) : "b";
	// attempt to convert it to a number
	var defaultSize = Number(sizePref);
	// make sure it converted, if not, don't set it at all
	/*
	if(isNaN(defaultSize)){
		defaultSize = Number.NaN;
	}
	*/
	
	return defaultSize;
}

function SetCookie(intSize){
	if(arguments.length < 1){
		return false;
	}
	// build cookie, we are not using expiration, domain, or secure for this 
	var strCookieString = escape(strCookieName) + "=" + escape(intSize) + "; path=/";

	// set the cookie
	document.cookie = strCookieString;
	return true;
}

