private function addContexts( &$document, $xbrldiPrefix )
	{
		foreach ( $this->contexts as $contextRef => $context )
		{
			$document[] = "  <context id=\"$contextRef\">";

			if ( isset( $context['entity'] ) )
			{
				$document[] = "    <entity>";

				if ( isset( $context['entity']['identifier'] ) )
				{
					$document[] = "      <identifier scheme=\"{$context['entity']['identifier']['scheme']}\">{$context['entity']['identifier']['value']}</identifier>";
				}

				if ( isset( $context['entity']['segment'] ) )
				{
					$this->addComponent( "segment", $context['entity']['segment'], $document, "      ", $xbrldiPrefix );
				}

				if ( isset( $context['entity']['scenario'] ) )
				{
					$this->addComponent( "scenario", $context['entity']['scenario'], $document, "    ", $xbrldiPrefix );
				}

				$document[] = "    </entity>";
			}

			if ( isset( $context['period'] ) )
			{
				$document[] = "    <period>";

				if ( $context['period']['is_instant'] )
				{
					$document[] = "      <instant>{$context['period']['startDate']}</instant>";
				}
				else if ( isset( $context['period']['type'] ) && $context['period']['type'] == 'forever' )
				{
					$document[] = "      <forever/>";
				}
				else if ( isset( $context['period']['type'] ) && $context['period']['type'] == 'duration' )
				{
					$document[] = "      <startDate>{$context['period']['startDate']}</startDate>";
					$document[] = "      <endDate>{$context['period']['endDate']}</endDate>";
				}
				$document[] = "    </period>";
			}

			if ( isset( $context['segment'] ) )
			{
				$this->addComponent( "segment", $context['segment'], $document, "    ", $xbrldiPrefix );
			}

			if ( isset( $context['scenario'] ) )
			{
				$this->addComponent( "scenario", $context['scenario'], $document, "  ", $xbrldiPrefix );
			}

			$document[] = "  </context>";
			$document[] = "";
		}
	}