var temp, temp2, cookieArray, cookieArray2, cookieCount;

var klassenattribut = (navigator.userAgent.toLowerCase().indexOf("msie") != -1)?"className":"class";

function initiate_tree1(){

	cookieCount=0;

	if(document.cookie){

		cookieArray=document.cookie.split(";");
		cookieArray2=new Array();

		for(i in cookieArray){
			cookieArray2[cookieArray[i].split("=")[0].replace(/ /g,"")]=cookieArray[i].split("=")[1].replace(/ /g,"");
		}

	}

	cookieArray=(document.cookie.indexOf("state=")>=0)?cookieArray2["state"].split(","):new Array();

	temp=document.getElementById("tree1");

	for(var o=0;o<temp.getElementsByTagName("li").length;o++){

		if(temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length>0){

			temp2                                = document.createElement("span");
			temp2.className                        = "symbols";
			//temp2.style.backgroundImage        = (cookieArray.length>0)?((cookieArray[cookieCount]=="true" || temp.getElementsByTagName("li")[o].getAttribute("class", true)=="item_selected")?"url(http://www.nightpics.de/images_nightpics/navigation/minus.gif)":"url(http://www.nightpics.de/images_nightpics/navigation/plus.gif)"):"url(http://www.nightpics.de/images_nightpics/navigation/plus.gif)";
			temp2.style.backgroundImage        = (cookieArray.length>0)?((temp.getElementsByTagName("li")[o].getAttribute(klassenattribut, true)=="item_selected")?"url(http://www.nightpics.de/images_nightpics/navigation/minus.gif)":"url(http://www.nightpics.de/images_nightpics/navigation/plus.gif)"):"url(http://www.nightpics.de/images_nightpics/navigation/plus.gif)";
			temp2.onclick=function(){
				showhide(this.parentNode);
				writeCookie();
			}

			temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild)

			temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none";

			//if(cookieArray[cookieCount]=="true" || temp.getElementsByTagName("li")[o].getAttribute("class", true)=="item_selected"){
			if(temp.getElementsByTagName("li")[o].getAttribute(klassenattribut, true)=="item_selected"){
				showhide(temp.getElementsByTagName("li")[o]);
			}

			cookieCount++;

		}
		else{

			temp2                                = document.createElement("span");
			temp2.className                        = "symbols";
			temp2.style.backgroundImage        = "url(http://www.nightpics.de/images_nightpics/navigation/page.gif)";

			temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild);

		}
	
	}

}



function showhide(el){

	el.getElementsByTagName("ul")[0].style.display=(el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block";

	el.getElementsByTagName("span")[0].style.backgroundImage=(el.getElementsByTagName("ul")[0].style.display=="block")?"url(http://www.nightpics.de/images_nightpics/navigation/minus.gif)":"url(http://www.nightpics.de/images_nightpics/navigation/plus.gif)";

	//el.style.color=(el.getAttribute("class", true)=="item_selected")?"#FFFF00":"#FFFFFF";

}



function writeCookie(){                // Runs through the menu and puts the "states" of each nested list into an array, the array is then joined together and assigned to a cookie.

	cookieArray=new Array()

	for(var q=0;q<temp.getElementsByTagName("li").length;q++){

		if(temp.getElementsByTagName("li")[q].childNodes.length>0){
			if(temp.getElementsByTagName("li")[q].childNodes[0].nodeName=="SPAN" && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length>0){

				cookieArray[cookieArray.length]=(temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display=="block");

			}
		}

	}

	document.cookie="state="+cookieArray.join(",")+";expires="+new Date(new Date().getTime() + 365*24*60*60*1000).toGMTString();

}

