$(function() {

var startSize = $.cookie('fontSize');
var startSize = parseFloat(startSize, 12);


$('#content p').css('font-size', startSize);


	$('#slider_caption').hide();
	var captionVisible = false;
	$('.slider_bar').slider({
		handle: '.slider_handle',
		startValue: startSize*100/15 - 53.3 ,
		minValue: 0,
		maxValue: 100,
		start: function(e, ui) {
			$('#slider_caption').fadeIn('fast', function() { captionVisible = true;});
			$('#font_indicator').fadeIn('slow');
			
		},
		stop: function(e, ui) { 
			if (captionVisible == false) {
				$('#slider_caption').fadeIn('fast', function() { captionVisible = true;});
				$('#font_indicator').fadeIn('slow');
				$('#slider_caption').css('left', ui.handle.css('left')).content(Math.round(ui.value * 15/100 + 8 ));
				$('#font_indicator b').content(Math.round(ui.value * 15/100 + 8 ));
				$("div#content p").animate({fontSize: ui.value * 15/100 + 8 }).fadeIn("slow");

			}
			$('#slider_caption').fadeOut('fast', function() { captionVisible = false; });
			$('#font_indicator').fadeOut('slow');
			
			
		},
	
		slide: function(e, ui) {
			$('#slider_caption').css('left', ui.handle.css('left')).content(Math.round(ui.value * 15/100 + 8 ));
			$('#font_indicator b').content(Math.round(ui.value * 15/100 + 8 ));
			$("div#content p").css({fontSize: ui.value * 15/100 + 8 }).fadeIn("slow");

		}
	});
	
	
	
	  $(".add").click(function(){
    var currentFontSize = $('#content p').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum+1;
	if (newFontSize < 23) {
    $('#content p').css('font-size', newFontSize);
	
	$('#slider_caption').css('left', newFontSize*19.75 - 158).fadeIn('fast').content(Math.round(newFontSize )).fadeOut();
	$('.slider_handle').css('left', newFontSize*19.75 - 158);
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').content(Math.round(newFontSize ));
	$('#font_indicator').fadeOut('slow');
	}
	else{
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').content("Isn't 23 big enough?");
	$('#font_indicator').fadeOut('slow');
	}
    return false;
  });
  	  $(".minus").click(function(){
    var currentFontSize = $('#content p').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum-1;
	if (newFontSize > 8) {
    $('#content p').css('font-size', newFontSize);
	$('#slider_caption').css('left', newFontSize*19.75 - 158).fadeIn('fast').content(Math.round(newFontSize )).fadeOut();
	$('.slider_handle').css('left', newFontSize*19.75 - 158);
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').content(Math.round(newFontSize ));
	$('#font_indicator').fadeOut('slow');
	}
	else{
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').content("Isn't 8 small enough?");
	$('#font_indicator').fadeOut('slow');
	}
	return false;
  });
  


});
  window.onbeforeunload = leaveCookie;

function leaveCookie()
{
			var FontSize = $('#content p').css('font-size');
   			var IntFontSize = parseFloat(FontSize, 10);
			$.cookie('fontSize', IntFontSize);
}
