$(document).ready (function() {
	
	var txt = 0;
	
	var headerHeight = 140;
	//var menuHeight = 18;
	var filarianeHeight = 17;
	var zoneHeight = 20;
	
	if($.cookie("css")) {
		setCSS ($.cookie("css"));
	}
	
	if($.cookie("txt")) {
		txt = parseInt ($.cookie("txt"));
		$('#header').css ('height', function () { return headerHeight + txt*4; });
		//$('#header .menuprim li a').css ('height', function () { return menuHeight + txt*4; });
		$('#zone02 .btn-fichier, #zone02 .ttr, #zone03 .ttr').css ('height', function () { return zoneHeight + txt*4; });
		$('#filariane').css ('height', function () { return filarianeHeight + txt*2; });
		$('body').css ( 'fontSize', function () { return 10 + txt*2; });
	}
	
	function setCSS (n) {
		switch (parseInt(n)) {
			case 1 :
				$("#link-design").attr ("href", "/styles/design.css");
				break;
			default :
				$("#link-design").attr ("href", "#");
				break;
		}
		$.cookie("css", n, {expires: 365, path: '/'});
	}
	
	function txtResize (n) {
		var signe = (parseInt(n)>0) ? "+" : "-";
		
		txt += n;
		
		$('.chapo').css ({ lineHeight:'normal' });
		//$('#header .menuprim li a, #zone02 .btn-fichier, #zone02 .ttr, #zone03 .ttr').animate ({ height: signe + '=4px' }, 100);
		$('#zone02 .btn-fichier, #zone02 .ttr, #zone03 .ttr').animate ({ height: signe + '=4px' }, 100);
		$('#header').animate ({ height: signe + '=4px' }, 100);
		$('#filariane').animate ({ height: signe + '=2px' }, 100);
		$('body').animate ({ fontSize:signe + '=2px' }, 300);
		$.cookie("txt", txt, {expires: 365, path: '/'});
	}
	
	/*function txtPlus () {
		$('.chapo').css ({ lineHeight:'normal' });
		$('#header .menuprim li a, #zone02 .btn-fichier, #zone02 .ttr, #zone03 .ttr').animate ({ height:'+=4px' }, 100);
		$('#header').animate ({ height:'+=4px' }, 100, function () {
			$('#filariane').animate ({ height:'+=2px' }, 100, function () { 
				$('body').animate ({ fontSize:'+=2px' }, 300); 
			});
		});
		$.cookie("txt", txt, {expires: 365, path: '/'});
	}
	
	function txtMoins () {
		$('.chapo').css ({ lineHeight:'normal' });
		$('body').animate ({ fontSize:'-=2px' }, 300, function () {
			$('#filariane').animate ({ height:'-=2px' }, 100, function () { 
				 $('#header').animate ({ height:'-=4px' }, 100, function () {
					$('#header .menuprim li a, #zone02 .btn-fichier, #zone02 .ttr, #zone03 .ttr').animate ({ height:'-=4px' }, 100);
				});
			});
		});
		$.cookie("txt", txt, {expires: 365, path: '/'});
	}*/
	
	$('#text-plus').click (function () { 
		//txtPlus ();
		txtResize (1);
	});
	
	$('#text-moins').click (function () { 
		//txtMoins ();
		txtResize (-1);
	});

	$('#text-reset').click (function () { 
		txt=0;
		$('body').animate ({ fontSize:'10px' }, 300, function () { 
			$('#filariane').animate ({ height: filarianeHeight + 'px' }, 100, function () { 
				$('#header').animate ({ height: headerHeight + 'px' }, 100, function () {
					//$('#header .menuprim li a').animate ({ height: menuHeight + 'px' }, 100); 
					$('#zone02 .btn-fichier, #zone02 .ttr, #zone03 .ttr').animate ({ height: zoneHeight + 'px' }, 100); 
				});
			});
		});
		$('.chapo').css ({ lineHeight:'14px' });
		$.cookie("txt", txt, {expires: 365, path: '/'});
	});
	
	// $('body, .fck, .legende').css ({ color:"#000" });
	// $('body, .fck, .legende').css ({ color:"#878789" });
	
	$("#style-sans").click (function () {
		setCSS (0);
	});
	$("#style-avec").click (function () {
		setCSS (1);
	});
		
	
	$('#ergonomie').fadeIn ('slow');
});
