(function ($) { function init() { // find all icon menu items and add event listeners $("#main-menu-links a.active").each(function(a) { $(this).width(190); $(this).hover( function () { $(this).width(190); }, function () { $(this).width(76); } ); }); $("#main-menu-links").each(function(a) { $(this).hover( function () { $("#main-menu-links a.active").width(76); }, function () { $("#main-menu-links a.active").width(190); } ); }); // Setup the Codon Optimizer $("#optimize-codons").click(function(c) { var map = Array(); map['TTT'] = 'TTC'; map['TTA'] = 'CTG'; map['TTG'] = 'CTG'; map['CTT'] = 'CTG'; map['CTC'] = 'CTG'; map['CTA'] = 'CTG'; map['ATA'] = 'ATC'; map['GTT'] = 'GTG'; map['GTA'] = 'GTC'; map['TCT'] = 'TCC'; map['TCA'] = 'TCG'; map['CCT'] = 'CCG'; map['CCA'] = 'CCC'; map['ACT'] = 'ACG'; map['ACA'] = 'ACC'; map['TAG'] = 'TGA'; map['CAA'] = 'CAG'; map['AAA'] = 'AAG'; map['TGT'] = 'TGC'; map['CGA'] = 'CGC'; map['CGT'] = 'CGC'; map['AGT'] = 'AGC'; map['AGA'] = 'AGG'; map['GGA'] = 'GGC'; map['GGT'] = 'GGC'; // Split the input string into chunks of 3 var codons = $('#old-codons').val().match(/.{1,3}/g); // Loop through each set of 3 and check if they match our conditions $.each(codons, function(index, value) { if(map[value]) { codons[index] = map[value]; } }); // Put our string back together and display it on the page $('#new-codons').html(codons.join('')); }); } $(function () { init(); }); })(jQuery);