(function AhsShowFlags ()
{
	function Decode (/* CharCode... */)
	{
		var	NumArgs = arguments.length,
				result	=	[],
				i				=	-1;
		for (i = 0; i < NumArgs; i++)
		{
			result.push(String.fromCharCode(arguments[i]));
		}
		return result.join('');
	} // .function Decode

	function GetShortSiteUrl (SiteUrl)
	{
		var	HttpSig	=	'://',
				StartPos	=	-1,
				EndPos		=	-1;
		SiteUrl		=	SiteUrl.replace('http://www.', 'http://');
		StartPos	=	SiteUrl.indexOf(HttpSig);
		if (StartPos === -1)
		{
			StartPos	=	0;
		}
		else
		{
			StartPos	=	StartPos + HttpSig.length;
		}
		EndPos		=	SiteUrl.indexOf('/', StartPos);
		if (EndPos === -1)
		{
			EndPos	=	SiteUrl.length;
		}
		return SiteUrl.slice(StartPos, EndPos);
	} // .function GetShortSiteUrl

	var	Flags	=
	[
		{
			power: 0
		},
		{
			url: 'woggrad.ru',
			title: Decode(1050,1088,1077,1084,1083,1100,46,32,1057,1083,1072,1074,1103,1085,1089,1082,1080,1081,32,1075,1086,1088,1086,1076),
			alt: Decode(1057,1072,1081,1090,32,1050,1088,1077,1084,1083,1103),
			img:
			[
				'http://pic4.ru/images/77697f3aa0dee0fb7d8cd981d4cf4202.gif',
				'http://pic4.ru/images/85c9feb55e754223015f6cae43090f9f.png',
				'http://pic4.ru/images/8d497f6096c4bfe61cfc6c1a444f7d75.gif',
				'http://pic4.ru/images/ca93945608cc4902b09f145f0692d7f6.png'
			],
			pos: 0,
			power: 12
		},
		{
			url: 'remake-heroes.ucoz.ru',
			title: Decode(1053,1086,1074,1086,1089,1090,1080,32,1087,1086,32,1043,1077,1088,1086,1103,1084,32,51,46,53,46,32,1055,1088,1086,1077,1082,1090,32,1056,1091,1089,1089,1082,1080,1077,32,1043,1077,1088,1086,1080,46),
			alt: Decode(1057,1072,1081,1090,32,1056,1077,1084,1077,1081,1082,1072,32,1043,1077,1088,1086,1077,1074),
			img:
			[
				'http://pic4.ru/images/1065734cbba0b1eda716a4ebb2cb1e73.gif',
				'http://pic4.ru/images/87ee959d9fd16aa0e1afa340f1f76ea7.gif'
			],
			pos: 0,
			power: 12
		},
		{
			url: 'wogarchive.ru',
			title: Decode(1042,1086,1075,32,1040,1088,1093,1080,1074,46,32,1057,1072,1084,1072,1103,32,1073,1086,1083,1100,1096,1072,1103,32,1082,1086,1083,1083,1077,1082,1094,1080,1103,32,1084,1072,1090,1077,1088,1080,1072,1083,1086,1074,32,1087,1086,32,1043,1077,1088,1086,1103,1084,32,51,46,32,1041,1086,1083,1077,1077,32,1075,1080,1075,1072,1073,1072,1081,1090,1072,32,1076,1072,1085,1085,1099,1093,46),
			alt: Decode(1042,1086,1075,32,1040,1088,1093,1080,1074),
			img:
			[
				'http://pic4.ru/images/560c0f68f99167d2e5c9a1f4c5f39f34.gif'
			],
			pos: 0,
			power: 16
		},
		{
			url: 'packa.ucoz.ru/forum/61-184-1',
			title: Decode(1050,1072,1090,1072,1083,1086,1075,32,1084,1086,1076,1086,1074,32,1076,1083,1103,32,1043,1077,1088,1086,1077,1074,32,51,46),
			alt: Decode(1050,1072,1090,1072,1083,1086,1075,32,1052,1086,1076,1086,1074,32,1043,51),
			img:
			[
				'http://pic4.ru/images/96542819dc744dab2042cdbd63a86523.png'
			],
			pos: 0,
			power: 12
		},
		{
			url: 'tp-mod.ucoz.net',
			title: Decode(84,101,114,114,121,32,80,114,97,116,99,104,101,116,116,115,32,77,111,100,44,32,1084,1086,1076,1080,1092,1080,1082,1072,1094,1080,1103,32,1076,1083,1103,32,1080,1075,1088,1099,32,1043,1077,1088,1086,1080,32,73,73,73),
			alt: Decode(84,101,114,114,121,32,80,114,97,116,99,104,101,116,116,115,32,77,111,100),
			img:
			[
				'http://tp-mod.ucoz.net/btpm/1.png',
				'http://tp-mod.ucoz.net/btpm/2.png'
			],
			pos: 0,
			power: 6
		},
		{
			url: 'heroesportal.net',
			title: Decode(72,101,114,111,101,115,32,80,111,114,116,97,108,32,45,32,1084,1077,1078,1076,1091,1085,1072,1088,1086,1076,1085,1099,1081,32,1080,1085,1090,1077,1088,1085,1077,1090,32,1088,1077,1089,1091,1088,1089,44,32,1086,1092,1092,45,1083,1072,1081,1085,32,1080,32,1086,1085,1085,45,1083,1072,1081,1085,32,1090,1091,1088,1085,1080,1088,1099,46),
			alt: Decode(1055,1086,1088,1090,1072,1083,32,1043,1077,1088,1086,1077,1074),
			img:
			[
				'http://pic4.ru/images/38ef19ba58a17be187e4b38d4b984cdc.png',
				'http://pic4.ru/images/31698b56dfee0865e5540331294f990d.png',
				'http://pic4.ru/images/38f707054b4a60ee05dd00cb7773011e.png',
				'http://pic4.ru/images/5ba79359767f08439f3887482f49de2f.png'
			],
			pos: 0,
			power: 8
		},
		{
			url: 'heroes3towns.com',
			title: Decode(1059,1079,1085,1072,1081,1090,1077,32,1073,1086,1083,1100,1096,1077,32,1086,32,1085,1086,1074,1099,1093,32,1075,1086,1088,1086,1076,1072,1093,32,1074,32,1043,1077,1088,1086,1103,1093,32,51,33),
			alt: Decode(1057,1072,1081,1090,32,1053,1086,1074,1099,1093,32,1043,1086,1088,1086,1076,1086,1074),
			img:
			[
				'http://pic4.ru/images/f6b779270c1184f3f3bfb1c3a8d14422.png'
			],
			pos: 0,
			power: 18
		},
		{
			url: 'heroes1-5.at.ua',
			title: Decode(1057,1072,1081,1090,44,32,1087,1086,1089,1074,1103,1097,1077,1085,1085,1099,1081,32,1074,1089,1077,1083,1077,1085,1085,1099,1084,32,77,38,77,44,32,72,79,77,77,32,1080,32,75,66,46),
			alt: Decode(1043,1077,1088,1086,1081,1089,1082,1086,1077,32,1057,1086,1086,1073,1097,1077,1089,1090,1074,1086),
			img:
			[
				'http://pic4.ru/images/6618bac42204df853da2dd04f1ec50be.gif',
				'http://pic4.ru/images/08e8398f9dc132284f77d8f304e1f1a9.png',
				'http://pic4.ru/images/eefb513f8575a3f27aaa66dcfaa3eb3e.png'
			],
			pos: 0,
			power: 6
		},
		{
			url: 'geroi-3.narod.ru',
			title: Decode(71,101,114,111,105,45,51,46,110,97,114,111,100,46,114,117,32,45,32,1087,1088,1086,1089,1090,1086,32,1086,32,1089,1077,1090,1077,1074,1086,1081,32,1080,1075,1088,1077,32,1043,1077,1088,1086,1080,45,51,58,32,32,32,1075,1076,1077,32,1089,1082,1072,1095,1072,1090,1100,32,1080,1075,1088,1091,44,32,32,32,1082,1072,1082,32,1087,1086,1076,1082,1083,1102,1095,1080,1090,1100,1089,1103,44,32,32,32,1075,1076,1077,32,1085,1072,1081,1090,1080,32,1080,1075,1088,1086,1082,1086,1074),
			alt: Decode(1043,1077,1088,1086,1080,32,51,32,1054,1085,1083,1072,1081,1085),
			img:
			[
				'http://pic4.ru/images/e2232a591fd37b605403e67e88594732.gif',
				'http://pic4.ru/images/6e3e0f0dfd2a5873906a1691da0e96e5.gif',
				'http://pic4.ru/images/87dbbb7cdd1666a097a1b350a7ec3f07.gif',
				'http://pic4.ru/images/55963f2f02ec56e3b28da986482d14d8.gif'
			],
			pos: 0,
			power: 12
		},
		{
			url: 'heroes-m-and-m.com',
			title: Decode(1060,1072,1085,45,1089,1072,1081,1090,32,1089,1077,1088,1080,1080,32,1080,1075,1088,32,34,72,101,114,111,101,115,32,111,102,32,77,105,103,104,116,32,97,110,100,32,77,97,103,105,99,34),
			alt: Decode(1060,1072,1085,45,1089,1072,1081,1090,32,1043,1077,1088,1086,1077,1074),
			img:
			[
				'http://heroes-m-and-m.com/Knopki/1.gif',
				'http://heroes-m-and-m.com/Knopki/2.gif',
				'http://heroes-m-and-m.com/Knopki/3.gif',
				'http://heroes-m-and-m.com/Knopki/proba.jpg'
			],
			pos: 0,
			power: 8
		},
		{
			url: 'bers.heroes35.net/ahs/index.html',
			title: Decode(1040,1089,1089,1086,1094,1080,1072,1094,1080,1103,32,1043,1077,1088,1086,1081,1089,1082,1080,1093,32,1057,1072,1081,1090,1086,1074),
			alt: Decode(1040,1043,1057),
			img:
			[
				'http://pic4.ru/images/2ddbb409c333483c033fb8b8c93e596f.png'
			],
			pos: 0,
			power: 8
		}
	], // Flags
	CurrSite		=	GetShortSiteUrl(document.location.href),
	NumFlags		=	Flags.length,
	SumRating		=	0,
	FlagElem		=	null,
	RandomPos		=	-1,
	LeftInd			=	-1,
	RightInd		=	-1,
	SiteInd			=	-1,
	SlotFound		=	false,
	SiteFound		=	false,
	ImgInd			=	-1,
	SiteRating	=	-1,	
	i						=	-1,
	y						=	-1;
	i	=	1;
	while ((i < NumFlags) && (GetShortSiteUrl(Flags[i].url) !== CurrSite))
	{
		i++;
	}
	if (i < NumFlags)
	{
		Flags.splice(i, 1);
		NumFlags--;
	}
	for (i = 1; i < NumFlags; i++)
	{
		SumRating			=	SumRating + Flags[i].power;
		Flags[i].pos	=	SumRating;
	}
	i					=	1;
	SlotFound	=	true;
	while ((NumFlags > 1) && SlotFound)
	{
		FlagElem	=	document.getElementById('wogflag' + i);
		SlotFound	=	FlagElem !== null;
		if (SlotFound)
		{
			RandomPos	=	Math.random() * SumRating;
			LeftInd		=	1;
			RightInd	=	NumFlags;
			SiteFound	=	false;
			while (!SiteFound)
			{
				SiteInd	=	Math.floor((RightInd - LeftInd) / 2 + LeftInd);
				if (RandomPos > Flags[SiteInd].pos)
				{
					LeftInd	=	SiteInd + 1;
				}
				else if (RandomPos < Flags[SiteInd].pos)
				{
					if (RandomPos >= Flags[SiteInd - 1].pos)
					{
						SiteFound	=	true;
					}
					else
					{
						RightInd	=	SiteInd - 1;
					}
				}
				else
				{
					SiteInd++;
					SiteFound	=	true;
				}
			}
			FlagElem.href				=	'http://bers.heroes35.net/ahs/go.php?go=' + escape(Flags[SiteInd].url);
			FlagElem.title			=	Flags[SiteInd].title;
			FlagElem.alt				=	Flags[SiteInd].alt;
			FlagElem.target			=	'_blank';
			Url									=	Flags[SiteInd].url;
			if ((window.CustomAHSFlags !== undefined) && (CustomAHSFlags[Url] !== undefined))
			{
				Img	=	CustomAHSFlags[Url];
			}
			else
			{
				Img	=	Flags[SiteInd].img;
			}
			ImgInd							=	Math.floor(Math.random() * Img.length);
			FlagElem.innerHTML	=	'<img src="' + Img[ImgInd] + '">';
			SiteRating					=	Flags[SiteInd].power;
			SumRating						=	SumRating - SiteRating;
			for (y = SiteInd + 1; y < NumFlags; y++)
			{
				Flags[y].pos	=	Flags[y].pos - SiteRating;
			}
			Flags.splice(SiteInd, 1);
			i++;
			NumFlags--;
		}
	} // .while
})();
