LeftNav = {
	
	loadXML: function(xml, div, active) {
		try { // Internet Explorer
			var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		} catch(e) { // FF
			var xmlDoc = document.implementation.createDocument("", "", null);
		}
		xmlDoc.async = false;
		xmlDoc.load(xml);
		if(!xmlDoc) return;
		
		var navDiv = document.getElementById(div);
		
		var sections = xmlDoc.getElementsByTagName('section');
		
		for(var i = 0; i < sections.length; i++) 
		{
			var h6 = document.createElement('H6');
			h6.innerHTML = sections[i].getAttribute('name');
			navDiv.appendChild(h6);
			
			var sectionDiv = document.createElement('DIV');
			sectionDiv.className = 'section';
			sectionDiv.subCats = [];
			
			var subcategories = sections[i].getElementsByTagName('subcategory');
			for(var j = 0; j < subcategories.length; j++)
			{
				var subcatDiv = document.createElement('DIV');
				subcatDiv.className = 'subcat';
				
				var subcatLink = document.createElement('A');
				subcatLink.innerHTML = subcategories[j].getAttribute('name');
				if (subcategories[j].getAttribute('name') == 'View All Products') 
				{
					subcatLink.href = '/products/index-products.html';
					if(window.location.href.indexOf('/products/index-products.html') != -1)
						subcatLink.className = 'active-top';
				} else if (subcategories[j].getAttribute('name') == 'Other Products')  {
					subcatLink.href = '/products/other-basf-products.html';
					if(window.location.href.indexOf('/products/other-basf-products.html') != -1)
						subcatLink.className = 'active-top';
				} else {
					subcatLink.href = '';
				}

				subcatDiv.appendChild(subcatLink);
				
				var subItemsDiv = document.createElement('DIV');
				subItemsDiv.className = 'sub';
				
				var subItems = subcategories[j].getElementsByTagName('product');
				for(var k = 0; k < subItems.length; k++) 
				{
					var productLink = document.createElement('A');
					productLink.innerHTML = subItems[k].getElementsByTagName('name')[0].firstChild.nodeValue;
					productLink.href = subItems[k].getElementsByTagName('url')[0].firstChild.nodeValue;
					if(subItems[k].getElementsByTagName('id')[0].firstChild.nodeValue == active)
					{
						productLink.className = 'active';
						subcatDiv.className = 'subcat active';
					}
					subItemsDiv.appendChild(productLink);
				}
				subcatDiv.appendChild(subItemsDiv);
				sectionDiv.appendChild(subcatDiv);
				sectionDiv.subCats.push(subcatDiv);
			}
			
			navDiv.appendChild(sectionDiv);
		}

		this.init(div);
	},
	
	init: function(div) {
		var navDiv = document.getElementById(div);
		$(navDiv).find('div.subcat').each(function() {
			if($(this).find('a.active').length) {
				$(this).addClass('active');
			} else if(!$(this).children('a').get(0).getAttribute('href')) {
				$(this).find('div.sub').hide();
			}
		});
		
		$(navDiv).find('div.subcat > a').each(function() {
			if(!$(this).next().length || this.getAttribute('href')) return;
			this.onclick = function() {
				var subcatDivs = $(this.parentNode.parentNode).find('div.subcat');
				for(var m = 0; m < subcatDivs.length; m++)
				{
					$(subcatDivs[m]).find('div.sub').hide();
					$(subcatDivs[m]).removeClass('active');
				}
				$(this.parentNode).find('div.sub').show();
				$(this.parentNode).addClass('active');
				return false;
			};
		});
	}

};