// Find and replace
var start = "<a class=\"foundtext\" href=\""
var mid1 = "\" onmouseover=\"setClass("
var mid2 = ")\" onmouseout=\"clearClass('popUpMessage"
var mid3 = "')\">"
var popupbox1 = "</a><div id=\"popUpMessage"
var end = "\" class=\"PopUp\"></div>"

var recipeneeds = document.getElementById('recipeneeds').innerHTML;

var a = new Array();
a=recipeneeds.split("  ");

// Items to be replaced - needs to match up with the values in the c array. 

b = new Array();
b[0] = /avocado/i;
b[1] = /beef/i;
b[2] = /bison/i;
b[3] = /broccoli/i;
b[4] = /buttercup squash/i;
b[5] = /carrots/i;
b[6] = /chicken/i;
b[7] = /leeks/i;
b[8] = /onion/i;
b[9] = /orange/i; 
b[10] = /pineapple/i;
b[11] = /pork/i;
b[12] = /potato/i; 
b[13] = /quinoa/i;
b[14] = /rice/i;
b[15] = /sweet potato/i;
b[16] = /tomatoes/i;
b[17] = /turkey/i;
b[18] = /oats/i;
b[19] = /peaches/i;
b[20] = /beet/i;

// Stuff that it will be replaced with. 

c = new Array();
c[0] = start + "../food-info/avocado.shtml" + mid1 + "'<h3>Avocados</h3><ul><li>Most popular variety is the Hass avocados which are available year round.</li><li>High in protein and high in fat.</li></ul>Click to learn more!<br />', '0'" + mid2 + '0' + mid3 + "avocado" + popupbox1 + '0' + end;
c[1] = start + "../food-info/beef.shtml" + mid1 + "'<h3>Beef</h3><ul><li>Beef is cut into primal cuts. The primal cuts are then cut into more specific cuts.</li><li>Grass fed beef is leaner and has a stronger flavor than non-grass fed beef.</li></ul>Click to learn more!<br />', '1'" + mid2 + '1' + mid3 + "beef" + popupbox1 + '1' + end;
c[2] = start + "../food-info/bison.shtml" + mid1 + "'<h3>Bison</h3><ul><li>Is leaner than beef and has a less domestic flavor than beef.</li><li>Because it is so lean, cooks much faster than other meats.</li></ul>Click to learn more!<br />', '2'" + mid2 + '2' + mid3 + "bison" + popupbox1 + '2' + end;
c[3] = start + "../food-info/broccoli.shtml" + mid1 + "'<h3>Broccoli</h3><ul><li>Broccoli is high in protein, fiber, Vitamin C and many other nutrients.</li><li>A member of the cabbage family.</li></ul>Click to learn more!<br />', '3'" + mid2 + '3' + mid3 + "broccoli" + popupbox1 + '3' + end;
c[4] = start + "../food-info/buttercup_squash.shtml" + mid1 + "'<h3>Buttercup Squash</h3><ul><li>A winter squash with outer rind and sweet orangish-colored interior.</li><li>Sweeter and dryer than other squashes.</li></ul>Click to learn more!<br />', '4'" + mid2 + '4' + mid3 + "buttercup squash" + popupbox1 + '4' + end;
c[5] = start + "../food-info/carrot.shtml" + mid1 + "'<h3>Carrots</h3><ul><li>High in starch, fiber and Vitamin A.</li><li>The carrot can produce an alcoholic liquid.</li></ul>Click to learn more!<br />', '5'" + mid2 + '5' + mid3 + "carrots" + popupbox1 + '5' + end;
c[6] = start + "../food-info/chicken.shtml" + mid1 + "'<h3>Chicken</h3><ul><li>The white meat comes from muscles used in short bursts.</li><li>The dark meat comes from muscles used more often.</li></ul>Click to learn more!<br />', '6'" + mid2 + '6' + mid3 + "chicken" + popupbox1 + '6' + end;
c[7] = start + "../food-info/leeks.shtml" + mid1 + "'<h3>Leeks</h3><ul><li>Lighter in flavor than onions or garlic.</li><li>Younger leeks will contain less fiber.</li></ul>Click to learn more!<br />', '7'" + mid2 + '7' + mid3 + "leeks" + popupbox1 + '7' + end;
c[8] = start + "../food-info/onion.shtml" + mid1 + "'<h3>Onions</h3><ul><li>The strong flavor comes from sulfides in the onion.</li><li>Spring onions have a milder flavor than other onion varieties.</li></ul>Click to learn more!<br />', '8'" + mid2 + '8' + mid3 + "onion" + popupbox1 + '8' + end;
c[9] = start + "../food-info/orange.shtml" + mid1 + "'<h3>Oranges</h3><ul><li>A member of the citrus family, oranges are high in Vitamin C, fiber and calcium.</li><li>The Valencia variety is juicier than the navel variety but he navel variety is meatier.</li></ul>Click to learn more!<br />', '9'" + mid2 + '9' + mid3 + "orange" + popupbox1 + '9' + end;
c[10] = start + "../food-info/pineapple.shtml" + mid1 + "'<h3>Pineapple</h3><ul><li>A tropical fruit that does best in warmer climates.</li><li>Bromelain, an enzyme found in pineapple, makes pineapple juice good at tenderizing meat.</li></ul>Click to learn more!<br />', '10'" + mid2 + '10' + mid3 + "pineapple" + popupbox1 + '10' + end;
c[11] = start + "../food-info/pork.shtml" + mid1 + "'<h3>Pork</h3><ul><li>Is a red meat not white.</li><li>Pigs have been domesticated on a diet of corn, barley, wheat and other grains allowing pigs to create more meat.</li></ul>Click to learn more!<br />', '11'" + mid2 + '11' + mid3 + "pork" + popupbox1 + '11' + end;
c[12] = start + "../food-info/potato.shtml" + mid1 + "'<h3>Potato</h3><ul><li>Russet potatoes, the most common variety, contain less moisture than other varieties.</li><li>The potato is a good source of carbohydrates, fiber and vitamin C.</li></ul>Click to learn more!<br />', '12'" + mid2 + '12' + mid3 + "potato" + popupbox1 + '12' + end;
c[13] = start + "../food-info/quinoa.shtml" + mid1 + "'<h3>Quinoa</h3><ul><li>Quinoa is actually a seed of a plant in the that happens to cook like a grain.</li><li>Quinoa flour provides a great substitute for wheat flour.</li></ul>Click to learn more!<br />', '13'" + mid2 + '13' + mid3 + "quinoa" + popupbox1 + '13' + end;
c[14] = start + "../food-info/rice.shtml" + mid1 + "'<h3>Rice</h3><ul><li>Brown rice is a whole grain and contains more fiber than white rice.</li><li>Rice provides over half of the daily calories for almost half of the world.</li></ul>Click to learn more!<br />', '14'" + mid2 + '14' + mid3 + "rice" + popupbox1 + '14' + end;
c[15] = start + "../food-info/sweet-potato.shtml" + mid1 + "'<h3>Sweet Potato</h3><ul><li>The sweet potato derives its sweetness from starch, which becomes sweeter when cooked.</li><li>In the US, the majority of sweet potatoes are grown in North Carolina.</li></ul>Click to learn more!<br />', '15'" + mid2 + '15' + mid3 + "sweet potato" + popupbox1 + '15' + end;
c[16] = start + "../food-info/tomato.shtml" + mid1 + "'<h3>Tomatoes</h3><ul><li>The tomato is a member of the nightshade family related to peppers and potatoes.</li><li>Globe tomatoes, the most popular type, are juicy than other varieties.</li></ul>Click to learn more!<br />', '16'" + mid2 + '16' + mid3 + "tomatoes" + popupbox1 + '16' + end;
c[17] = start + "../food-info/turkey.shtml" + mid1 + "'<h3>Turkey</h3><ul><li>The majority of the turkey is the white meat</li><li>Is a descendent of the wild turkey and native to North America.</li></ul>Click to learn more!<br />', '17'" + mid2 + '17' + mid3 + "turkey" + popupbox1 + '17' + end;
c[18] = start + "../food-info/oats.shtml" + mid1 + "'<h3>Oats</h3><ul><li>Rolled oats cook faster than other varieties.</li><li>Are gluten free and therefore do not rise when baked.</li></ul>Click to learn more!<br />', '18'" + mid2 + '18' + mid3 + "oats" + popupbox1 + '18' + end;
c[19] = start + "../food-info/peaches.shtml" + mid1 + "'<h3>Peaches</h3><ul><li>High in Vitamin C and fiber</li><li>Is a stone fruit (named because of the outer shell of the seed.)</li><li>Native to China</li></ul>Click to learn more!<br />', '19'" + mid2 + '19' + mid3 + "peaches" + popupbox1 + '19' + end;
c[20] = start + "../food-info/beets.shtml" + mid1 + "'<h3>Beets</h3><ul><li>Most beets contain 3% sugar; sugar beets contain up to 20%.</li><li>High in fiber and many vitamins, including vitamin C</li><li>Water soluble pigments will stain any liquid it is cooked in</li></ul>Click to learn more!<br />', '20'" + mid2 + '20' + mid3 + "beets" + popupbox1 + '20' + end;

// Run the replace. 

for(var i = 0 ; i < a.length ; i ++ ) {
    for (var j = 0 ; j < b.length ; j ++) {
        if (a[i].search(b[j]) != -1) {
            a[i] = a[i].replace(b[j],c[j]); 
        }
   }    
}

for(var i = 0 ; i < a.length ; i ++ ) {
	document.getElementById('recipeneeds').innerHTML = a[i];
}

// Text swap

function changeImage(foodnotes, popUpMessage) {
	var newImage = foodnotes
	document.getElementById(popUpMessage).innerHTML = newImage;
}
function setClass(imageURL, popupid) {
	var popUpMessage = "popUpMessage" + popupid;
	var object = document.getElementById(popUpMessage);
	object.className = 'PopUpShow';
	
	changeImage(imageURL, popUpMessage)
}
function clearClass(popUpMessage) {
	var object = document.getElementById(popUpMessage);
	object.className = 'PopUp';
}