

if (document.getElementById) { 

	

	//
	ff = readCookie('fontFamily');
	if (ff=='times') ff=' times';

	// read the cookie to get the proper font size, set to default 12 if a first timer
	fs = parseInt(readCookie('fontSize'));
	if (!fs>0) fs=17;

	// set the appropriate font sizes for the relevant HTML elements
	// any other elements that you want to have a changeable font size must be added to this list
	// in the form "element_fs" and then also added to the setSizes and changeType functions
	var body_fs, table_fs, div_fs,  small_fs, h1_fs, h2_fs, h3_fs, h4_fs, h5_fs, h6_fs;
	
	setSizes();

	// lets write out styles with the changeable values that we get from the cookies
	// and the random rgb values. This will make the page display
	document.writeln('<style>');
	document.writeln('body{font-size:'+body_fs+'px;}');
	document.writeln('body{font-family:'+ff+';}');
	document.writeln('table{font-size:'+table_fs+'px;}');
	document.writeln('div{font-size:'+div_fs+'px;}');
	document.writeln('small{font-size:'+small_fs+'px;}');
	document.writeln('h1{font-size:'+h1_fs+'px;}');
	document.writeln('h2{font-size:'+h2_fs+'px;}');
	document.writeln('h3{font-size:'+h3_fs+'px;}');
	document.writeln('h4{font-size:'+h4_fs+'px;}');
	document.writeln('h5{font-size:'+h5_fs+'px;}');
	document.writeln('h6{font-size:'+h6_fs+'px;}');

	document.writeln('<\/style>');
	}


	
// this changes the sizes of the various elements relative to the fs
function setSizes() {
	body_fs = fs
	table_fs = fs;
	div_fs = fs;
	small_fs = fs;
	h1_fs = body_fs+6;
	h2_fs = body_fs+5;
	h3_fs = body_fs+4;
	h4_fs = body_fs+3;
	h5_fs = body_fs+2;
	h6_fs = body_fs+1;
	}

function changeType() {
	if (!document.getElementsByTagName) {return false;} // unclean! unclean!
	// because NS6 seems to freak out on abs. positionined divs
	// when you change a style property of the body, we have to
	// set the fontFamily and fontSize on div elements and not the body
	setStyleByTag('table','fontFamily',ff);
	setStyleByTag('table','fontSize',table_fs+'px');			setStyleByTag('div','fontSize',div_fs+'px');
	setStyleByTag('div','fontFamily',ff);
	setStyleByTag('h1','fontSize',h1_fs+'px');
	setStyleByTag('h2','fontSize',h2_fs+'px');
	setStyleByTag('h3','fontSize',h3_fs+'px');
	setStyleByTag('h4','fontSize',h4_fs+'px');
	setStyleByTag('h5','fontSize',h5_fs+'px');
	setStyleByTag('h6','fontSize',h6_fs+'px');
	
	// store these values in cookies for subsequent page loads
	setCookie('fontSize',fs);
	setCookie('fontFamily',ff);
	}

// this function is called from the A+ button
function increaseSize() {
	fs+=1;
	setSizes();
	changeType();
	}

// this function is called from the A- button
function decreaseSize() {
	if (body_fs>1) {
		fs-=1;
		setSizes();
		changeType();
		}
	}



function writeControls() {	
	if (document.getElementsByTagName) { // kosher
	document.writeln('<form action="" name="targeter" onsubmit="return false;">')
	document.writeln('<input type="button" id="textDown" class="textSizer" onclick="decreaseSize()" value="A-" \/> ')
	document.writeln('<input type="button" id="textUp" class="textSizer" onclick="increaseSize()" value="A+" \/>')
	document.writeln('<br \/>')
	document.writeln('<select onchange="if(this.selectedIndex>0) 	{ff=this.options[this.selectedIndex].value;changeType()}" class="menu" > ')
	
document.writeln('<option value="Berling Antiqua, garamond, serif">Berling Antiqua<\/option>')
	document.writeln('<option value="Book Antiqua, palatino linotype, palatino, serif">Book Antiqua<\/option>')
	document.writeln('<option value="Calisto MT, new times roman, serif">Calisto MT<\/option>')
	document.writeln('<option value="garamond, times, new roman, serif">Garamond<\/option>')
	document.writeln('<option value="georgia, times, times new roman, serif">Georgia<\/option>')
	document.writeln('<option value="Hoefler text, times, times new roman, serif">Hoefler Text<\/option>')
	document.writeln('<option value="New York, times, times new roman, serif">New York<\/option>')
	document.writeln('<option value="palatino linotype, palatino, book antiqua, times new roman, serif">Palatino<\/option>')
	document.writeln('<option value="Sylfaen, garamond, times new roman, serif">Sylfaen<\/option>')
	document.writeln('<option value="times new roman, times, serif">Times<\/option>')
	document.writeln('<\/select>')
		
		document.writeln('<\/form>')
		}
	}

// cookie functions modified from code found at Alexei Kourbatov's javascripter.net/faq/
function setCookie(cookieName,cookieValue) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*3000);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
	}
	
function readCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}



// These 2 setstyle functions were modified from code by Steven Champeon found at
// http://developer.apple.com/internet/_javascript/styles.html

// setStyleByTag: given an element type, style property and value
// args:
//  e - element type or id
//  p - property
//  v - value
function setStyleByTag(e, p, v) {
	var elements = document.getElementsByTagName(e);
	for(var i = 0; i < elements.length; i++) {
		elements.item(i).style[p] = v;
		}
	}

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
// 
function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}
