	var fadeWaitTime = 300; //time in ms to wait before fading boxes
	var fadeDuration = 0.4; //time in seconds the fade effect lasts
	
	var setupShowHidePane = function (openButton, pane) {
	
		openButton.paneID = pane.id;
		$(openButton).onclick = function() { showPane($(this.paneID)); return false;};
		
		setPaneID(pane, pane.id);
		
		addCancelClicks(pane);
	}
	
	var setPaneID = function (elem, paneID) {
		elem.paneID = paneID;
		
		var children = elem.childElements();
		
		if (children.length > 0) {
			for (var i in children) {
				if (children[i] && children[i].tagName){
					setPaneID(children[i], paneID);
				}
			}
		}
	}
	
	var showPane = function (pane) {
		pane.style.display = '';
		pane.style.opacity = '1.0';
		
		setInputFadeFocus(pane);
		if (!setFocusOnFirstTag(pane, 'INPUT', true)) {
			setFocusOnFirstTag(pane, 'A', false);
		}
		
		if (pane.id == rightListId && $('googleSubmitButton')) {
			$('googleSubmitButton').style.display = 'none';
		}
		
		return false;
	}
	
	var hidePane = function (paneID) {
		new Effect.Fade($(paneID), { duration:fadeDuration, 
			afterFinish: function (e) {
				if (paneID == rightListId && $('googleSubmitButton')) {
					$('googleSubmitButton').style.display = '';
				}
			}
		});
		clearTimeout($(paneID).timeout);
		$(paneID).timeout = -1;
		
		
	}
	
	var hidePaneTimed = function (event, pane) {
		var current_mouse_target = null;
		
		if (event) {
			if (event.toElement) {				
				current_mouse_target = event.toElement;
			}
			else if (event.relatedTarget) {				
				current_mouse_target = event.relatedTarget;
			}
		}
		
		if (!isChildOf(pane, current_mouse_target) &&
			pane != current_mouse_target &&
			!childHasFocus(pane)) {
			pane.timeout = setTimeout("hidePane('"+pane.id+"')", fadeWaitTime);
		}
	
	
	}
	
	var clearPaneTimeout = function (paneID) {
		if ($(paneID) != null) {
			clearTimeout($(paneID).timeout);
		}
	}
	
	var childHasFocus = function (node) {
		if (node && (node.tagName == 'A' || node.tagName == 'INPUT') && node.hasFocus()) {
			return true;
		}
		else {
			var children = node.childElements();
			
			if (children.length > 0) {
				for (var i in children) {
					if (children[i] && children[i].tagName && childHasFocus(children[i])){
						return true;
					}
				}
			}
		}
		return false;
	}
	
	var setFocusOnFirstTag = function (node, tagName, isEmpty) {
		if (node.tagName == tagName && ((node.value == "" && isEmpty) || !isEmpty)) {
			node.focus();
			return true;
		}
		else {
			var children = node.childElements();
			
			if (children.length > 0) {
				for (var i in children) {
					if (children[i] && children[i].tagName != null) {
						if (setFocusOnFirstTag(children[i], tagName, isEmpty)) {
							return true;
						}
					}
				}
			}
		}
		
		return false;
	}
	
	var setInputFadeFocus = function (elem) {
		if (elem) {
		
			if (elem.tagName == 'A' || elem.tagName == 'INPUT') {
				elem.focused = false;
				elem.hasFocus = function() { return this.focused; };
				elem.onfocus = function(event) { clearPaneTimeout($(this.paneID)); this.focused = true; };
				elem.onblur = function(event) { this.focused = false; hidePaneTimed(event, $(this.paneID)); };
			}

			var childElems = elem.childElements();
			
			for (var j = 0; j < childElems.length; j++) {
				if (childElems[j] && childElems[j].tagName) {
					setInputFadeFocus(childElems[j]);
				}
			}
		}
	}
	
	var addCancelClicks = function (node) {
		var children = node.childElements();
		
		if (children.length > 0) {
			for (var i in children) {
				if (children[i] && children[i].tagName) {
					addCancelClicks(children[i]);
				}
			}
		}
		
		Event.observe(node, "click", function() { clearPaneTimeout(this.paneID); return false; });
	}
	
	var isChildOf = function (parent, child) {
		if (child != null) {			
			while (child.parentNode) {
				if ((child = child.parentNode) == parent) {
					return true;
				}
			}
		}
		return false;
	}