/*  
 * Note:
 *	NS4 = Netscape 4
 *	NS6 = Netscape 6/Mozilla
 *	IE  = Internet Explorer 4+
 *	DOM = DOM capable browser (Mozilla)
 */

capable = (is.ns4 || is.ie || is.dom) ? true : false;
isExpanded = false;

/** Holds a identifier for the currently open thread */
var openThread = null;

/* Function for ns4 */
function getIndex( thread ){
	index = null;
	
	for( i = 0; i < document.layers.length; i++ ){
		whichThread = document.layers[i];
		
		/* Move the menu to following coordinates: */
		whichThread.pageX = 10;
		whichThread.pageY = 75;
		
		if( whichThread.id == thread ){
			index = i;
			break;
		}
	}
	
	return index;
}

/* Function for ns4 */
function arrange(){
	nextY = document.layers[firstIndex].pageY + document.layers[firstIndex].document.height;
	
	for( i = firstIndex+1; i < document.layers.length; i++ ){
		whichThread = document.layers[i];
		if( whichThread.visibility != "hide" ){
			/* Move the specified layer to following coordinates */
			whichThread.pageY = nextY;
			whichThread.pageX = 10;
			nextY += whichThread.document.height;
		}
	}
}

/* Initialize menu */
function initIt(){
	if( is.ns4 ) {
		for( i = 0; i < document.layers.length; i++ ){
			whichThread = document.layers[i];
			if( whichThread.id.indexOf("Child") != -1 ){ 
				whichThread.visibility = "hide"
			};
		}
		arrange();
		
	} else if(is.ie) {
		tempColl = document.all.tags("DIV");
		for( i = 0; i < tempColl.length; i++ ){
			if( tempColl(i).className == "child" ) {
				tempColl(i).style.display = "none";
			}
		}
		
	} else if( is.dom ) {
		tempColl = document.getElementsByTagName("DIV");
		for( i=0; i<tempColl.length; i++ ) {
			if( tempColl(i).className == "child" ) {
				tempColl(i).style.display = "none";
			}
		}
	}
}



/* Open/Close thread */
function toggle( thread, test ) {
	if( capable ) {
		if( is.ie ) {
			toggleIE(thread,test);
		} else if( is.ns4 ) {
			toggleNS(thread,test);
		} else if( is.dom ) {
			toggleDOM(thread,test);
		}
	}
}

/* Open/Close thread in IE */
function toggleIE( thread, test ) {
	whichThread	= eval(thread + "Child");
	whichImage	= eval(thread + "Img");
	
	if (thread != openThread) {
		whichThread.style.display = "block";
		whichImage.src = prepend + "pic/menu/minus_open.gif";
		
		if(openThread != null){
			whichThread	= eval(openThread + "Child");
			whichImage	= eval(openThread + "Img");
			whichThread.style.display = "none";
			whichImage.src = prepend + "pic/menu/plus.gif";
		}
		
		openThread = thread;
	}
	else if(test == 1){
		whichThread.style.display = "none";
		whichImage.src = prepend + "pic/menu/plus.gif";
		openThread = null;
	}
	
	window.event.cancelBubble = true ;
}

/* Open/Close thread in NS4 */
function toggleNS( thread, test ) {
	whichThread	= eval("document." + thread + "Child");
	whichImage	= eval("document." + thread + "Parent.document.images['imEx']");
	
	if (thread != openThread) {
		whichThread.visibility = "show";
		whichImage.src = prepend + "pic/menu/minus_open.gif";
		
		if(openThread != null){
			whichThread	= eval("document." + openThread + "Child");
			whichImage	= eval("document." + openThread + "Parent.document.images['imEx']");
			whichThread.visibility = "hide";
			whichImage.src = prepend + "pic/menu/plus.gif";
		}
		openThread = thread;
	}
	else if( test == 1) {
		whichThread.visibility = "hide";
		whichImage.src = prepend + "pic/menu/plus.gif";
		openThread = null;
	}
	arrange();
}

/* Open/Close thread in DOM browsers */
function toggleDOM(thread, test ) {
	whichThread	= document.getElementById( thread + "Child" );
	whichImage	= document.getElementById( thread + "Img" );
	
	if( thread != openThread ) {
		whichThread.style.display = "block";
		whichImage.src = prepend + "pic/menu/minus_open.gif";
		
		if(openThread != null){
			whichThread	= document.getElementById( openThread + "Child" );
			whichImage	= document.getElementById( openThread + "Img" );
			whichThread.style.display = "none";
			whichImage.src = prepend + "pic/menu/plus.gif";
		}
		
		openThread = thread;
	} else if( test == 1) {
		whichThread.style.display = "none";
		whichImage.src = prepend + "pic/menu/plus.gif";
		openThread = null;
	}
}

function closeThread() {
	if(openThread != null){
		if( is.ns ) {
			whichThread	= eval("document." + openThread + "Child");
			whichImage	= eval("document." + openThread + "Parent.document.images['imEx']");
			whichThread.visibility = "hide";
			whichImage.src = prepend + "pic/menu/plus.gif";
			arrange();
		} else if( is.ie ) {
			whichThread	= eval(openThread + "Child");
			whichImage	= eval(openThread + "Img");
			whichThread.style.display = "none";
			whichImage.src = prepend + "pic/menu/plus.gif";
		} else if( is.dom ) {
			whichThread	= document.getElementById( openThread + "Child" );
			whichImage	= document.getElementById( openThread + "Img" );
			whichThread.style.display = "none";
			whichImage.src = prepend + "pic/menu/plus.gif";
		}
		openThread = null;
	}
}

/* Function for NS4 */
function showAll() {
	for ( i = firstIndex; i < document.layers.length; i++ ) {
		whichThread = document.layers[i];
		whichThread.visibility = "show";
	}
}

/* Initialization */
function expandAll(isBot) {
	newSrc = (isExpanded) ? prepend + "pic/menu/minus_open.gif" : prepend + "pic/menu/plus.gif";
	
	if (is.ns4) {
		for( i = firstIndex; i < document.layers.length; i++ ) {
			whichThread = document.layers[i];
			
			if (whichThread.id.indexOf("Parent") != -1) {
				whichThread.document.images["imEx"].src = newSrc;
			}
			
			if (whichThread.id.indexOf("Child") != -1) {
				whichThread.visibility = (isExpanded) ? "hide" : "show";
			}
		}
		
		arrange();
		
		if (isBot && isExpanded) {
			scrollTo( 0, document.layers[firstInd].pageY );
		}
	
	} else if(is.ie) {
		divColl = document.all.tags("DIV");
		
		for ( i = 0; i < divColl.length; i++ ) {
			if( divColl(i).className == "child" ) {
				divColl(i).style.display = (isExpanded) ? "none" : "block";
			}
		}
		
		imColl = document.images.item("imEx");
		
		for ( i = 0; i < imColl.length; i++ ) {
			imColl(i).src = newSrc;
		}

	} else if(is.dom) {
		divColl = document.getElementsByTagName("DIV");
		
		for ( i = 0; i < divColl.length; i++ ) {
			if( divColl(i).className == "child" ) {
				divColl(i).style.display = (isExpanded) ? "none" : "block";
			}
		}
	
		imColl = document.getElementsByName("imEx");
	
		for ( i = 0; i < imColl.length; i++ ) {
			imColl(i).src = newSrc;
		}
	}
	
	isExpanded = !isExpanded;
}

/* Write style according to browser version etc. */
with (document) {
    write("<style type='text/css'>");
    if (is.ns4) {
            write(".parent {position:absolute; visibility:hidden;}");
            write(".child {position:absolute; visibility:hidden}");
    } else if(is.ie) {
            write(".child {display:none}");
            write(".parent {}");
    } else if(is.dom) {
            write(".child {display:none}");
            write(".parent {}");
    }
    write("</style>");
}

onload = initIt;