//an anonymous function wraps our code to keep our variables
//in function scope rather than in the global namespace:
	var tree; //will hold our TreeView instance
	

	var conditions = ["Allergies",
	"Alzheimer\’s",
	"Aging",
	"Arthritis",
	"Arteriosclerosis",
	"Autism",
	"Brain Tumor",
	"Breast Cancer",
	"Cancer",
	"Chronic Fatigue",
	"Coronary Heart Disease",
	"Depression",
	"Diabetes",
	"Giant-Cell Arthritis",
	"Heart Decease",
	"Hypertension"];

	var conditions2 = ["Infertility",
    "Insomnia",
    "IBS",
    "Joints and Bones",
    "Parkinsons Decease",
    "Perimenopause",
    "Leukemia",
    "Lung Cancer",
    "Migraine",
    "Neurological Disorders",
    "Obesity",
    "Psychological Disorders",
    "Rheumatoid Arthritis",
    "Stress-Anxiety-Depression",
    "Stroke",
    "Thyroid Disease"];

	function treeInit() {
		
		//Hand off ot a method that randomly generates tree nodes:
		buildRandomTextNodeTree();
		

	}

	function getTableStructure(){
	
		return "<table> <tr> <td><div id='condtreeDiv1' </td> <td><div id='condtreeDiv2'></div></td> </tr></table>";

	}
	
	//This method will build a TreeView instance and populate it with
	//between 3 and 7 top-level nodes
	function buildRandomTextNodeTree() {

		maintree = new YAHOO.widget.TreeView("treeDiv1");
		var tmpNode = new YAHOO.widget.MenuNode("Conditions", maintree.getRoot(), true);
		var htmlNode = new YAHOO.widget.MenuNode(getTableStructure(), tmpNode, false);
		maintree.draw();

		//instantiate the tree:
		tree = new YAHOO.widget.TreeView("condtreeDiv1");
		buildBranch(tree.getRoot(),conditions,true);
		tree.draw();

		condtree2 = new YAHOO.widget.TreeView("condtreeDiv2");
		buildBranch(condtree2.getRoot(),conditions2,false);
		condtree2.draw();
	}


	function getPractionersLabel(){
		return '<a href="../practitioners/practitioners.html" target="content">Practitioners</a>';
	}

	function getTherapiesLabel(){
		return '<a href="../therapies/therapies.html" target="content">Therapy</a>';
	}


	//This function adds a random number <4 of child nodes to a given
	//node, stopping at a specific node depth:
	function buildRandomTextBranch(node) {
		var tmpNode = new YAHOO.widget.MenuNode(getTherapiesLabel(), node, false);
		 tmpNode = new YAHOO.widget.MenuNode(getPractionersLabel(), node, false);
		 tmpNode = new YAHOO.widget.MenuNode("Organizations", node, false);
		 tmpNode = new YAHOO.widget.MenuNode("Groups", node, false);
	}

	function buildBranch(node,names,flag) {
	
		if(node && names){
			for(var i=0; i<names.length;i++){
				var  isExpand = false;
				if(i==12 && flag){
					isExpand = true;
				}

				var tmpNode = new YAHOO.widget.MenuNode(names[i], node, isExpand);
				buildRandomTextBranch(tmpNode);
			}
		}
	}
