//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 alterTherapies = ["Acupuncture", 
	"Aromatherapy",
    "Ayurveda",
    "Breathwork",
    "Buteyko",
    "Chinese Medicine",
    "Colonic Cleansing",
    "Color Therapy",
    "Energy Medicine",
    "Flower Essences",
    "Gemstone Therapy",
    "Homeopathy",
    "Humor Therapy",
    "Hydrotherapy"];

	var	alterTherapies2 = [
    "Iridology",
    "Magnets",
    "Massage Therapy",
    "Macrobiotics",
    "Meditation",
    "Mind-Body Medicine",
    "Music Therapy",
    "Naturopathy",
    "Reiki",
    "Shiatsu",
    "Somatic Education",
    "Tai Chi",
    "Therapeutic Touch",
    "Yoga"];

	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("Alternative Therapies", 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(),alterTherapies,true);
		tree.draw();

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


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

	//This function adds a random number <4 of child nodes to a given
	//node, stopping at a specific node depth:
	function buildRandomTextBranch(node) {
		 //tmpNode = new YAHOO.widget.MenuNode("Therapy", node, false);
		var 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) {
	
		if(node && names){
			for(var i=0; i<names.length;i++){
				var tmpNode = new YAHOO.widget.MenuNode(names[i], node, false);
				buildRandomTextBranch(tmpNode);
			}
		}
	}


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

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