function init(){
	//Check to see if we can use the DOM
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	if(!document.createElement) return;
	
	//Get all the UL's in the sitemapigation
	var sitemapigation = document.getElementById('sitemap');
	var sitemapSub = sitemapigation.getElementsByTagName('ul');
	
	//Go through all the Sub sitemap's - give them a hidden class, inject in the toogle graphic
	for (i=0; i<sitemapSub.length; i++){
		
		//Create the Image to inject in
		var toggleImage = document.createElement('img');
		toggleImage.setAttribute('src', '/img/icons/expand.gif');
		toggleImage.style.cursor = "pointer";
		toggleImage.onclick = function() {
			togglesitemap(this);
		}
		
		//Get the Parent of the UL, and insert the Image before the first child
		sitemapSub[i].parentNode.insertBefore(toggleImage, sitemapSub[i].parentNode.firstChild);
		
		//Hide the Sub sitemapigation using a CSS Class and assign a class to the parent for styling
		sitemapSub[i].style.display="none";
		sitemapSub[i].parentNode.className = "expandable";
	}
	
}

function togglesitemap(whichOne){
	if (whichOne.getAttribute('id') == "expandAll") {
		var sitemapigation = document.getElementById('sitemap');
		var sitemapigationULs = sitemapigation.getElementsByTagName('ul');
		var allImages = sitemapigation.getElementsByTagName('img');
		for (i = 0; i < sitemapigationULs.length; i++) {
				sitemapigationULs[i].style.display = "block";
				allImages[i].setAttribute('src', '/img/icons/contract.gif')
		
		}
	}
	else if (whichOne.getAttribute('id') == "collapseAll"){
		var sitemapigation = document.getElementById('sitemap');
		var sitemapigationULs = sitemapigation.getElementsByTagName('ul');
		var allImages = sitemapigation.getElementsByTagName('img');
			for (i = 0; i < sitemapigationULs.length; i++) {
				sitemapigationULs[i].style.display = "none";
				allImages[i].setAttribute('src', '/img/icons/expand.gif')
			}
	}
	else {
		var theParent = whichOne.parentNode;
		var theParentULs = theParent.getElementsByTagName('ul');
		var theParentImage = theParent.getElementsByTagName('img');
		
		//Grab just the first UL and the first toggle image so that sub-sub UL sitemaps/image don't expand too
		if (theParentULs[0].style.display == "none") {
			theParentULs[0].style.display = "block";
			theParentImage[0].setAttribute('src', '/img/icons/contract.gif');
		}
		else {
			theParentULs[0].style.display = "none";
			theParentImage[0].setAttribute('src', '/img/icons/expand.gif');
		}
	}
}

window.onload = init;