// HELPER OBJECTS
var LinkHelper =
{
	OpenOffSite: function(anchor)
	{
		window.open(anchor.href, "OffSite", "directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes").focus();

		return false;
	}
};

/* var FlashHelper =
{
	Load: function(elementID, url, width, height)
	{
		if(window.navigator.userAgent.indexOf("Firefox") >= 0)
			return;
		
		var Output = "<object id=\"" + elementID + "Flash\" ";
		
		if(document.all)
			Output += "classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" ";
		else
			Output += "data=\"" + url + "\" type=\"application/x-shockwave-flash\" ";

		Output += "width=\"" + width + "\" height=\"" + height + "\">\n";
		Output += "<param name=\"movie\" value=\"" + url + "\" />\n";

		for(var i = 4; i < arguments.length; ++i)
		{
			var SepPos = arguments[i].indexOf("|");
			var ParamName = arguments[i].substring(0, SepPos);
			var ParamValue = arguments[i].substring(SepPos + 1, arguments[i].length);

			Output += "<param name=\"" + ParamName + "\" value=\"" + ParamValue + "\" />\n";
		}

		Output += "</object>";
		
		var Elem = document.getElementById(elementID);
		
		if(Elem)
			Elem.innerHTML = Output;
		else
			document.writeln(Output);
	}
}; */

// UTILITY
var Utility =
{
	GetViewportWidth: function()
	{
		if(typeof window.innerWidth != "undefined")
			return window.innerWidth;
		else if(typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined")
			return document.documentElement.clientWidth;
		else
			return document.getElementsByTagName("body")[0].clientWidth;
	},

	GetViewportHeight: function()
	{
		if(typeof window.innerHeight != "undefined")
			return window.innerHeight;
		else if(typeof document.documentElement != "undefined" && typeof document.documentElement.clientHeight != "undefined")
			return document.documentElement.clientHeight;
		else
			return document.getElementsByTagName("body")[0].clientHeight;
	},

	GetScrollTop: function()
	{
		return document.documentElement.scrollTop;
	},

	GetAbsoluteTop: function(element)
	{
		var Top = 0;

		for(var i = element; i; i = i.offsetParent)
			Top += i.offsetTop;

		return Top;
	},

	GetAbsoluteLeft: function(element)
	{
		var Left = 0;

		for(var i = element; i; i = i.offsetParent)
			Left += i.offsetLeft;

		return Left;
	}
};

// FLYOUT MENU
function FlyOut(activatorID, menuID)
{
	this.AllFlyOuts.push(this);
	
	this.activatorID = activatorID;
	this.activator = document.getElementById(activatorID);

	if(!this.activator)
		throw "Activator '" + activatorID + "' not found!";

	this.menuID = menuID;
	this.menu = document.getElementById(menuID);

	if(!this.menu)
		throw "Menu '" + menuID + "' not found!";

	var Me = this;

	function OnOver()
	{
		Me.Activate();
		Me.CancelDeactivateTimed();
	}

	function OnOut()
	{
		Me.DeactivateTimed();
	}

	this.activator.onmouseover = OnOver;
	this.activator.onmouseout = OnOut;
	this.menu.onmouseover = OnOver;
	this.menu.onmouseout = OnOut;

	this.SetMenuEvents(this.menu.firstChild, OnOver, OnOut);

	this.Deactivate();
}

FlyOut.prototype.AllFlyOuts = new Array();
FlyOut.prototype.TimeoutDuration = 250;

FlyOut.prototype.SetMenuEvents = function(firstNode, overEvent, outEvent)
{
	for(var i = firstNode; i; i = i.nextSibling)
	{
		// If element node
		if(i.nodeType == 1)
		{
			i.onmouseover = overEvent;
			i.onmouseout = outEvent;

			if(i.firstChild)
				this.SetMenuEvents(i.firstChild, overEvent, outEvent);
		}
	}
}

FlyOut.prototype.Activate = function()
{
	this.menu.style.top = "";
	this.menu.style.display = "";

	if(Utility.GetAbsoluteTop(this.menu) < Utility.GetScrollTop())
		this.menu.style.top = (this.menu.offsetTop + Utility.GetScrollTop() - Utility.GetAbsoluteTop(this.menu) + 28) + "px";
	else if(Utility.GetAbsoluteTop(this.menu) + this.menu.offsetHeight > Utility.GetScrollTop() + Utility.GetViewportHeight())
		this.menu.style.top = (this.menu.offsetTop - ((Utility.GetAbsoluteTop(this.menu) + this.menu.offsetHeight) - (Utility.GetScrollTop() + Utility.GetViewportHeight())) + 28) + "px";

	for(var i = 0, ii = this.AllFlyOuts.length; i != ii; ++i)
	{
		if(this.AllFlyOuts[i] != this)
			this.AllFlyOuts[i].Deactivate();
	}
}

FlyOut.prototype.Deactivate = function()
{
	if(this.timeout)
		clearTimeout(this.timeout);

	this.timeout = null;
	this.menu.style.display = "none";
}

FlyOut.prototype.DeactivateTimed = function()
{
	if(this.timeout)
		clearTimeout(this.timeout);

	var Me = this;

	this.timeout = setTimeout(function() { Me.Deactivate(); }, this.TimeoutDuration);
}

FlyOut.prototype.CancelDeactivateTimed = function()
{
	if(this.timeout)
	{
		clearTimeout(this.timeout);
		this.timeout = null;
	}
}
