var left_nav = {
	//function toggleNode
	tn: function(e, id) {
		//change the class 
		var node = document.getElementById(id);
		if (node) {
			if (window.getSelection && window.getSelection()) {
				window.getSelection().collapseToStart();
			}
			//toggle the class name from one with _exp at the end to one without
			var parts = node.className.match(/^(.*?)([0-9]*?)(_exp)?$/);
			node.className =parts[1]+((parts[3]=='_exp')?'':'_exp');

			var kids = document.getElementById(id+'.kids');
			if (kids) {
				//toggle the visibility
				if (kids.style.display != 'none') {
					kids.style.display='none';
				} else {
					kids.style.display='block';
				}
			} else {
				//write out a 'Loading...' node temporaryly and make 
				//an ajax call to fill it up
				/*
				var depth = parts[2];
				if (depth=='') depth = 1;
				kids = document.createElement('UL');
				var loading = document.createElement('LI');
				kids.appendChild(loading);
				node.appendChild(kids);
				kids.id = node.id+'.kids';
				loading.innerHTML = "Loading...";
				loading.className = parts[1]+(depth+1)+'_noExp';
				loading.onclick = left_nav.cancelBubble;
				*/
				var loading = document.createElement('DIV');
				loading.id = node.id+'.loading';
				node.appendChild(loading);
				loading.innerHTML = "Loading...";
				// Tree can now have a third level expansion, if so the id will split into three
				var arrIDPieces = new Array();
				arrIDPieces = id.split('.');
				var numExp = arrIDPieces.length;
				var type = arrIDPieces[0];
				var head1 = '';
				var head2 = '';
				// If there are only two elements, only pass head1
				var head1 = arrIDPieces[1].replace('n','');
				// otherwise there is a third level expansion, pass head2 as well
				if (numExp == 3) {
					var head2 = arrIDPieces[2].replace('n','');
				}
				addTreeChunk(e,node,type,head1,head2);
			}
			this.cancelBubble(e);
		}
	},
	cancelBubble: function (e) {
		if (window.getSelection && window.getSelection()) {
			window.getSelection().collapseToStart();
		}
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		if (e.target) e.target.blur();
	}
}

function addTreeChunk(e, element, type, head, head2)
{
	var xmlHttp;
	try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	// Internet Explorer
	try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	catch (e)
	  {
	  try
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  catch (e)
		{
		//alert("Your browser does not support AJAX!");
		return false;
		}
	  }
	}
	xmlHttp.onreadystatechange=function()
	  {
	  if(xmlHttp.readyState==4)
		{
		var loading = document.getElementById(element.id+'.loading');
		element.removeChild(loading);
		element.innerHTML += xmlHttp.responseText;
		return true;
		}
	  }
	// If head2 contains an ID this is a third level drill down and need to include additional url variable
	// presence of a value for head2 will trigger display differences on menu end
	var url = "/cftemplates/tree.cfm?ajax=1&type=" + type + "&head1=" + head + "&head2=";
	if(head2 != '') {
		url = url + head2;
	}
	// If this is leed, pass in additional page and query information to maintain page context across
	// both leed nav locations
	if(type=='LEED') {
        var param = "";
		var loc = location.href;
		var locParts = loc.split('/');
		var page = locParts[3]+'/'+locParts[4].split('?')[0];
		var pageParams = locParts[4].split('&')[0];
		// Pass the page calling left nav, mainatin nav across pages when ajax involved
		url = url + '&page='+ page;
		
		// only interested in first url param to check if it is a credit id
		if(pageParams.indexOf('?') != -1) {
			param = pageParams.split('?')[1];
			// If the first query param is LEEDCreditID pass it in url
			// it is needed to maintain page display, otherwise pass empty param.
			if(param.indexOf('LEEDCreditID') != -1) {
				url = url + '&pageParam=' + param;	
			}
		}
	}
	//xmlHttp.open("GET","/cftemplates/tree.cfm?ajax=1&type=" + type + "&head1=" + head,true);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function preloadImages() {
	//background image
	imgBackground = new Image();
	imgBackground.src = "/nav_images/content.gif";
	
	//rollovers
	imgGT = new Image();
	imgCSI = new Image();
	imgLEED = new Image();
	imgGP = new Image();
	imgHPB = new Image();
	imgNews = new Image();
	
	imgGTov = new Image();
	imgCSIov = new Image();
	imgLEEDov = new Image();
	imgGPov = new Image();
	imgHPBov = new Image();
	imgNewsov = new Image();
	
	imgGT.src = '/nav_images/green_topics.jpg';
	imgCSI.src = '/nav_images/csi_divs.jpg';
	imgLEED.src = '/nav_images/green_topics.jpg';
	imgGP.src = '/nav_images/leed_credits.jpg';
	imgHPB.src = '/nav_images/prod_listings.jpg';
	imgNews.src = '/nav_images/projects.jpg';
	
	imgGTov.src = '/nav_images/green_topics_ov.jpg';
	imgCSIov.src = '/nav_images/csi_divs_ov.jpg';
	imgLEEDov.src = '/nav_images/green_topics_ov.jpg';
	imgGPov.src = '/nav_images/leed_credits_ov.jpg';
	imgHPBov.src = '/nav_images/prod_listings_ov.jpg';
	imgNewsov.src = '/nav_images/projects_ov.jpg';

	
}
