var ACTION_AUTO = 0;
var ACTION_EXPAND = 1;
var ACTION_COLLAPSE = 2;

function init()
	{
	var loc = document.location.href;
	var queryStr = "id=";
	if (loc.indexOf(queryStr) != -1)
		{
		var id=loc.substring(loc.indexOf(queryStr)+queryStr.length);
		shift(id);
		if (id.indexOf("_") != -1)
			{
			var tmp = id.split("_");
			shift(tmp[0]);
			}
		}
	}
	
function shift(id, action)
	{
	if (!action) action = ACTION_AUTO;
	var detailDiv = document.getElementById(id + "_detail");
	var shifter = document.getElementById(id + "_shifter");
	
	if (detailDiv)
		{
		if (action == ACTION_EXPAND || (action == ACTION_AUTO && detailDiv.style.display != "block"))
			{
			detailDiv.style.display = "block";
			shifter.src = "imgs/collapse.gif";
			if (detailDiv.innerHTML == "Loading ...")
				{
				detailDiv.innerHTML = getDetailHtml(id);
				}
			}
		else
			{
			detailDiv.style.display = "none";
			shifter.src = "imgs/expand.gif";
			}
		}
	}
	

function getDetailHtml(id)
	{
	var httpRequest=this.getHttpRequest();
	if (httpRequest)
		{
		var token = id.split("_"); 
		var url = "details/" + token[0] + "/" + token[1] + ".html";
		httpRequest.open("GET",url,false);
		httpRequest.send(null);
		return(httpRequest.responseText);
		}
	else return "";
	}


var gShifter;
function shiftAll(shifter)
	{
	var standbyDiv = document.getElementById("standby");
	if (shifter.src.indexOf("expand") != -1)
		{
		standbyDiv.style.visibility = "visible";
		}
	gShifter = shifter;
	setTimeout("shiftAll2();", 1);
	}

function shiftAll2()
	{
	var shifter = gShifter;
	var action;
	if (shifter.src.indexOf("expand") != -1)
		{
		action = ACTION_EXPAND;
		shifter.src = "imgs/collapse.gif";
		shifter.title = "collapse all";
		}
	else
		{
		action = ACTION_COLLAPSE;
		shifter.src = "imgs/expand.gif";
		shifter.title = "expand all";
		}
	var divs = document.getElementsByTagName("div");
	var divArray = new Array(); // ff ...
	for (elem in divs)
		{
		var div = divs[elem];
		if (div.id && div.id.indexOf("_detail") != 0)
			{
			divArray[divArray.length] = div.id.replace("_detail", "");
			}
		}
	for (var i = 0; i < divArray.length; i++)
		{
		shift(divArray[i], action);
		}

	var standbyDiv = document.getElementById("standby");
	standbyDiv.style.visibility = "hidden";
	}
	

function getHttpRequest()
	{
	var httpRequest;
	if (window.XMLHttpRequest) httpRequest = new XMLHttpRequest();
	else if (window.ActiveXObject) httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); //IE/Windows ActiveX
	return httpRequest;
	}
	



