/*
 * These are general variables and function accesses for popup tree
 * Usefull if there are more than 1 tree & there are only 1 popup block can be displayed at the same time
 */
var cur_level = 0;
var popup_blocks = new Array();
var in_menu = false;

function popupFunction(block_obj, popup_block_id, show_direction, popup_zindex, level) {
	// hide all displayed blocks
	cur_level = hideBlocks(popup_blocks, cur_level, level);
	
	// show popup block
	popupBlock(block_obj, popup_block_id, show_direction, popup_zindex);
	
	// add popup block to list & set the current popup level
	cur_level = addBlockToList(popup_blocks, popup_block_id, level);
}

/*
 * purpose: hide blocks from the list
 * created: Indrajaya Lie
 */
function hideBlocks(block_list_var, cur_level, level) {
	if (cur_level >= level) {
		// get the popup blocks that are displayed
		while (cur_level >= level) {
			var block_id = block_list_var.pop();
			popup_block_obj = document.getElementById(block_id);
			if (popup_block_obj != null)
				popup_block_obj.style.display = "none";
			
			cur_level--;
		}
	}
	return cur_level;
}
			
/*
 * purpose: add block to list and update the current level
 * created: Indrajaya Lie
 */
function addBlockToList(block_list_var, block_id, level) {
	// store the popup block id that are displayed
	block_list_var.push(block_id);
	
	return level;
}

/*
 * purpose: hide the blocks by using a timeout
 *			This function should be called by setTimeout() function
 * created by: Indrajaya Lie
 */
function hideBlocksTimer(block_list_var) {
	if (!in_menu) {
		hideBlocks(block_list_var, cur_level, 1);
	}
}