// DOM ready
	 $(document).ready(function() {
	   
      // Create the dropdown base
      $("<select />").appendTo("#header2");
      
      // Create default option "Go to..."
      $("<option />", {
         "selected": "selected",
         "value"   : "",
         "text"    : "Go to..."
      }).appendTo("#header2 select");
 
	// Populate dropdown with menu items
      $("nav#menu > ul > li").each(function() {
      
        var el = $(this);
      
        var hasChildren = el.find("ul"),
            children    = el.find("li");
       
        if (hasChildren.length) {
        
                $("<optgroup />", {
                        "label": el.find("> a").text()
                }).appendTo("#header2 select");
                
                children.each(function() {
                                        
                        $("<option />", {
                                "text": " - " + $(this).text()
                        }).appendTo("optgroup:last");
                
                });
                        
        } else {
        
                $("<option />", {
                   "value"   : el.attr("href"),
                   "text"    : el.text()
               }).appendTo("#header2 select");
        
        } 
             
      });

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

