
community_links.sort (function () {return 0.5 - Math.random ();});
servermod_links.sort (function () {return 0.5 - Math.random ();});
clan_links.sort (function () {return 0.5 - Math.random ();});

var bMayClose = true;
var bMayOpen = true;

function Show_fl_community_HeadbarLinks (bUseDynBar)
{
	if (bUseDynBar)
	{
		var curr_domain = document.domain, banned = false, ban_id = -1;

		if (curr_domain.indexOf ("www.") === 0)
		{
			curr_domain = curr_domain.substring (4);
		}

		for (var i = 0; i < banned_domains.length; i++)
		{
			if (banned_domains[i] === curr_domain)
			{
				ban_id = i;
				banned = true;
				break;
			}
		}

		if (!banned)
		{
			var index_before, index_before2;

			// 2 community links
			var index = Math.floor (Math.random () * community_links.length);

			document.write ("<a href=\"" + community_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + community_links[index].name + "</a> &nbsp;&nbsp;&nbsp&nbsp;&nbsp;");
			index_before = index;
			while (index == index_before)
			{
				index = Math.floor (Math.random () * community_links.length);
			}
			document.write ("<a href=\"" + community_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + community_links[index].name + "</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");

			document.write (" || &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");

			// 3 servermod links
			index = Math.floor (Math.random () * servermod_links.length);
			document.write ("<a href=\"" + servermod_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + servermod_links[index].name + "</a> &nbsp;&nbsp;&nbsp&nbsp;&nbsp;");

			index_before = index;
			while (index == index_before)
			{
				index = Math.floor (Math.random () * servermod_links.length);
			}
			document.write ("<a href=\"" + servermod_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + servermod_links[index].name + "</a> &nbsp;&nbsp;&nbsp&nbsp;&nbsp;");

			index_before2 = index;
			while (index == index_before || index == index_before2)
			{
				index = Math.floor (Math.random () * servermod_links.length);
			}
			document.write ("<a href=\"" + servermod_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + servermod_links[index].name + "</a>");
		}
		else
		{
			if  (temp_banned_domains[ban_id])
			{
				document.write ("<font style='font-weight:bold; color: #FF0000; font-size: 10px;'>THIS WEBSITE/SERVER/CLAN HAS BEEN TEMPORARILY BANNED FROM THE COMMUNITY NETWORK</font>");
			}
			else
			{
				document.write ("<font style='font-weight:bold; color: #FF0000; font-size: 10px;'>THIS WEBSITE/SERVER/CLAN HAS BEEN BANNED FROM THE COMMUNITY NETWORK</font>");
			}

			if  (ban_reasons[ban_id] != "")
			{
				document.write ("<font style='color: #FF0000; font-size: 8px;'>&nbsp;" + ban_reasons[ban_id] + "</font>");
			}
		}
	}
	else
	{
		document.write ("<div class=\"communityBar\">");
		new commBarTicker ("", "communityBar", "class_flc_headbar", 8000, "fade");
		document.write ("</div>");
	}
}

function Show_fl_community_PopupLinks (color)
{
	document.write ("<span class=\"class_flc_headbar\">");
	if (color === "brightblue")
	{
		document.write ("<table width=\"500\" bgcolor=\"#FFFFFF\" style=\"font-family:verdana;color:#222F47;border-left-width:1px;border-top-width:0px;border-style:solid;border-right-width:1px;border-color:#C0C9E0;border-bottom-width:1px;\">");
	}
	else if (color === "darkblue")
	{
		document.write ("<table width=\"500\" bgcolor=\"#000000\" style=\"font-family:verdana;color:#B7BECA;border-left-width:1px;border-top-width:0px;border-style:solid;border-right-width:1px;border-color:#283753;border-bottom-width:1px;\">");
	}
	else if (color === "yellow")
	{
	  document.write ("<table width=\"500\" bgcolor=\"yellow\" style=\"font-family:verdana;color:black;border-left-width:1px;border-top-width:0px;border-style:solid;border-right-width:1px;border-color:black;border-bottom-width:1px;\">");
	}
	document.write ("<tr><td><b>General/Fansite Links</b></td><td><b>Server/Mod Links</b></td><td><b>Clan Links</b></td></tr>");

	var index = 0;
	var max_servermod = 12;
	var max_clan = 3;
	var max_community = 6;

	while ((index < servermod_links.length && index < max_servermod + 1) || (index < clan_links.length && index < max_clan + 1) || (index < community_links.length && index < max_community + 1))
	{
		document.write ("<tr><td>");

		if (index < community_links.length && index < max_community)
		{
			document.write ("<a href=\"" + community_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + community_links[index].name + "</a>");
		}
		else if (index < community_links.length && index < max_community + 1)
		{
			document.write ("<a href=\"http://www.flcnb.net\" target=\"_blank\" style=\"font-weight: bold; text-decoration: underline;\">See more...</a>");
		}

		document.write ("</td><td>");

		if (index < servermod_links.length && index < max_servermod)
		{
			document.write ("<a href=\"" + servermod_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + servermod_links[index].name + "</a>");
		}
		else if (index < servermod_links.length && index < max_servermod + 1)
		{
			document.write ("<a href=\"http://www.flcnb.net\" target=\"_blank\" style=\"font-weight: bold; text-decoration: underline;\">See more...</a>");
		}

		document.write ("</td><td>");

		if (index < clan_links.length && index < max_clan)
		{
			document.write ("<a href=\"" + clan_links[index].url + "\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">" + clan_links[index].name + "</a>");
		}
		else if (index < clan_links.length && index < max_clan + 1)
		{
			document.write ("<a href=\"http://www.flcnb.net\" target=\"_blank\" style=\"font-weight: bold; text-decoration: underline;\">See more...</a>");
		}

		document.write ("</td></tr>");
		index++;
	}

	document.write ("<tr><td colspan=\"3\" style=\"width:100%;text-align:center;\"><a href=\"http://www.flcnb.net/add\" style=\"font-family:Verdana;text-decoration: none;\" target=\"_blank\">Add your Freelancer site to the Community Network!</a></td></tr>");
	document.write ("</table></span>");
}

function Show_fl_community_Popup (element)
{
	bMayClose = false;
	bMayOpen = true;

	var curr_domain = document.domain;
	if (curr_domain.indexOf ("www.") === 0)
	{
		curr_domain = curr_domain.substring (4);
	}

	for (var i = 0; i < banned_domains.length; i++)
	{
		if (banned_domains[i] == curr_domain)
		{
			return;
		}
	}

	hp = document.getElementById ("fl_community_hoverpopup");

	// Set position of hover-over popup
	hp.style.top = findPosY (element) + 20 + "px";
	hp.style.left = findPosX (element) + 0 + "px";

	setTimeout ("_Show_fl_community_Popup()", 200);
}

function _Show_fl_community_Popup ()
{
	if (bMayOpen)
	{
		// Set popup to visible
		hp.style.visibility="Visible";
	}
}

function Enter_fl_community_Menu ()
{
	bMayClose = false;
}

function Hide_fl_community_Popup ()
{
	bMayClose = true;
	bMayOpen = false;
	setTimeout ("_Hide_fl_community_Popup()", 200);
}

function _Hide_fl_community_Popup ()
{
	if (bMayClose)
	{
		hp = document.getElementById ("fl_community_hoverpopup");
		hp.style.visibility = "Hidden";
	}
}

function findPosX (obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (1)
		{
			curleft  += obj.offsetLeft;
			if (!obj.offsetParent)
			{
				break;
			}
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft  +=obj.x;
	}
	return curleft;
}

function findPosY (obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (1)
		{
			curtop  +=obj.offsetTop;
			if (!obj.offsetParent)
			{
				break;
			}
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop  +=obj.y;
	}
	return curtop;
}

