'+$(this).html()+'
');\n $(this).replaceWith(p);\n\n // Copy over its attributes\n $.each($(this).get(0).attributes, function(i, a) {p.attr(a.nodeName, a.nodeValue);});\n if (p.attr('class')) {\n p.attr('class', p.attr('class') + ' legend');\n }\n else p.attr('class', 'legend');\n });\n },\n\n\n // Manage open/close/hasChild classes for a ul-based menu tree\n initMenu: function(root) {\n $(\"ul.menu\").each(function() {\n var $menu = $(this),\n timer,\n closeMenu, openMenu,\n mouseOverHandler, mouseOutHandler;\n\n openMenu = function($li) {\n if (timer) {\n clearTimeout(timer);\n timer = null;\n }\n\n if (!$li.hasClass(\"open\")) {\n $li.siblings(\"li.open\").each(function() { closeMenu($menu);});\n $li.addClass(\"open\").removeClass(\"closed\");\n }\n };\n\n closeMenu = function($li) {\n $li.find(\"li.open\").addBack().removeClass(\"open\").addClass(\"closed\");\n };\n\n mouseOverHandler = function() {\n var $li = $(this);\n openMenu($li);\n };\n\n mouseOutHandler = function() {\n var $li = $(this);\n\n if (timer) {\n clearTimeout(timer);\n timer=null;\n }\n\n timer = setTimeout(function() { closeMenu($li); }, 1000);\n };\n\n $(\"ul.menu li\", root)\n .addClass(\"closed\")\n .filter(\":has(ul)\").addClass(\"hasChildren\").end()\n .bind(\"mouseover.mapal\", mouseOverHandler)\n .bind(\"mouseout.mapal\", mouseOutHandler);\n });\n },\n\n // Utility method to facilitate AJAX content loading\n loadSnippet: function(url, selector, target, callback) {\n var $factory = $(\"\"),\n $target = $(\"#\"+target);\n\n if ($target.length===0) {\n $target = $(\"\")\n .css(\"opacity\", 0)\n .appendTo(document.body);\n }\n\n function htmlLoaded(data, textStatus, response) {\n if (response.status < 200 || response.status >= 400) {\n return;\n }\n\n $target.replaceWith(\n $factory.find(\"#\"+selector)\n .attr(\"id\", target)\n .css(\"opacity\", 0));\n $target = $(\"#\"+target);\n\n mapal.initContent($target);\n callback($target);\n }\n\n $target.animate({opacity: 0}, \"slow\", function() {\n url = url + \" #\" + selector;\n $factory.load(url, htmlLoaded);\n });\n },\n\n // Enable DOM-injection from anchors\n initDomInjection: function () {\n $(\"a[rel^='#']\").on(\"click.mapal\", function (e) {\n var $a = $(this),\n parts = $a.attr(\"href\").split(\"#\", 2),\n target = $a.attr(\"rel\").slice(1);\n\n mapal.loadSnippet(parts[0], parts[1], target, function($target) {\n $target.animate({opacity: 1}, \"fast\");\n });\n\n e.preventDefault();\n });\n },\n\n // Event handler for forms in a panel\n panelFormHandler: function(data, status, xhr, $form) {\n // regexp taken from jQuery 1.4.1\n var rscript = /