$(function(){
	
	container = '#wrapper';
	currentState = 0;
	
	//save the originalfont-size and line-height attributes for every element in the specified container
	sizeOrig = new Array;
	lineOrig = new Array;
	$(container+' *').each(function(){
		sizeOrig.push($(this).css('font-size'));
		lineOrig.push($(this).css('line-height'));
	});
	
	function smaller(){
		size = new Array;
		line = new Array;
		//make an array of font-sizes for each element in the container
		//and array of line-heights for each element in the container
		$(container+' *').each(function(){
			size.push($(this).css('font-size'));
			line.push($(this).css('line-height'));
		});
		$(container+' *').each(function(){
			//grab the first element from each array
			sizeShift = size.shift();
			lineShift = line.shift();
			//extract the number from the font-size attribute
			position = sizeShift.indexOf('px');
			number = sizeShift.substring(0,position);
			//minus two from the number and concatenate with 'px' to create new font-size attribute
			//parsefloat in case font-sizes are set in pt (pt will be converted into px, in which case a float will occur)
			newsize = (parseFloat(number)-2)+'px';
			//apply new font-size attribute to current element
			$(this).css('font-size',newsize)
			
			lineposition = lineShift.indexOf('px');
			linenumber = lineShift.substring(0,lineposition);
			linenewsize = (parseFloat(linenumber)-2)+'px';
			$(this).css('line-height',linenewsize);
		});
	}
	
	function bigger(x){
	var loops = (x == null) ? 1 : x;
		for(var i=loops;i>=1;i--){
			size = new Array;
			line = new Array;
			$(container+' *').each(function(){
				size.push($(this).css('font-size'));
				line.push($(this).css('line-height'));
			});
			$(container+' *').each(function(){
				sizeShift = size.shift();
				lineShift = line.shift();
				
				position = sizeShift.indexOf('px');
				number = sizeShift.substring(0,position);
				newsize = (parseFloat(number)+2)+'px';
				$(this).css('font-size',newsize)
				
				lineposition = lineShift.indexOf('px');
				linenumber = lineShift.substring(0,lineposition);
				linenewsize = (parseFloat(linenumber)+2)+'px';
				$(this).css('line-height',linenewsize);
			});
		}
	}
	
	$('#bigger').click(function(){
		if(currentState == 0 || currentState == 2){
			currentState == 0 ? bigger() : smaller();
			currentState == 0 ? currentState ++ : currentState--;
		};//endif
	});

	$('#biggest').click(function(){
		if(currentState == 0 || currentState == 1){		
			currentState == 0 ? bigger(2) : bigger();
			currentState == 0 ? currentState += 2 : currentState++;	
		};//endif
	});

	$('#original').click(function(){
		currentState = 0;
		$(container+' *').each(function(){
			sizeShift2 = sizeOrig.shift();
			lineShift2 = lineOrig.shift();
			
			$(this).css('font-size',sizeShift2)
			$(this).css('line-height',lineShift2);
		});
		sizeOrig = new Array;
		lineOrig = new Array;
		$(container+' *').each(function(){
			sizeOrig.push($(this).css('font-size'));
			lineOrig.push($(this).css('line-height'));
		});
	});
});