// DOM ready
$(function() {
 
// Create the dropdown base
$("<select />").appendTo("#topnav nav");

// Create default option "Go to..."
$("<option />", {
   "selected": "selected",
   "value"   : "",
   "text"    : "Go to section..."
}).appendTo("#topnav select");

// Populate dropdown with menu items
$("#topnav a").each(function() {
 var el = $(this);
	 if(el.attr("class")=='current') 
		var classCurrent=" (current)";
     else 
		var classCurrent="";
	 $("<option />", {
	 "value"   : el.attr("href"),
	 "text"    : el.text() + classCurrent
 }).appendTo("#topnav select");
});

 // To make dropdown actually work
 // To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
$("#topnav select").change(function() {
  window.location = $(this).find("option:selected").val();
});

$("<select />").appendTo("nav#side-bar");

// Create default option "Go to..."
$("<option />", {
   "selected": "selected",
   "value"   : "",
   "text"    : "Go to page..."
}).appendTo("#side-bar select");

// Populate dropdown with menu items
$("#side-bar a").each(function() {
 var sb = $(this);
	 $("<option />", {
	 "value"   : sb.attr("href"),
	 "text"    : sb.text()
 }).appendTo("#side-bar select");
});

 // To make dropdown actually work
 // To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
$("#side-bar select").change(function() {
  window.location = $(this).find("option:selected").val();
});

});

