﻿//YAHOO.util.Event.addListener(window, "load", CreateTree);
YAHOO.util.Event.onAvailable("LRTree", CreateTree);
  
//var templateRootNode = "<img src=\"/images/bullet_arrow.gif\" align=\"absmiddle\" hspace=\"0\">&nbsp;&nbsp; {0}";
var templateRootNode = "&nbsp;&nbsp;{0}";
var templateChildNode = "<img src=\"/images/dot.gif\" align=\"absmiddle\"><a href=\"{0}\" class=\"sidemenu\">{1}</a>";
//var template = "<img src=\"/images/bullet_space.gif\" align=\"absmiddle\" >&nbsp;&nbsp;<a href=\"{0}\" class=\"sidemenu\">{1}</a>";
var template = "<img src=\"/images/bullet_space.gif\" align=\"absmiddle\"><a href=\"{0}\" class=\"sidemenu\">{1}</a>";

//var LRProjectId = 1;
//var UnitType = 3;
var nodes = [	
				{label: "Floor Plan", link: "", children: [{label: "Single", link: "LRProject_floorplan.aspx?LRProjectId="+LRProjectId+"&UnitType=2"},{label:"Duplex", link: "LRProject_floorplan.aspx?LRProjectId="+LRProjectId+"&UnitType=3"}]},
				{label: "Gallery", link: "LRProject_gallery.aspx?LRProjectId="+LRProjectId},
				{label: "Building Specifications", link: "LRProject_building_spec.aspx?LRProjectId="+LRProjectId},
				{label: "Room Specifications", link: "", children: [{label: "Single", link: "LRProject_room_spec.aspx?LRProjectId="+LRProjectId+"&UnitType=2"},{label:"Duplex", link: "LRProject_room_spec.aspx?LRProjectId="+LRProjectId+"&UnitType=3"}]},
				{label: "Location Map", link: "LRProject_location_map.aspx?LRProjectId="+LRProjectId},
				{label: "Services", link: "LRProject_services.aspx?LRProjectId="+LRProjectId},
				{label: "Construction Update", link: "LRProject_construction.aspx?LRProjectId="+LRProjectId},
				{label: "Virtual Tour", link: "LRProject_virtual_tour.aspx?LRProjectId="+LRProjectId},
				{label: "Video Presentation",  link: "LRProject_vdo_presentation.aspx?LRProjectId="+LRProjectId}
			];

if(LRProjectId == 3 || LRProjectId == 4) nodes[4].show = false; 
if(LRProjectId == 3 || LRProjectId == 4) nodes[7].show = false; 			
if(LRProjectId == 3 || LRProjectId == 4) nodes[8].show = false;   
  
if (FSingleType == "" && FDSingleType == "") nodes[0].children[0].show = false;
if (FDuplexType == "" && FDDuplexType == "") nodes[0].children[1].show = false;
nodes[0].show = nodes[0].children[0].show || nodes[0].children[1].show;
if (ChkGallery == "") nodes[1].show = false;
if (ChkBSpecification == "") nodes[2].show = false;
if (RSpecificationSingleType == "") nodes[3].children[0].show = false;
if (RSpecificationDuplexType == "") nodes[3].children[1].show = false;
nodes[3].show = nodes[3].children[0].show || nodes[3].children[1].show;
if (ChkService == "") nodes[5].show = false;
if (ChkConstruction == "") nodes[6].show = false;

function CreateTree() {
	var tree = new YAHOO.widget.TreeView("LRTree");
	var rootNode = tree.getRoot();
	for (var index = 0; index < nodes.length; index++) {
		var obj = nodes[index];
		var node = null;
		var show = (typeof(obj.show) == "undefined") ? true : obj.show;
		if (show && obj.children) {
		    node = new YAHOO.widget.TextNode(templateRootNode.replace("{0}",obj.label), rootNode, false);				
			node.expanded = true;			
			createNodes(node, obj.children);
		}  
		else if(show)
		{
		    var label = template.replace("{0}", obj.link).replace("{1}", obj.label);
		    node = new YAHOO.widget.HTMLNode(label, rootNode, false);
			node.contentStyle = "";
		}
	}
	tree.draw();
}

function createNodes(parent, nodes) {
	for(var index = 0; index < nodes.length; index++) {	    
	    var obj = nodes[index];	    
	    var show = (typeof(obj.show) == "undefined") ? true : obj.show;
	    if (show) {
	        var label = templateChildNode.replace("{0}", obj.link).replace("{1}", obj.label);
	        var node = new YAHOO.widget.HTMLNode(label, parent, false);
		    node.contentStyle = "";
		}
	}
}

