﻿var $j = jQuery.noConflict();

$j(function(){
	var originalFontSize = $j('html').css('font-size');
	
	var $text = $j('html .body');
	
	// add controls
	$j('.mainmenu .wrapper').prepend('<div id="fontsizer"><a href="#" class="increase"><span>Increase</span></a><a href="#" class="decrease"><span>Decrease</span></a></div>');
	if( getcookie('fontsize') ) {
        var newFontSize = getcookie('fontsize');
        //$text.css( {'font-size':getcookie('fontsize')+'px', "line-height":getcookie('lineheight')} );
    }  
	// Reset Font Size
	$j(".reset").click(function(){
		$text.css('font-size', originalFontSize);
	});
	// Increase Font Size
	$j(".increase").click(function(){
		var currentFontSize = $text.css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		//var newFontSize = Math.round(currentFontSizeNum*1.2);
		var newFontSize = currentFontSizeNum+2;
		var currentLineHeight = $text.css('lineHeight');
		var currentLineHeightNum = parseFloat(currentLineHeight, 10);
		//var newLineHeight = currentLineHeightNum*1.2;
		var newLineHeight = currentLineHeightNum+2;		
		var stringEnding = currentLineHeight.slice(-2);
		if( currentFontSizeNum < 20) {
			$text.css( {'font-size':newFontSize, "line-height":newLineHeight+stringEnding} );
			setcookie( 'fontsize', newFontSize );
			setcookie( 'lineheight', newLineHeight+stringEnding );
		}
		return false;
	});
	// Decrease Font Size
	$j(".decrease").click(function(){
		var currentFontSize = $text.css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		//var newFontSize = Math.round(currentFontSizeNum*0.8);
		var newFontSize = currentFontSizeNum-2;
		var currentLineHeight = $text.css('lineHeight');
		var currentLineHeightNum = parseFloat(currentLineHeight, 10);
		//var newLineHeight = currentLineHeightNum*0.8;
		var newLineHeight = currentLineHeightNum-2;
		var stringEnding = currentLineHeight.slice(-2)
		if( currentFontSizeNum > 10 ){
			$text.css( {'font-size':newFontSize, "line-height":newLineHeight+stringEnding} );
			setcookie( 'fontsize', newFontSize );
			setcookie( 'lineheight', newLineHeight+stringEnding );
		}
		return false;
	});
});

function getcookie( cookie_name ) {
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results )
    return ( results[1] );
  else
    return false;
}

function setcookie( cookie_name, value ) {
    document.cookie = cookie_name+"="+value+"; path=/; domain="+document.domain;
}
