// JavaScript Document
var pix=0
var t
function hideAddress()
{
	window.scrollBy(0,1);
	pix++
	if(pix<6){
    	t=setTimeout(hideAddress, 100)
	}
	else
	{
		clearTimeout(t)	
	}
}

function iniCode()
{
	var RnaCode=document.getElementById('c1').innerHTML+document.getElementById('c2').innerHTML+document.getElementById('c3').innerHTML
	var ProCode=getAA(RnaCode)
	var selObj=document.getElementById("aalist")
	for (i=0;i<selObj.length;i++)
    {
    	if (selObj.options[i].value==ProCode)
		{
			selObj.options[i].selected=true
		}
		else
		{
			selObj.options[i].selected=false
		}
    }
	document.getElementById('pic1').src='img/aa/'+ProCode+'.jpg'
	document.getElementById('pic2').src='img/aa/'+ProCode+'3d.jpg'
	document.getElementById('txt').innerHTML="Also serves as an initiation site: the first AUG in an mRNA's coding region is where translation into protein begins."
}

function tapCode(obj)
{
	switch (obj.innerHTML)
	{
		case "A":
			obj.innerHTML="U"
			break
		case "U":
			obj.innerHTML="C"
			break
		case "C":
			obj.innerHTML="G"
			break
		case "G":
			obj.innerHTML="A"
			break
	}
	var RnaCode=document.getElementById('c1').innerHTML+document.getElementById('c2').innerHTML+document.getElementById('c3').innerHTML
	var ProCode=getAA(RnaCode)
	var selObj=document.getElementById("aalist")
	for (i=0;i<selObj.length;i++)
    {
    	if (selObj.options[i].value==ProCode)
		{
			selObj.options[i].selected=true
		}
		else
		{
			selObj.options[i].selected=false
		}
    }
	getAAtxt(ProCode)
}

function getAA(RnaCode)
{
	if (RnaCode == "UUU" || RnaCode == "UUC") {
		ProCode = "F";
	} else if (RnaCode == "UUA" || RnaCode == "UUG" || RnaCode == "CUU" || RnaCode == "CUC" || RnaCode == "CUA" || RnaCode == "CUG") {
		ProCode = "L";
	} else if (RnaCode == "AUU" || RnaCode == "AUC" || RnaCode == "AUA") {
		ProCode = "I";
	} else if (RnaCode == "AUG") {
		ProCode = "M";
	} else if (RnaCode == "GUU" || RnaCode == "GUC" || RnaCode == "GUA" || RnaCode == "GUG") {
		ProCode = "V";
	} else if (RnaCode == "UCU" || RnaCode == "UCC" || RnaCode == "UCA" || RnaCode == "UCG" || RnaCode == "AGU" || RnaCode == "AGC") {
		ProCode = "S";
	} else if (RnaCode == "CCU" || RnaCode == "CCC" || RnaCode == "CCA" || RnaCode == "CCG") {
		ProCode = "P";
	} else if (RnaCode == "ACU" || RnaCode == "ACC" || RnaCode == "ACA" || RnaCode == "ACG") {
		ProCode = "T";
	} else if (RnaCode == "GCU" || RnaCode == "GCC" || RnaCode == "GCA" || RnaCode == "GCG") {
		ProCode = "A";
	} else if (RnaCode == "UAU" || RnaCode == "UAC") {
		ProCode = "Y";
	} else if (RnaCode == "UAA") {
		ProCode = "Ochre";
	} else if (RnaCode == "UAG") {
		ProCode = "Amber";
	} else if (RnaCode == "UGA") {
		ProCode = "Opal";
	} else if (RnaCode == "CAU" || RnaCode == "CAC") {
		ProCode = "H";
	} else if (RnaCode == "CAA" || RnaCode == "CAG") {
		ProCode = "Q";
	} else if (RnaCode == "AAU" || RnaCode == "AAC") {
		ProCode = "N";
	} else if (RnaCode == "AAA" || RnaCode == "AAG") {
		ProCode = "K";
	} else if (RnaCode == "GAU" || RnaCode == "GAC") {
		ProCode = "D";
	} else if (RnaCode == "GAA" || RnaCode == "GAG") {
		ProCode = "E";
	} else if (RnaCode == "UGU" || RnaCode == "UGC") {
		ProCode = "C";
	} else if (RnaCode == "UGG") {
		ProCode = "W";
	} else if (RnaCode == "CGU" || RnaCode == "CGC" || RnaCode == "CGA" || RnaCode == "CGG" || RnaCode == "AGA" || RnaCode == "AGG") {
		ProCode = "R";
	} else if (RnaCode == "GGU" || RnaCode == "GGC" || RnaCode == "GGA" || RnaCode == "GGG") {
		ProCode = "G";
	}
	return ProCode
}

function getAAtxt(ProCode)
{
	var obj=document.getElementById('txt')
	switch (ProCode)
	{
		case "F":
			obj.innerHTML="Essential amino acid. Nonpolar, electrically neutral amino acid. Codon: UUU and UUC."
			break
		case "L":
			obj.innerHTML="Essential amino acid. Hydrophobic. Codon: UUA, UUG, CUU, CUC, CUA, and CUG."
			break
		case "I":
			obj.innerHTML="Essential amino acid. Hydrophobic. Codon: AUU, AUC and AUA."
			break
		case "M":
			obj.innerHTML="Also serves as an initiation site: the first AUG in an mRNA's coding region is where translation into protein begins."
			break
		case "V":
			obj.innerHTML="Essential amino acid. Nonpolar, hydrophobic. Codon: GUU, GUC, GUA, and GUG."
			break
		case "S":
			obj.innerHTML="Bearing an alcohol group. Polar amino acid. Codon: UCU, UCC, UCA, UCG, AGU and AGC."
			break
		case "P":
			obj.innerHTML="Unique among the 20 protein-forming amino acids as the a-amino group is secondary. Codon: CCU, CCC, CCA, and CCG."
			break
		case "T":
			obj.innerHTML="Essential amino acid. Bearing an alcohol group. Codon: ACU, ACA, ACC, and ACG."
			break
		case "A":
			obj.innerHTML="Non-polar amino acid. Codon: GCU, GCC, GCA, and GCG."
			break
		case "Y":
			obj.innerHTML="Important in signal transduction proteins, functions as a receiver of phosphate groups. Codon: UAU and UAC."
			break
		case "H":
			obj.innerHTML="Essential amino acid. Bearing imidazole side chains. Relatively neutral pKa. Codon: CAU and CAC."
			break
		case "Q":
			obj.innerHTML="Its side chain is an amide. Codon: CAA and CAG."
			break
		case "N":
			obj.innerHTML="It has carboxamide as the side chain's functional group. Codon: AAU and AAC."
			break
		case "K":
			obj.innerHTML="Essential amino acid. Lysine is a base, as are arginine and histidine. Codon: AAA and AAG."
			break
		case "D":
			obj.innerHTML="The carboxylate anion of aspartic acid is known as aspartate. Acidic amino acid with a pKa of 4.0. Codon: GAU and GAC."
			break
		case "E":
			obj.innerHTML="The carboxylate anion of glutamic acid is known as glutamate. Acidic amino acid with a pKa of 4.1. Codon: GAA and GAG."
			break
		case "C":
			obj.innerHTML="Hydrophilic amino acid. Codon: UGU and UGC."
			break
		case "W":
			obj.innerHTML="Essential amino acid. Contains an indole functional group. Codon: TGG."
			break
		case "R":
			obj.innerHTML="Semiessential amino acid. Basic with a pKa of 12.48. Codon: CGU, CGC, CGA, CGG, AGA, and AGG."
			break
		case "G":
			obj.innerHTML="Often evolutionarily conserved. Unique amino acid that is not optically active. Codon: GGU, GGC, GGA and GGG."
			break
		default:
			obj.innerHTML="Also called termination codon. No cognate tRNAs with anticodons that complement to these stop signals."
			break
	}

	if(ProCode.length>1)
	{
		document.getElementById("pic1").style.visibility="hidden";
		document.getElementById("pic2").style.visibility="hidden";
	}
	else
	{
		document.getElementById("pic1").src="img/aa/"+ProCode+".jpg";
		document.getElementById("pic2").src="img/aa/"+ProCode+"3d.jpg";
		document.getElementById("pic1").style.visibility="visible";
		document.getElementById("pic2").style.visibility="visible";
	}
	
}

function share()
{
	if(confirm("Would you like to share this Web App with your friends?"))
	{
		var tmp="mailto:?subject="+encodeURI("New iPhone Web App recommended from your friend!");
		tmp=tmp+"&body="+encodeURI("Genetic decoder<br>>> <a href='http://www.biocourseware.com/iphone/genecode/'>Look at it now</a>");	
		window.location.href=tmp;
	}
}