﻿	
		
		// JavaScript Document

var openImg = new Image();
openImg.src = "images/minus.gif";
var closedImg = new Image();
closedImg.src = "images/plus.gif";


function showBranch(branch){
   var objBranch = 
   document.getElementById(branch).style;
   if (objBranch.display=="block")
      objBranch.display="none";
   else
      objBranch.display="block";
   swapFolder('I' + branch);
}

function swapFolder(img){
   objImg = document.getElementById(img);
   if (objImg.src.indexOf('images/plus.gif')>-1)
      objImg.src = openImg.src;
   else
      objImg.src = closedImg.src;
}

		
				function tree(){
				   this.branches = new Array();
				   this.add = addBranch;
				   this.write = writeTree;
				}
				
				function addBranch(branch){
				   this.branches[this.branches.length] = branch;
				}
				
				function writeTree(){
				   var treeString = '';
				   var numBranches = this.branches.length;
				   for (var i=0;i <numBranches;i++)
					  treeString += this.branches[i].write();
				   document.write(treeString);
				}
				
				function branch(id, text){
				   this.id = id;
				   this.text = text;
				   this.write = writeBranch;
				   this.add = addLeaf;
				   this.leaves = new Array();
				}
				
				function addLeaf(leaf){
				   this.leaves[this.leaves.length] = leaf;
				}
				
				function writeBranch(){
				    var branchString = '<span class="branch" ' +  'onClick="showBranch(\'' + this.id + '\')"';
					  branchString += '><img src="images/plus.gif" id="I' +  this.id + ' ">' + this.text;
				
				   branchString += '</span>';
				   branchString += '<span class="leaf" id="';
				   branchString += this.id + '">';
				   var numLeaves = this.leaves.length;
				   for (var j=0;j<numLeaves;j++)
					  branchString += this.leaves[j].write();
				   branchString += '</span>';
				   return branchString; 

				} 
				
				function leaf(text, link){
				   this.text = text;
				   this.link = link;
				   this.write = writeLeaf;
				}
				
				
				function writeLeaf(){
				var leafString = '<a href=recipe.php?id="' + this.link + '">';
				leafString += this.text;
				leafString += '</a><br>';
				return leafString;
				}

			