$(document).ready(function(){

	var tapTimer = {}; // initialize the timer
	
	function tapTap(){ // 1st part of the loop
		$('button').addClass('tap');
		tapTimer = $.timer(300, function(){
			reTap(); // go to 2nd part of the loop
		});
	}
	function reTap(){ // 2nd part of the loop
		$('button').removeClass('tap');
		tapTimer = $.timer(300, function(){
			tapTap(); // back to 1st part of the loop
		});
	}
	function unTap(){
		$('button').removeClass('tap');
	}
	function typeTap(){
		$('button').addClass('tap');
		tapTimer = $.timer(200, function(){
			unTap(); // remove hover class
		});
	}
	
	// hovering over the button makes the telegraph repeatedly tap
	$('button').hover(function() {
		tapTap(); 
	}, function(){
		$.clearTimer(tapTimer);
		unTap();
	});
	// typing in the form makes the telegraph tap on each keypress
	$("input, textarea").keypress(function(){
	  typeTap();
	});

});
