// Function to resize the text of an element (target) by a multiplier (multiplier)
var defaultSize = [];
function resizeText(multiplier, target) {
	if (target.css('fontSize') == "") {
		target.css('fontSize', '12px');
	}
	var newSize = parseFloat(target.css('fontSize')) + (multiplier * 2);

	// Remember default fontsize and do not go below it
	var id = (target.attr("id")) ? target.attr("id") : "fsize-" + String.fromCharCode(65 + Math.round(Math.random() * 25))+ Math.round(Math.random()*100)
	
	if(!target.attr("id"))
	    target.attr("id", id);
	
	if(!defaultSize[id])
	    defaultSize[id] = newSize - (multiplier * 2);
	if(newSize > defaultSize[id])
	    target.css('fontSize', newSize + 'px');
	else
	    target.css('fontSize', defaultSize[id] + 'px');
}

jQuery(function($) {
	// Increase font size
	$('a.increase-font-size').live('click', function(e) {
		$(this).closest('.article').children('.article-main').children('p').each(function(){
		    resizeText(1, $(this));
		});
		
		e.preventDefault();
	});

	// Decrease font size
	$('a.decrease-font-size').live('click', function(e) {
		//var target = $(this).closest('.article');
		//resizeText(-1, target);
		$(this).closest('.article').children('.article-main').children('p').each(function(){
		    resizeText(-1, $(this));
		    
		});

		e.preventDefault();
	});

	// Print the current screen
	$('a.print').live('click', function(e) {
		window.print();

		e.preventDefault();
	});
});
