// JavaScript Document








$(document).ready(function() {

if($.cookie("set") == "Yes"){


$('#contentarea').css('lineHeight', 	$.cookie("lineheight"));
$('#contentarea').css('fontSize', $.cookie("fontsize"));
$('.increase').css('visibility', $.cookie("increase"));
$('.decrease').css('visibility', $.cookie("decrease"));
}






$('.increase').click(function() {
	$(this).FontSizeAccessibilty(10, 20, .1, 20);
});
$('.decrease').click(function() {
	$(this).FontSizeAccessibilty(10, 20, .1, 20);
});
$('.default').click(function() {
	$(this).FontSizeAccessibilty(10, 20, .1, 20);
});

});


$.fn.FontSizeAccessibilty = function(minSize, maxSize, increasePercent, cookies) {
  return this.each(function(){
 	var lineHeightofParent = $('#contentarea').css('lineHeight');
	var fontSizeofParent = $('#contentarea').css('fontSize');
	var unitOfLineHeight = lineHeightofParent.replace(/\d/g, "");
	var unitOfFontSize = fontSizeofParent.replace(/\d/g, "");
	var fontSizeOfParentNumber =  parseFloat(fontSizeofParent);
	var lineHeightofParentNumber =  parseFloat(lineHeightofParent);
	var fontSizeDifference = fontSizeOfParentNumber * increasePercent;
	var lineHeightDifference = lineHeightofParentNumber * increasePercent;
	var updatedFontSize = 0;
	var updatedLineHeightSize = 0;
	if($(this).attr("class") == "increase"){
			
		if(fontSizeOfParentNumber <= maxSize){
			updatedFontSize = fontSizeOfParentNumber + fontSizeDifference;
			updatedLineHeightSize = lineHeightofParentNumber + lineHeightDifference;
			updatedFontSize = Math.round(updatedFontSize);
			updatedLineHeightSize = Math.round(updatedLineHeightSize);
		}else{
			updatedFontSize = fontSizeOfParentNumber;
			updatedLineHeightSize = lineHeightofParentNumber;	
	}
	}
 
	if($(this).attr("class") == "decrease"){
		if(fontSizeOfParentNumber >= minSize){
			updatedFontSize = fontSizeOfParentNumber - fontSizeDifference;
			updatedLineHeightSize = lineHeightofParentNumber - lineHeightDifference;
			updatedFontSize = Math.round(updatedFontSize);
			updatedLineHeightSize = Math.round(updatedLineHeightSize);
		}else{
			updatedFontSize = fontSizeOfParentNumber;
			updatedLineHeightSize = lineHeightofParentNumber;	
		}
	
	}
	
	if(updatedFontSize >= maxSize && $(this).attr("class") == "increase"){
		$(this).css('visibility', 'hidden');
		$(this).prev('decrease').css('visibility', 'visible');
	}else if(updatedFontSize <= maxSize && $(this).attr("class") == "increase"){
			$(this).next().css('visibility', 'visible');
	}
	if(updatedFontSize <= minSize && $(this).attr("class") == "decrease" ){
		$(this).css('visibility', 'hidden');
		$(this).prev('.increase').css('visibility', 'visible');
	}else if(updatedFontSize >= minSize && $(this).attr("class") == "decrease" ){
		$(this).prev('.increase').css('visibility', 'visible');
		
	}

	
updatedFontSize = updatedFontSize + unitOfFontSize;
updatedLineHeightSize = updatedLineHeightSize + unitOfLineHeight;
$('#contentarea').css('lineHeight', updatedLineHeightSize);
$('#contentarea').css('fontSize', updatedFontSize);
$.cookie("lineheight", updatedLineHeightSize);
$.cookie("fontsize", updatedFontSize);
$.cookie("increase", $('.increase').css("visibility"));
$.cookie("decrease", $('.decrease').css("visibility"));
$.cookie("set", "Yes");
$.cookie("path", $('#contentarea'))


if($(this).attr('class') == "default"){
		 $('#contentarea').removeAttr('style');
	 $(this).prev('.decrease').css('visibility', 'visible');
		 $(this).prev().prev('.increase').css('visibility', 'visible');
		 $.cookie("set", "");
}
 	
  });
};
