/*------------------------------------------------------------

  Text re-sizer

  Author:	Graham Hobbs, (mouseklix.co.uk) 24/01/2005
  
  Syntax:	ts (target, inc)
  
  where:	target = style name root
			inc    = change in size required (+ or -) in px
  
  Usage:	ts ('.text', -2) would decrease the size of all
			components whose class name begins with 'text'
			(eg. 'text1', 'text50', 'texts') by 2 px.

			This function assumes that the units are px.

			Change minSz and maxSz to set maximum and minimum
			permissible text sizes.

--------------------------------------------------------------*/


function ts (target, inc) {
	
	var st1 = document.styleSheets[0], s1, sn1, n1, i, j;
	// st1  - document stylesheet
	// s1   - current instance of font size (in px)
	// sn1  - numeric part of font size
	// n1   - new font size (as a number)
	// i, j - index variables

	var minSz = 10, maxSz = 20;
	// minSz - minimum permissible size (px)
	// maxSz - maximum permissible size (px)

	for (i=0; i<document.styleSheets.length; i++) {			// include all stylesheets
		for (j=0; j<st1.rules.length; j++)					// text all rules in each stylesheet
		{
			if (st1.rules[j].selectorText.substring(0,target.length) == target && st1.rules[j].style.fontSize)
			{												// match target style and font-size property
				s1 = st1.rules[j].style.fontSize;			// extract old font size
				sn1 = s1.substring(0,s1.lastIndexOf("px"));	// strip off 'px'
				n1 = new Number(sn1) + inc;					// create new size
				if (n1 >= minSz && n1 <= maxSz)
				{
					st1.rules[j].style.fontSize = n1 + "px";	// re-set font-size property
				}
			}
		}
	}
}

