/**
 * Script für Ändern der Schriftgröße per Steuerelemente auf der Seite.
 * Passt die Zeilenhöhe entsprechend der Schriftgröße an.
 *
 * @author Lars-Erik Kimmel
 *
 * //SEIBERT/MEDIA GmbH
 * Rheingau Palais
 * Soehnleinstr. 8
 * 65201 Wiesbaden
 * Tel: +49 (0) 611 205 700
 * Fax: +49 (0) 611 205 7070
 * www.seibert-media.net
 */
var options = {
	// Grenzen der Schriftgrößen
	minFontSize: 12,
	maxFontSize: 16,
	// Stufengröße
	steps: 2,
	// Inhaltskontainer, die beeinflusst werden sollen
	elements: "#center_col *:not(#portal_teaser, #portal_teaser *, #home_teaser, #home_teaser *)",
	// Element mit Referenzgröße
	fontSizeReference: "#center_col",
	// Kontrollelemente
	buttonPlus: ".fontresize .plus",
	buttonMinus: ".fontresize .minus"
};

(function ($) {
	$(function () {
		var currSize = parseInt($(options.fontSizeReference).css("font-size"));
		var lastSize = currSize;
		
		var fontresize = function () {
			// Groessenänderung ermitteln
			//console.log(currSize, parseInt($reference.css("font-size")));
			var diff = currSize - lastSize;

			// Schriftgroesse anpassen
			$(options.elements).filter(function () {
				// nur Elemente mit Textinhalte verändern
				return ($(this).contents("[nodeType=3]").filter(function () {
							return !this.data.match(/^[ \t\n]*$/);
						}).length > 0);
			}).add(options.fontSizeReference).each(function () {
				var $this = $(this);
				//console.log($this, $this.css("font-size"), $this.css("line-height"), diff);
				$this.css({
					fontSize: parseInt($this.css("font-size")) + diff,
					lineHeight: (parseInt($this.css("line-height")) + diff) + "px"
				});
				//console.log($this, $this.css("font-size"), $this.css("line-height"));
			});
		};
		
		$(options.buttonPlus + ", " + options.buttonMinus).hover(function () {
				$(this).addClass("hover");
			}, function () {
				$(this).removeClass("hover");
		});
		
		$(options.buttonPlus).click(function () {
			lastSize = currSize;
			currSize += options.steps;
			if (currSize > options.maxFontSize) {
				currSize = options.maxFontSize;
			} else {
				fontresize();
			}
			return false;
		});
		
		$(options.buttonMinus).click(function () {
			lastSize = currSize;
			currSize -= options.steps;
			if (currSize < options.minFontSize) {
				currSize = options.minFontSize;
			} else {
				fontresize();
			}
			return false;
		});
	});
})(jQuery);