/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the versification table for this versification
		/// </summary>
		/// <param name="vers"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static VersificationTable Get(ScrVers vers)
		{
			Debug.Assert(vers != ScrVers.Unknown);

			if (versifications == null)
				versifications = new VersificationTable[versificationFiles.GetUpperBound(0)];

			// Read versification table if not already read
			if (versifications[(int)vers] == null)
			{
				versifications[(int)vers] = new VersificationTable(vers);
				ReadVersificationFile(FileName(vers), versifications[(int)vers]);
			}

			return versifications[(int)vers];
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Read versification file and "add" its entries.
		/// At the moment we only do this once. Eventually we will call this twice.
		/// Once for the standard versification, once for custom entries in versification.vrs
		/// file for this project.
		/// </summary>
		/// <param name="fileName"></param>
		/// <param name="versification"></param>
		/// ------------------------------------------------------------------------------------
		private static void ReadVersificationFile(string fileName, VersificationTable versification)
		{
			using (TextReader reader = new StreamReader(fileName))
			{
				for (string line = reader.ReadLine(); line != null; line = reader.ReadLine())
				{
					line = line.Trim();
					if (line == "" || line[0] == '#')
						continue;

					if (line.Contains("="))
						ParseMappingLine(fileName, versification, line);
					else
						ParseChapterVerseLine(fileName, versification, line);
				}
			}
		}
		// Parse lines giving number of verses for each chapter like
		// GEN 1:10 2:23 ...
		private static void ParseMappingLine(string fileName, VersificationTable versification, string line)
		{
			try
			{
				string[] parts = line.Split('=');
				string[] leftPieces = parts[0].Trim().Split('-');
				string[] rightPieces = parts[1].Trim().Split('-');

				BCVRef left = new BCVRef(leftPieces[0]);
				int leftLimit = leftPieces.GetUpperBound(0) == 0 ? 0 : int.Parse(leftPieces[1]);

				BCVRef right = new BCVRef(rightPieces[0]);

				while (true)
				{
					versification.toStandard[left.ToString()] = right.ToString();
					versification.fromStandard[right.ToString()] = left.ToString();

					if (left.Verse >= leftLimit)
						break;

					left.Verse = left.Verse + 1;
					right.Verse = right.Verse + 1;
				}
			}
			catch
			{
				// ENHANCE: Make it so the TE version of Localizer can have its own resources for stuff
				// like this.
				throw new Exception("Invalid [" + line + "] " + fileName);
			}
		}
		// Parse lines mapping from this versification to standard versification
		// GEN 1:10	= GEN 2:11
		// GEN 1:10-13 = GEN 2:11-14
		private static void ParseChapterVerseLine(string fileName, VersificationTable versification, string line)
		{
			string[] parts = line.Split(' ');
			int bookNum = BCVRef.BookToNumber(parts[0]);
			if (bookNum == -1)
				return; // Deuterocanonical books not supported
			
			if (bookNum == 0)
				throw new Exception("Invalid [" + parts[0] + "] " + fileName);

			while (versification.bookList.Count < bookNum)
				versification.bookList.Add(new int[1] { 1 });

			List<int> verses = new List<int>();

			for (int i = 1; i <= parts.GetUpperBound(0); ++i)
			{
				string[] pieces = parts[i].Split(':');
				int verseCount;
				if (pieces.GetUpperBound(0) != 1 ||
					!int.TryParse(pieces[1], out verseCount) || verseCount <= 0)
				{
					throw new Exception("Invalid [" + line + "] " + fileName);
				}

				verses.Add(verseCount);
			}

			versification.bookList[bookNum - 1] = verses.ToArray();
		}