<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>${headers['title']} ${headers['version']} - ${headers['subtitle']}</title>
		<link href="bootstrap/css/bootstrap.min.css?${version}" rel="stylesheet" />
		<link href="css/page.css?${version}" rel="stylesheet" />
	</head>
	<body>
		<div class="navbar navbar-fixed-top navbar-inverse">
			<div class="navbar-inner">
				<div class="_container">
					<a class="brand" href="#">${headers['title']} ${headers['subtitle']} <small>${headers['version'].replace("version ", "")}</small></a>
					<ul class="nav">
						<li class="divider-vertical"></li>
						<li><a href="http://haproxy.1wt.eu/">HAProxy home page</a></li>
						<li class="dropdown">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								Versions
								<b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								## TODO : provide a structure to dynamically generate per version links
								<li class="dropdown-submenu">
									 <a tabindex="-1" href="#">HAProxy 1.4</a>
									 <ul class="dropdown-menu">
										<li><a href="configuration-1.4.html">Configuration Manual</a></li>
										<li class="divider"></li>
										<li><a href="http://git.1wt.eu/git/haproxy-1.4.git/">GIT Repository</a></li>
										<li><a href="http://haproxy.1wt.eu/git/?p=haproxy-1.4.git">Browse repository</a></li>
										<li><a href="http://haproxy.1wt.eu/download/1.4/">Browse directory</a></li>
									</ul>
								</li>
								<li class="dropdown-submenu">
									 <a tabindex="-1" href="#">HAProxy 1.5</a>
									 <ul class="dropdown-menu">
										<li><a href="configuration-1.5.html">Configuration Manual</a></li>
										<li class="divider"></li>
										<li><a href="http://git.1wt.eu/git/haproxy.git/">GIT Repository</a></li>
										<li><a href="http://haproxy.1wt.eu/git/?p=haproxy.git">Browse repository</a></li>
										<li><a href="http://haproxy.1wt.eu/download/1.5/">Browse directory</a></li>
									</ul>
								</li>
							</ul>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<div class="navbar navbar-fixed-bottom navbar-inverse">
			<div class="navbar-inner">
				<ul class="nav">
					<li id="previous"></li>
				</ul>
				<ul class="nav pull-right">
					<li id="next"></li>
				</ul>
			</div>
		</div>
		<div class="affix" id="menu-left">
			<div class="container-fluid">
				<form class="form" onsubmit="search(this.keyword.value); return false">
					<input id="searchKeyword" type="text" name="keyword" class="search-query input-block-level" placeholder="Search keyword" autocomplete="off"/>
				</form>
				<div id="error"></div>
				<p>
					Keyboard navigation&nbsp;: <span id="keyboardNavStatus"></span>
				</p>
				<p>
					When enabled, you can use <strong>left</strong> and <strong>right</strong> arrow keys to navigate between chapters.<br>
					The feature is automatically disabled when the search field is focused.
				</p>
				<p class="text-right">
					<small>Converted with <a href="http://github.com/cbonte/haproxy-dconv">haproxy-dconv</a> v<b>${version}</b> on <b>${date}</b></small>
				</p>
			</div>
		</div>
		<div class="container-fluid" id="main">
			<div class="row-fluid">
				<div class="span12">
					<div class="well pagination-centered">
						<h1>${headers['title']}</h1>
						<h2>${headers['subtitle']}</h2>
						<p><strong>${headers['version']}</strong></p>
						<p>
							<a href="http://haproxy.1wt.eu/" title="HAProxy Home Page"><img src="http://haproxy.1wt.eu/img/logo-med.png" /></a><br>
							${headers['author']}<br>
							${headers['date']}
						</p>
					</div>
					
					${document}
				</div>
			</div>
		</div>

		<script src="js/jquery.min.js?${version}"></script>
		<script src="bootstrap/js/bootstrap.min.js?${version}"></script>

		<script>
			/* Keyword search */
			var searchFocus = false
			var keywords = [
				"${'",\n\t\t\t\t"'.join(keywords)}"
			]
			
			function updateKeyboardNavStatus() {
				var status = searchFocus ? '<span class="label label-disabled">Disabled</span>' : '<span class="label label-success">Enabled</span>'
				$('#keyboardNavStatus').html(status)
			}

			function search(keyword) {
				if (keyword) {
					if (!!~$.inArray(keyword, keywords)) {
						window.location.hash = keyword
						$("#error").html('')
					} else {
						var error = $('<div/>', {
							"class": "alert alert-error"
						}).html('\
							<a class="close" href="#" data-dismiss="alert">&times;</a>\
							<strong>Unknown keyword !</strong>\
							<p>The keyword <strong class="unknown"></strong> you\'re looking for doesn\'t exist or is not detected by the documentation converter.</p>\
						')
						error.find(".unknown").text(keyword)

						$("#error").html(error)
					}
				}
			}
			
			$('#searchKeyword').typeahead({
				source: keywords,
				updater: function(item) {
					search(item)
					return item
				}
			}).focus(function() {
				searchFocus = true
				updateKeyboardNavStatus()
			}).blur(function() {
				searchFocus = false
				updateKeyboardNavStatus()
			})

			/* EXPERIMENTAL - Previous/Next navigation */
			var headings = $(":header")
			var previousTarget = false
			var nextTarget = false
			function refreshNavigation() {
				var previous = false
				var next = false
				$.each(headings, function(item, value) {
					var el = $(value)

					// TODO : avoid target recalculation on each refresh
					var target = el.attr('data-target')
					if (! target) return true

					var target_el = $('#' + target.replace(/\./, "\\."))
					if (! target_el.attr('id')) return true

					if (target_el.offset().top < $(window).scrollTop()) {
						previous = el
					}
					if (target_el.offset().top - 1 > $(window).scrollTop()) {
						next = el
					}
					if (next) return false
				})
				previousTarget = previous ? previous.attr('data-target') : 'top'
				$('#previous').html(
					previous && previousTarget ? '<a href="#' + previousTarget + '">&larr; ' + previous.text() + '</a>' : '<a href="#top">&larr; Top</a>'
				)
				nextTarget = next ? next.attr('data-target') : 'bottom'
				$('#next').html(
					next && nextTarget ? '<a href="#' + nextTarget + '">' + next.text() + ' &rarr;</a>' : '<a href="#bottom">Bottom &rarr;</a>'
				)
			}

			$(window).scroll(function () {
				refreshNavigation()
			});
			$(document).ready(function() {
				refreshNavigation()
				updateKeyboardNavStatus()
			});

			/* EXPERIMENTAL - Enable keyboard navigation */
			$(document).keydown(function(e){
				if (searchFocus) return

				switch(e.which) {
					case 37: // left
					window.location.hash = previousTarget ? previousTarget : 'top'
					break

					case 39: // right
					window.location.hash = nextTarget ? nextTarget : 'bottom'
					break

					default: return // exit this handler for other keys
				}
				e.preventDefault()
			})
		</script>
		${footer}
		<a class="anchor" name="bottom"></a>
	</body>
</html>
