/************** CONFIG ************/
//class font sizes add to switch in getElFontSize()
var body9 = 9;
var body10 = 10;
var body11 = 11;
var body12 = 12;
var body13 = 13;
var other = 10;

var max_pos = 3; //largest increment pos

var min_font_percent = 100; //start at 100%
var max_font_percent = 160; //max of 180%

var increment = 20; //increment by 20%
/************* \CONFIG ************/

var min_pos = 0; //smallest increment
var curr_font_pos = 0; //starting point 100%
var done_switching = false; //flag after first element incremented so we only increment pos once
var cookie_set=false;
var completeTimer;
var mouseX=0;
var mouseY=0;
var anchorX=0;
var anchorY=0;
var heightRatio = 1;
var	gotHeightRatio = false;

function getElFontSize(o){ //switch for class font sizes
	switch(o.className){
		case "body9":
			return body9;
			break;
		case "body10":
			return body10;
			break;
		case "body11":
			return body11;
			break;
		case "body12":
			return body12;
			break;
		case "body13":
			return body13;
			break;
		default:
			return other;
	}
}

function saveFaceSize(){ //set cookie with current pos
	var expire = new Date ();
   	expire.setTime (expire.getTime() + (6 * 3600000));
	expire = expire.toGMTString();	
//	alert("set: " + curr_font_pos);	
	document.cookie="curr_font_pos="+curr_font_pos+";path=/;expires="+expire;
}	
function loadFontSize(){ //get cookie with current pos
	tempArray = document.cookie.split(";");		
	for (tA = 0; tA < tempArray.length; tA++){
		if (tempArray[tA].indexOf('curr_font_pos') > -1) {
			fontValue = tempArray[tA].split("=")
			curr_font_pos = parseInt(fontValue[1]);
	//		alert("read: " + curr_font_pos);
			cookie_set = true;
		}
	}
}

function switchFontByElement(o,v){ //switch individual element font size
	if(o.style){
		if(curr_font_pos<min_pos) //keep pos within range
			curr_font_pos=min_pos;
		else if(curr_font_pos>max_pos)
			curr_font_pos=max_pos;	
		if(o.style.fontSize!=""){ //get font size if set (write only) stripping "px"
			o.fontSize = o.style.fontSize.replace(/([0-9]+)px/, "$1");
		}	
		else{
			o.fontSize = getElFontSize(o)+(getElFontSize(o)*curr_font_pos*increment/100); // get new size; default font size + (default font size * current position * increment)/100
		}	
		o.fontSize = parseInt(o.fontSize)+(v*getElFontSize(o)/100); //increment or decrement by percentage
		if(o.fontSize<(getElFontSize(o)*min_font_percent/100))//keep font within range of min/max
			o.fontSize=min_font_percent*getElFontSize(o)/100;
		else if(o.fontSize>(getElFontSize(o)*max_font_percent/100))
			o.fontSize=max_font_percent*getElFontSize(o)/100;
		if(v>0&&!done_switching){//increment or decrement pos
			curr_font_pos++;
		}	
		else if(v<0&&!done_switching){
			curr_font_pos--;
		}
		o.style.fontSize = o.fontSize+"px";
		o.style.lineHeight = "120%";
	
		done_switching=true;	
	}
	saveFaceSize();//set cookie
	return false;
}	

function switchFont(v){
	done_switching=false;
	v=v?v:0;
	loadFontSize(); //get cookie
	if(!cookie_set){saveFaceSize();}
	if(document.getElementsByTagName) { //dom
	 	var x = document.getElementsByTagName('SPAN');
		for (i=0;i<x.length;i++){			
			if (x[i].className=="body9" || x[i].className=="body10" || x[i].className=="body11" || x[i].className=="body12" || x[i].className=="body13") {		
		       switchFontByElement(x[i],v);
			}
		}
	}			
	else if(document.all){//old M$
		for (i=0;i<document.all.length;i++){
			if (document.all[i].className=="adjustable_font"&&document.all[i].nodeName=="DIV") {		
		        for (j=0; j<document.all[i].childNodes.length; j++) {
					switchFontByElement(document.all[i].childNodes[j],v);
				}
			}
		}
	}		
}

function initSwitcher()	{
	 switchFont();
}
