// Toggles dropdowns for header navigation
// Used in Controls\Header.ascx
function ToggleCarrot(whichCarr)
{
	carr = document.getElementById('carrot_' + whichCarr);
	if (carr)
	{
		carr.style.display = ((carr.style.display == 'block') ? ('none') : ('block'));
	}
}

// Cross platform function to attach an event
// handler to a DOM object.  Used on the homepage
// for various mouse-over events
function eventRegistration(element, eventName, handler)
{
	if (element.addEventListener)
	{
		element.addEventListener(eventName, handler, false);
	}
	else
	{
		eventName = 'on' + eventName;
		element.attachEvent(eventName, handler);
	}
}

// Opens the FloatingBullet content.
// Used in the FloatingBullet control
function showBulletContent(e)
{
	var target = getTargetFloatingBullet(e);

	if (target.className.indexOf(" open") < 0)
	{
		target.className = target.className + " open";
	}

	setPosition(target);
}

// Closes the FloatingBullet content.
// Used in the FloatingBullet control
function hideBulletContent(e)
{
	var target = getTargetFloatingBullet(e);

	target.className = target.className.replace(/ open/g, "");
	target.popup.style.top = "0px";
}

function setPosition(target)
{
	var topLeftCoords = findPos(target);

	target.popup.style.top = topLeftCoords[1] + "px";
	target.popup.style.left = (topLeftCoords[0] + target.offsetWidth - target.popup.offsetWidth) + "px";
}

// Helper function for hideBulletContent and showBulletContent
function getTargetFloatingBullet(e)
{
	if (!e) var e = window.event;
	var target;
	if (e.target) target = e.target;
	else if (e.srcElement) target = e.srcElement;

	while ((target != document) && (target.className.search("(^| )floatingbullet($| )") < 0))
	{
		target = target.parentNode;
	}

	if (target == document)
	{
		target = null;
	}

	return target;
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	
	return [curleft, curtop];
}
