/* creates the markup for the leaf tree navigation */
// determine if current page is either a product or department page
	var isProdDept = (((window.location.href).indexOf('product.asp') > -1) || ((window.location.href).indexOf('dept.asp') > -1))? true : false;
function draw_leaf_tree(){
  var base_dept=500;  	//20090119 - WCD - Changed as per request in SUP34670 - changed base_dept to 500 (from 10) and unquoted it so it would evaluate as an int instead of a string.
  var passed_base=false; //20090119 - WCD - Changed as per request in SUP34670 - passed_base[sic] was set to true, leaving a dangling else; changed to false.
  var leafTreeMkup = "";

	if ((typeof(leaf_tree)!="nothing")&&(leaf_tree.length>0)){
		for (var i=leaf_tree.length-1;i>=0;i--){
			if (passed_base && leaf_tree[i].dept_name.indexOf("Navigation")==-1){
				//link and name
				leafTreeMkup += "<a class=\"leaftree\" href=\"" + leaf_tree[i].dept_link + "\">" + leaf_tree[i].dept_name + "<\/a>";
			}else{
				if (leaf_tree[i].dept_id==base_dept){
					passed_base=true;
					//HOME link and HOME name
					//20090119 - WCD - Changed as per request in SUP34670
					//http://www.cavaliersteamshop.com/fangear/search2.asp?search_freetext=cavs
					leafTreeMkup += "<a class=\"leaftree\" href=\"search2.asp?search_freetext=cavs\" onclick=\"return(visitargs('search2.asp','?search_freetext=cavs',''))\">CAVS<\/a>";
					
				}
			}
		}
		
	}else{
		if(!isProdDept){
			// just show home link if not product or department page and leaftree is empty
			leafTreeMkup += "<a class=\"leaftree\" href=\"default.asp\" onclick=\"return(visitargs('default.asp','',''))\">Shop<\/a>";
		}
	}
  return leafTreeMkup;
}

/* displays the table with leaf tree stuff inside */
function display_leaf_tree(){
	var tblId = (isProdDept)? "leaftreeTbl" : "leaftreeTblLong";
	var leafTreeMkup = "";
	leafTreeMkup += "<!-- FEATURE BEGIN: 505 - Leaf Tree Navigation, edit:jat, created:11.SEPT.2007 -->\n";
	//leafTreeMkup += "<div style=\"height:24px;width:647px;position:relative;left:3px;top:5px;padding:10px 5px 0px 5px;background:url(assets/images/leaftree_full_bg.gif) no-repeat;\">";
	leafTreeMkup += "<table cellspacing=\"0\" cellpadding=\"0\" id=\"" + tblId + "\"><tr valign=\"middle\"><td align=\"left\" style=\"padding:0px 0px 0px 5px;\"><div id=\"leafLinkDiv\">";
	leafTreeMkup += draw_leaf_tree();
	leafTreeMkup += "</div></td><td align=\"right\" style=\"font-size:8px;color:#727272;padding-right:10px;\">";
	leafTreeMkup += "<a class=\"printthis\" href=\"javascript:window.print()\">PRINT THIS PAGE&nbsp;<img border=\"0\" src=\"assets/images/print_arrow.gif\" /></a>";
	leafTreeMkup += "</td></tr></table>";
	//leafTreeMkup += "</div>";
	//leafTreeMkup += "<br/><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr valign=\"middle\">";
	//leafTreeMkup += "<td height=\"24\" class=\"leafTreeBg\" align=\"left\"><img width=\"8\" height=\"24\" src=\"assets/images/leaftree_header.gif\"/>&nbsp;" + draw_leaf_tree();
	//leafTreeMkup += "</td><td  height=\"24\" width=\"7\"><img width=\"7\" height=\"24\" src=\"assets/images/leaftree_footer.gif\" align=\"right\"/></td></tr></table>";
	leafTreeMkup += "\n<!-- FEATURE END: 505 - Leaf Tree Navigation -->\n";
	document.write(leafTreeMkup);
}