var _oroll = [];
function initPage()
{
	var blocks = document.getElementsByTagName("div");
	for (var i=0; i<blocks.length; i++)
	{
		if (blocks[i].className.indexOf("roll") != -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 == "button") {
						_oroll.push(links[k]);
						links[k]._parent = links[k].parentNode;
						if (links[k]._parent.className.indexOf("inner-info-1") != -1)
						{
							links[k]._parent = links[k].parentNode.parentNode;
						}
						
						if (links[k].rel)
						{
							links[k].rels = links[k].rel.split(" ");
							if (links[k]._parent.className.indexOf("close") != -1)
							{
								for (j = 0; j < links[k].rels.length; j++)
								{
									var box = document.getElementById(links[k].rels[j]);
									if (box)
									{
										box.style.display = "none";
									}
								}
							}
						}
						links[k].onclick = function()
						{
							if ( this._parent.className.indexOf("close") != -1 ) 
							{
								
								for (i = 0; i < _oroll.length; i ++)
								{
									if (_oroll[i].rels)
									{
										for (j = 0; j < _oroll[i].rels.length; j++)
										{
											var box = document.getElementById(_oroll[i].rels[j]);
											if (box)
											{
												box.style.display = "none";
											}
										}
									}
									if (_oroll[i]._parent.className.indexOf("close") == -1)
									{
										_oroll[i]._parent.className += " close";
									}
								}

								
								this._parent.className = this._parent.className.replace("close", "");
								if (this.rels)
								{
								for (j = 0; j < this.rels.length; j++)
								{
									var box = document.getElementById(this.rels[j]);
									if (box)
									{
										box.style.display = "block";
										box.style.marginTop = "0px";
										var btop = findPosY(box);
										var ltop = findPosY(this);
										if (ltop > (btop+30))
										{
											box.style.marginTop = ltop - (btop+30) + "px";
										}
										
									}
								}
							}
							}
							else
							{
								this._parent.className += " close";
								if (this.rels)
								{
								for (j = 0; j < this.rels.length; j++)
								{
									var box = document.getElementById(this.rels[j]);
									if (box)
									{
										box.style.display = "none";
									}
								}
							}
							}
							return false;
						}
				}
			}
		}
	}
}

function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}


if (window.addEventListener){
	window.addEventListener("load", initPage, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", initPage);
}
