// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Ensure the prototype library is already loaded!

setLastFormFocus = function() {
	if (document.forms.length > 0) {
		$(document.forms[document.forms.length - 1]).focusFirstElement();
	}
}

toggleBranch = function(ref){
	new Effect.toggle(ref + '_child', 'blind', {duration:0.2});
	var img = $(ref + '_icon');
	if (img.getAttribute('src').indexOf('expanded.gif') > 0)
	{
		img.setAttribute('alt', 'Click to Expand');
		img.setAttribute('src', '/images/collapsed.gif');
	}
	else
	{
		img.setAttribute('alt', 'Click to Collapse');
		img.setAttribute('src', '/images/expanded.gif');
	}
}

hideMe = function(ref) {
	var elem = $(ref);
  elem.setAttribute('timerHandle', setTimeout(function() { elem.style.display = "none"; }, 100));
}

showMe = function(event, ref) {
	var elem = $(ref);
  if (elem.style.display == "none")
  {
    var size = elem.getDimensions();
    var pos = Position.cumulativeOffset(Event.element(window.event || event))
    elem.style.display = "";
    elem.style.top = (pos[1] - size.height) + 'px';
    elem.style.left = pos[0] + 'px';
  }
}