/*------------------------------------------------------------
	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( 'font', 'label' );

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 3;

var __TS_COOKIE_NAME = "__TEXT_SIZE";

function ts( trgt,inc ) {
	var sz = startSz;
	
	sz += inc;

	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
		
	setTS( trgt, sz );
}

function setTS( trgt, idx )
{
	if (!document.getElementById) return
	
	var d = document,
		cEl = null,
		i,
		j,
		cTags;
		
	startSz = idx;

	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ idx ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ idx ];
	}
	
	// Store current size in a cookie
	setStoredTS( idx );
}

function loadStoredTS( trgt )
{
	var previousSizeIdx = getStoredTS();
	if( previousSizeIdx >= 0 )
	{
		setTS( trgt, previousSizeIdx );
	}
}

function getStoredTS()
{
	if( typeof(jQuery) != "undefined" )
	{
		var result = parseInt( jQuery.cookie( __TS_COOKIE_NAME ) );
		if( !isNaN( result ) )
			return result;
	}
	
	return -1;
}

function setStoredTS( idx )
{
	if( typeof(jQuery) != "undefined" )
	{
		// Cookie expires in 10 years (365 days/year * 10 years)
		jQuery.cookie( __TS_COOKIE_NAME, idx, { expires: 3650, path: "/" } );
	}
}
