var bDidBounceUp = false;


function BounceUp(e, obj, itemIndex, pixelsToSlideVertical, duration)
{
	if(!isMouseLeaveOrEnter(e, obj)) return;
	
	var bIsDown = true;

	var queue = Effect.Queues.get('Scope' + itemIndex);
	queue.each(function(e) { 
		// If there's a BounceDown in queue, then it's already up and there's no need to go up again
		if(e.state != "running" && e.options.y == pixelsToSlideVertical)
		{
			bIsDown = false;
		}
	});
	
	// The content is down (not up) so it's safe to add it to the queue to move up
	if(bIsDown)
	{
		new Effect.Move(obj, {x:0, y:-pixelsToSlideVertical, duration:duration, queue: {position:'end', scope:'Scope' + itemIndex} });
		bDidBounceUp = true;
	}
}

function BounceDown(e, obj, itemIndex, pixelsToSlideVertical, duration)
{
	if(!isMouseLeaveOrEnter(e, obj)) return;

	if(bDidBounceUp)
	{
		bDidBounceUp = false;
		new Effect.Move(obj, {x:0, y:pixelsToSlideVertical, duration:duration, queue: {position:'end', scope:'Scope' + itemIndex} });	
	}
}



// this function determines whether the event is the equivalent of the microsoft mouseleave or mouseenter events. 
// This is needed since onmouseout gets called when you leave the parent element and enter a child
function isMouseLeaveOrEnter(e, handler) 
{ 
	if (e.type != 'mouseout' && e.type != 'mouseover') 
		return false; 
		
	var reltg = e.relatedTarget ? e.relatedTarget : 
		e.type == 'mouseout' ? e.toElement : e.fromElement; 
	
	while (reltg && reltg != handler) 
		reltg = reltg.parentNode; 
		
	return (reltg != handler); 
}
