
$(function() {


var startSize = $.cookie('fontSize');
var startSize = parseFloat(startSize, 12);

 


	$('#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')).text(Math.round(ui.value * 15/100 + 8 ));
				$('#font_indicator b').text(Math.round(ui.value * 15/100 + 8 ));
				$("div#text 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')).text(Math.round(ui.value * 15/100 + 8 ));
			$('#font_indicator b').text(Math.round(ui.value * 15/100 + 8 ));
			$("div#text p").css({fontSize: ui.value * 15/100 + 8 }).fadeIn("slow");

		}
	});
	
	
	
	  $(".add").click(function(){
    var currentFontSize = $('#text p').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum+1;
	if (newFontSize < 30) {
    $('#text p').css('font-size', newFontSize);
	$('#slider_caption').css('left', newFontSize*19.75 - 158).fadeIn('fast').text(Math.round(newFontSize )).fadeOut();
	$('.slider_handle').css('left', newFontSize*19.75 - 158);
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').text(Math.round(newFontSize ));
	$('#font_indicator').fadeOut('slow');
	}
	else{
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').text("30 is the largest font size we display.");
	$('#font_indicator').fadeOut('slow');
	}
    return false;
  });
  
  
  	  $(".minus").click(function(){
    var currentFontSize = $('#text p').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum-1;
	if (newFontSize > 10) {
    $('#text p').css('font-size', newFontSize);
	$('#slider_caption').css('left', newFontSize*19.75 - 158).fadeIn('fast').text(Math.round(newFontSize )).fadeOut();
	$('.slider_handle').css('left', newFontSize*19.75 - 158);
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').text(Math.round(newFontSize ));
	$('#font_indicator').fadeOut('slow');
	}
	else{
	$('#font_indicator').fadeIn('slow');
	$('#font_indicator b').text("Sorry, 10 is a small as the text gets.");
	$('#font_indicator').fadeOut('slow');
	}
	return false;
  });
  
  
  	  $(".recycle").click(function(){ 
    $('#text p').css('font-size', 12); 
	$('#font_indicator b').text(Math.round(newFontSize )); 
 
	return false;
  });
  


});
  window.onbeforeunload = leaveCookie;

function leaveCookie()
{
			var FontSize = $('#text p').css('font-size');
   			var IntFontSize = parseFloat(FontSize, 10);
			$.cookie('fontSize', IntFontSize);
}
