﻿function getFontUnit(fontProperty) {
//%, in, cm, mm, em, ex ,pt, pc, px 
if (fontProperty.indexOf('px') > -1) {return 'px';}
if (fontProperty.indexOf('pt') > -1) {return 'pt';}
if (fontProperty.indexOf('%') > -1) {return 'pt';}
if (fontProperty.indexOf('in') > -1) {return 'in';}
if (fontProperty.indexOf('cm') > -1) {return 'cm';}
if (fontProperty.indexOf('mm') > -1) {return 'mm';}
if (fontProperty.indexOf('em') > -1) {return 'em';}
if (fontProperty.indexOf('ex') > -1) {return 'ex';}
if (fontProperty.indexOf('pc') > -1) {return 'pc';}
return 'pt';
}

function getFontNumber(fontProperty) {
//%, in, cm, mm, em, ex ,pt, pc, px 
if (fontProperty.indexOf('px') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
if (fontProperty.indexOf('pt') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
if (fontProperty.indexOf('%') > -1) { 

var percentNo = parseFloat( fontProperty.substring(0, fontProperty.length -1) );
return percentNo * 0.1;

}
if (fontProperty.indexOf('in') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
if (fontProperty.indexOf('cm') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
if (fontProperty.indexOf('mm') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
if (fontProperty.indexOf('em') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
if (fontProperty.indexOf('ex') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
if (fontProperty.indexOf('pc') > -1) {return fontProperty.substring(0, fontProperty.length -2);}
return 0;
}

function setNormalFonts(){
$('#divNormalFonts').addClass('selectedFontSize');
$('#divLargeFonts').removeClass('selectedFontSize');
$('#divLargerFonts').removeClass('selectedFontSize');

//set menu font size
$('.mainMenuItem').css('font-size', '14px');
$('.linkListItem').css('font-size', '9pt');
$('.linkListItem > li > a > p').css('font-size', '8pt');

//set content div font sizes
$('#s4-mainarea').find('div, td, p, li, span').each(function(){
  //get current font size
  var curFontSize = $(this).css("font-size");
  
  //check if orig font sizes have been set:
  var origFontSize = $(this).attr('origFontSize');
  if (origFontSize == null) {
  //we're done, keep existing font and record it as orig font
  $(this).attr('origFontSize', parseFloat(getFontNumber(curFontSize)) );
  $(this).attr('origFontUnit', getFontUnit(curFontSize) );
  }
  else {
  //current size is bigger, go back to original font size
  	if ( parseFloat(getFontNumber(curFontSize)) > $(this).attr('origFontSize')) {     
 		$(this).css('font-size', $(this).attr('origFontSize') + $(this).attr('origFontUnit')  );
  	}
  }
});

}


function setLargeFonts(){
$('#divNormalFonts').removeClass('selectedFontSize');
$('#divLargeFonts').addClass('selectedFontSize');
$('#divLargerFonts').removeClass('selectedFontSize');

//set menu font size
$('.mainMenuItem').css('font-size', '16px');
$('.linkListItem').css('font-size', '11pt');
$('.linkListItem > li > a > p').css('font-size', '10pt');

//set content div font sizes
$('#s4-mainarea').find('div, td, p, li, span').each(function(){
  //get current font size
  var curFontSize = $(this).css("font-size");
  
  //check if orig font sizes have been set:
  var origFontSize = $(this).attr('origFontSize');
  var origFontUnit = $(this).attr('origFontUnit');
  
  //save orig font before we change anything
  if (origFontSize == null) {
  origFontSize = parseFloat(getFontNumber(curFontSize));
  origFontUnit = getFontUnit(curFontSize);
  $(this).attr('origFontSize', origFontSize  );
  $(this).attr('origFontUnit', origFontUnit  );
  
  //if (origFontSize > 30){ alert( curFontSize + ' - ' +   origFontSize  + ':' + origFontUnit );  }
  
  }
  
  //set current size to 1.2% of origional  
  $(this).css('font-size', (origFontSize * 1.1) + '' + origFontUnit   );

});

}

function setLargerFonts(){
$('#divNormalFonts').removeClass('selectedFontSize');
$('#divLargeFonts').removeClass('selectedFontSize');
$('#divLargerFonts').addClass('selectedFontSize');

//set menu font size
$('.mainMenuItem').css('font-size', '18px');
$('.linkListItem').css('font-size', '14pt');
$('.linkListItem > li > a > p').css('font-size', '13pt');

//set content div font sizes
$('#s4-mainarea').find('div, td, p, li, span').each(function(){
  //get current font size
  var curFontSize = $(this).css("font-size");
  
  //check if orig font sizes have been set:
  var origFontSize = $(this).attr('origFontSize');
  var origFontUnit = $(this).attr('origFontUnit');
  
  //save orig font before we change anything
  if (origFontSize == null) {
  origFontSize = parseFloat(getFontNumber(curFontSize));
  origFontUnit = getFontUnit(curFontSize);
  $(this).attr('origFontSize', origFontSize  );
  $(this).attr('origFontUnit', origFontUnit  );
  
  //if (origFontSize > 30){ alert( curFontSize + ' - ' +   origFontSize  + ':' + origFontUnit );  }
  
  }
  
  //set current size to 1.2% of origional  
  $(this).css('font-size', (origFontSize * 1.3) + '' + origFontUnit   );

});

}



