var text_element = 'div#right_column p, div#right_column li';

$( function() {

	var MIN_SIZE = 9;
	var MAX_SIZE = 25;

	var SIZE_DIFF = (MAX_SIZE - MIN_SIZE)

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

	$(text_element).css('font-size', startSize);

	$('#slider_caption').hide();
	var captionVisible = false;
	$('.slider_bar').slider( {
		handle :'.slider_handle',
		startValue :startSize * 100 / SIZE_DIFF - 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 * SIZE_DIFF / 100 + MIN_SIZE));
				$('#font_indicator b').text(Math.round(ui.value * SIZE_DIFF / 100 + MIN_SIZE));
				$(text_element).animate( {
					fontSize :ui.value * SIZE_DIFF / 100 + MIN_SIZE
				}).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 * SIZE_DIFF / 100 + MIN_SIZE));
			$('#font_indicator b').text(Math.round(ui.value * SIZE_DIFF / 100 + MIN_SIZE));
			$(text_element).css( {
				fontSize :ui.value * SIZE_DIFF / 100 + MIN_SIZE
			}).fadeIn("slow");

		}
	});

	/*
	 * $(".add").click(function(){ var currentFontSize = $('#text
	 * p').css('font-size'); var currentFontSizeNum =
	 * parseFloat(currentFontSize, 10); var newFontSize = currentFontSizeNum+1;
	 * if (newFontSize < 23) { $(text_element).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("Isn't 23 big enough?"); $('#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 > 8) { $(text_element).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("Isn't 8 small enough?"); $('#font_indicator').fadeOut('slow'); }
	 * return false; });
	 */

});

window.onbeforeunload = leaveCookie;

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