$(function(){
	var transforms=[
		{
			name:'Discrete-time Fourier transform (DTFT)',
			timeFormula:function(neg,inv,conj){
				return (neg?'-':'')+'x'+(conj?'^*':'')+'['+(inv?'-':'')+'n]';
			},
			freqFormula:function(neg,inv,conj){
				return (neg?'-':'')+'X'+(conj?'^*':'')+'(e^{'+(inv?'-':'')+'j\\omega})';
			}
		},{
			name:'Discrete Fourier transform (DFT)',
			timeFormula:function(neg,inv,conj){
				return (neg?'-':'')+'x'+(conj?'^*':'')+'['+(inv?'-':'')+'n]';
			},
			freqFormula:function(neg,inv,conj){
				return (neg?'-':'')+'X'+(conj?'^*':'')+'['+(inv?'-':'')+'k]';
			}
		}
	];
	$('.signal-transform-properties').each(function(){
		var tableElm=$(this);
		var transformElm=tableElm.find('caption');
		var transformSelectElm=null;
		transformElm.wrapInner("<span class='signal-transform-dropdown'>");
		var transformDropdownElm=transformElm.find('.signal-transform-dropdown');
		transformDropdownElm.click(function(){
			if (transformSelectElm===null) {
				transformSelectElm=$("<ul class='transform-select' />");
				transforms.forEach(function(transform){
					transformSelectElm.append(
						$("<li>"+transform.name+"</li>").click(function(){
							transformSelectElm.remove();
							transformSelectElm=null;
							transformDropdownElm.text(transform.name);
							tableElm.find('tbody').children('tr').each(function(i){
								$(this).children('td').text(function(j){
									if (i==0 && j==0) return '$$'+transform.timeFormula(1,1,1)+'$$'; if (i==0 && j==1) return '$$'+transform.timeFormula(1,1,0)+'$$';
									if (i==0 && j==4) return '$$'+transform.freqFormula(1,0,1)+'$$'; if (i==0 && j==5) return '$$'+transform.freqFormula(1,1,0)+'$$';
									// TODO the rest
									return '';
								});
							});
							MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
						})
					);
				});
				transformElm.append(transformSelectElm);
			} else {
				transformSelectElm.remove();
				transformSelectElm=null;
			}
		});
	});
});

@@ -590,16 +590,230 @@
 %09%09%7D%0A%09%5D;%0A
+%09var timePatterns=%5B%0A%09%09%5B%5B1,1,1%5D,%5B1,1,0%5D,null%5D,%0A%09%09%5B%5B1,0,1%5D,%5B0,0,0%5D,%5B0,0,1%5D%5D,%0A%09%09%5Bnull,   %5B0,1,0%5D,%5B0,1,1%5D%5D%0A%09%5D;%0A%09var freqPatterns=%5B%0A%09%09%5B%5B1,0,1%5D,%5B1,1,0%5D,null%5D,%0A%09%09%5B%5B1,1,1%5D,%5B0,0,0%5D,%5B0,1,1%5D%5D,%0A%09%09%5Bnull,   %5B0,1,0%5D,%5B0,0,1%5D%5D%0A%09%5D;%0A
 %09$('.sig
@@ -1616,322 +1616,425 @@
 %09%09%09%09
-if (i==0 && j==0) return '$$'+transform.timeFormula(1,1,1)+'$$'; if (i==0 && j==1) return '$$'+transform.timeFormula(1,1,0)+'$$';%0A%09%09%09%09%09%09%09%09%09if (i==0 && j==4) return '$$'+transform.freqFormula(1,0,1)+'$$'; if (i==0 && j==5) return '$$'+transform.freqFormula(1,1,0)+'$$';%0A%09%09%09%09%09%09%09%09%09// TODO the rest%0A%09%09%09%09%09%09%09%09%09return '';
+var pattern,formula;%0A%09%09%09%09%09%09%09%09%09if (j%3C3) %7B%0A%09%09%09%09%09%09%09%09%09%09pattern=timePatterns%5Bi%5D%5Bj%5D;%0A%09%09%09%09%09%09%09%09%09%09formula=transform.timeFormula;%0A%09%09%09%09%09%09%09%09%09%7D else if (j%3E3) %7B%0A%09%09%09%09%09%09%09%09%09%09pattern=freqPatterns%5Bi%5D%5Bj-4%5D;%0A%09%09%09%09%09%09%09%09%09%09formula=transform.freqFormula;%0A%09%09%09%09%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09%09%09%09%09pattern=null;%0A%09%09%09%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09%09%09%09if (pattern===null) %7B%0A%09%09%09%09%09%09%09%09%09%09return '';%0A%09%09%09%09%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09%09%09%09%09return '$$'+formula.apply(null,pattern)+'$$';%0A%09%09%09%09%09%09%09%09%09%7D
 %0A%09%09%09

update all formulas