
//global font variation for the content 
var mutiplyer_1 = 0;

//global  font variation for the menu_vert
var mutiplyer_2 = 0;

//global header_links for the header_links
var mutiplyer_3 = 0;

//global footer_detail for the header_links
var mutiplyer_4 = 0;

/*
@mutilper - (1 or -1 defines whether scaling font ranges up or down)
set the various parent divs ranges, scales, and steps here
everything is housed in this function 

to add a new ranger create a new global multiplyer_

*/
function resizeText(mutiplyerIn){
	var newVal;
	var step;

	/*change content div*/
	step = 10;	
	div_id = "content";
	newVal = changeFontRange(div_id, mutiplyerIn, 5, -3, step);
	if (newVal!='nf'){
		mutiplyer_1=newVal;
		recurseChangeSize(document.getElementById(div_id), mutiplyer_1, step);
	}else{
		return;
	}	

	/*change menu_vert*/
	


	/*change header_links*/
	step = 10;
	div_id = "headerLinks";	
	newVal = changeFontRange(div_id, mutiplyerIn, 5, -2, step);
	//newVal != 'nf' ? mutiplyer_2 = newVal:return;	
	if (newVal!='nf'){
		mutiplyer_3=newVal;		
		recurseChangeSize(document.getElementById(div_id), mutiplyer_3, step);
	}else{
		return;
	}
	
	
	/*change footer_detail*/
	step = 10;
	div_id = "IA_footer";	
	newVal = changeFontRange(div_id, mutiplyerIn, 5, -2, step);
	//newVal != 'nf' ? mutiplyer_2 = newVal:return;	
	if (newVal!='nf'){
		mutiplyer_3=newVal;		
		recurseChangeSize(document.getElementById(div_id), mutiplyer_3, step);
	}else{
		return;
	}
}

function resetText(){
	mutiplyer_1 = 0;
	recurseChangeSize(document.getElementById("content"), mutiplyer_1, 0);
	
	mutiplyer_2 = 0;
	recurseChangeSize(document.getElementById("menu_vert"), mutiplyer_2, 0);
	
	mutiplyer_3 = 0;
	recurseChangeSize(document.getElementById("header_links"), mutiplyer_3, 0);
	
	mutiplyer_4 = 0;
	recurseChangeSize(document.getElementById("footer_detail"), mutiplyer_4, 0);
	
}



/*
distiguish if the divs for the font is in the avialbe ranges
@divId - the div parent whose font you which to change (the function will later recurse all the elements in side of it and scale up their fonts to match)

@multiplyerIn - 1 or -1 (scaling up or down)
@upperRange - the number of steps a font can be scaled up from its original size
@lowerRange - the number of steps a font can be scaled down from its original size
*/
function changeFontRange(divId, multiplyerIn, upperRange, lowerRange){
	gMultipler = divId == "content"?mutiplyer_1:mutiplyer_2;
	var newMutiplyer = multiplyerIn>0?gMultipler +1:gMultipler -1; 
		
	if (newMutiplyer > upperRange || newMutiplyer < lowerRange){
		return 'nf';
	}else{
		return newMutiplyer;		
	}
}


/*
this function recursese the parent item and all of its children and 
finds there original font size and scales it based upon the step
*/
function recurseChangeSize(n, mutiplyerIn, step){
	if (n.nodeType == 1){					
		if (!n.origFSize){					
			var oFs = getStyle(n, "font-size");			
			n.fontSuffix = oFs.indexOf('px') > -1?"px":"em"; 			
			n.origFSize = oFs.replace(/px/, "");			
			n.origFSize = n.origFSize.replace(/em/, "");
		}
		if (!n.origLHeight){		
			var oLh = getStyle(n, "line-height");
			n.lHSuffix = oLh.indexOf('px') > -1?"px":"em"; 			
			n.origLHeight = oLh.replace(/px/, "");
			n.origLHeight = n.origLHeight.replace(/em/, "");
		}
				
		var newFontSize = ((100 + (step*mutiplyerIn))/100) * n.origFSize;  		
		
		var newLineHeight = ((100 + (step*mutiplyerIn))/100) * n.origLHeight;  
		
		
		if (newFontSize){			
			n.style.fontSize = parseInt(newFontSize) + n.fontSuffix;
		}
		if (newLineHeight){			
			n.style.lineHeight = parseInt(newLineHeight) + n.fontSuffix;
		}		
	}
	if (n.nodeType != 3){
		var kids = n.childNodes;		
		for (var i = 0; i < kids.length; i++){
			recurseChangeSize(kids[i], mutiplyerIn, step);
		}		
	}
}



//gets the style currently applied to the element 
//different for IE and Mozilla(gecko)

function getStyle(oElm, strCssRule){
  var strValue = "";
  if(document.defaultView && document.defaultView.getComputedStyle){
    strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
  }
  else if(oElm.currentStyle){
    strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
      return p1.toUpperCase();
    });
    strValue = oElm.currentStyle[strCssRule];
  }
  return strValue;
}

