$(document).ready(function(){
    //changed to use % value
    
    function setSize(textMultiplier){
        //min text size is 75% max text size is 175%
        if(textMultiplier < 0.75 ){
            textMultiplier = 0.75;
        }
        if(textMultiplier > 1.75 ){
            textMultiplier = 1.75;
        }
        $('body').css('fontSize', textMultiplier + "em");
        if(textMultiplier > 1.3){
            if(textMultiplier > 1.6){
                $('.buttonbar_top').css('width','190px');
                $('#content').css('marginLeft','205px');
                $('#SrchHelp').css('marginLeft','205px');
            }  else {
                $('.buttonbar_top').css('width','175px');
                $('#content').css('marginLeft','190px');
                $('#SrchHelp').css('marginLeft','190px');
            }
        } else {
            $('.buttonbar_top').css('width','155px');
            $('#content').css('marginLeft','170px');
            $('#SrchHelp').css('marginLeft','170px');
        }
        var textMultiplierPercent = textMultiplier * 100;
        $.cookie('textSize', textMultiplierPercent, {path: cookiepath});
        var textareaMultiplier = textMultiplier *0.9;
        $('textarea').css('fontSize', textareaMultiplier + "em");
        //additional changes for button resize
        $('input.button').each(function(){
            $(this).css('width',null);
            var buttonId = this.id;
            var buttonWidth = $(this).width();
            if(buttonWidth < '46'){
              $(this).css('width','60px');
              //var afterWidth = $(this).width();
              //alert(afterWidth);
            }
        });
        
    }
  var startingTextSize = $.cookie('textSize');
  if(startingTextSize){
    var re = new RegExp('[.]?[0-9]+[.]?[0-9]*');
    var remAlphaTextSize = startingTextSize.match(re);
    var currentSize = remAlphaTextSize / 100;
  }

	var cookieColWidth = $.cookie('colWidth');
        
	if (currentSize) {
		setSize(currentSize);
	}
	if(cookieColWidth){
		$('.numColumn').width(cookieColWidth);
	}
    
	$('.textplus').click(function() {
        cookieSize = $.cookie('textSize');
        if(cookieSize){  
            currentSize = cookieSize / 100;
        } else {
            currentSize = 1;
        }
        //if less than 175% add 25%
		if(currentSize < 1.75){
            currentSize += 0.25;
            setSize(currentSize);
		}
        
		//resize columns in image display format
		var colWidth = $('.numColumn').width();
		if (colWidth){
			if(colWidth < 48){
			  newColWidth = parseInt(colWidth * 1.25, 10);
			  $('.numColumn').width(newColWidth);
			  $.cookie('colWidth', newColWidth);
			}
		}
		
	});
	
	
	$('.textminus').click(function() {
        cookieSize = $.cookie('textSize');
        if(cookieSize){  
            currentSize = cookieSize / 100;
        } else {
            currentSize = 1;
        }
        //if greater than 75% subtract 25%
		if(currentSize > 0.75){
            currentSize -= 0.25;
            setSize(currentSize);
		}
		
		//resize columns in image display format
		var colWidth = $('.numColumn').width();
		if (colWidth){
			if(colWidth > 27){
			  newColWidth = parseInt(colWidth * 0.75, 10);
			  $('.numColumn').width(newColWidth);
			  $.cookie('colWidth', newColWidth);
			}
		}
	});
	
	$('.textreset').click(function() {
		setSize(1);
		$.cookie('textSize', null);
		$.cookie('textUnit', null);
		$.cookie('colWidth', null);
		$('.numColumn').width(33);
	});

});