/* --------------------------------------------------------------------
	Text resizer in 4 steps
-------------------------------------------------------------------- */

var SIZE_TABLE = ['s', 'm', 'l', 'xl'];

$(document).ready(function() {

	$('.txtSizeUp').bind('click', function(evt) {
		textResize(1);
		evt.preventDefault();
	});
	
	$('.txtSizeDown').bind('click', function(evt) {
		textResize(-1);
		evt.preventDefault();
	});

	function getCurrentTableIndex() {
		
		for (var tableIdx in SIZE_TABLE) {
			if ($("body").hasClass(SIZE_TABLE[tableIdx]))
				return parseInt(tableIdx, 10);
		}
		
		return 0;
	}
	
	function textResize(resizeDirection) {

		var tableIdx = getCurrentTableIndex();

		// determine the new array index
		var newIdx = Math.max(0, Math.min(3, tableIdx + resizeDirection));

		// adjust styles
		$('body').removeClass(SIZE_TABLE[tableIdx]).addClass(SIZE_TABLE[newIdx]);
		
		
		// get json
		if (typeof(URL_BASE) != 'undefined') {
			$.getJSON(
				URL_BASE + "/textresize", 
				{ "textSize" : SIZE_TABLE[newIdx] },
				function(data) {
				}
			);
		}
		
	}

}); 

