var _links = [];

function initPage()
{
	var blocks = document.getElementsByTagName("div");
	for (var i=0; i<blocks.length; i++)
	{
		if (blocks[i].className.indexOf("rooll") != -1)
		{
			//if ( blocks[i].className.indexOf("close") == -1 ) blocks[i].className += " close";
			var links = blocks[i].getElementsByTagName("a");
		
				for (var k=0; k<links.length; k++) {
					
					if (links[k].className.indexOf("button") != -1) {
							links[k].states = links[k].innerHTML.split("/");
							if (links[k].states.length > 1)
							{
								if ( links[k].parentNode.parentNode.className.indexOf("close") != -1 ) 
								{
									links[k].innerHTML = links[k].states[0];
								}
								else
								{
									links[k].innerHTML = links[k].states[1];
								}
							}
						links[k].onclick = function()
						{
								if (this.states.length > 1)
								{
									if ( this.parentNode.parentNode.className.indexOf("close") != -1 ) 
									{
										this.parentNode.parentNode.className = this.parentNode.parentNode.className.replace("close", "");
										this.innerHTML = this.states[1];
									}
									else
									{
										this.parentNode.parentNode.className += " close";
										this.innerHTML = this.states[0];
									}
								}
							return false;
						}
						_links[_links.length] = links[k];
				}
			}
		}
	}
	var close_all = document.getElementById('close-all');
	if(close_all)
	{
		close_all.states = close_all.innerHTML.split("/");
		close_all.innerHTML = close_all.states[0];

		close_all.onclick = function()
		{
			for (var k=0; k < _links.length; k++)
			{
				if((close_all.innerHTML == close_all.states[0])&&(close_all.states[0]=="Close All")){
					close_all.states[0] = "Open All";
					if (_links[k].className.indexOf("button") != -1)
					{
						if(_links[k].parentNode.parentNode.className.indexOf("close") == -1)
						{
							_links[k].onclick();
						}
					}
				}
				else if(close_all.innerHTML == close_all.states[0])
				{
					if (_links[k].className.indexOf("button") != -1)
					{
						if(_links[k].parentNode.parentNode.className.indexOf("close") != -1)
						{
							_links[k].onclick();
						}
					}
				}
				else
				{
					if (_links[k].className.indexOf("button") != -1)
					{
						if(_links[k].parentNode.parentNode.className.indexOf("close") == -1)
						{
							_links[k].onclick();
						}
					}					
				}
			}			

			if(close_all.innerHTML == close_all.states[0])
			{
					close_all.parentNode.className = close_all.parentNode.className.replace("cclose","");
					close_all.innerHTML = close_all.states[1];
			}
			else
			{
				close_all.parentNode.className += " cclose";
				close_all.innerHTML = close_all.states[0];					
			}

			return false;
		}
	}
}


if (window.addEventListener){
	window.addEventListener("load", initPage, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", initPage);
}


