jQuery(document).ready(function($){
	var QuinyxSelectMenu = (function ($, _) {
		// Constructor
		function QuinyxSelectMenu(menu) {
			// Put the active element first. Always put non-active
			// menu items below the active item (there is no way to do
			// this from T3).
			// We do this by creating a copy of active, called newActive.

			// We wrap whole menu in a div.quinyx-select-wrap. This is
			// probably to do some css on it. Since wrap() returns the
			// wrapped element, and not the wrapper it self, we need
			// to apply parent() in order to get the wrapper.
			var wrap = $(menu).wrap('<div class="quinyx-select-wrap" />').parent();

			// Find a active element and separate it from the others.
			var active = $(menu).children('.active');
			if (!active.length) {
				// There is no active item. This should never happen
				// on the real web page, since every page is in one
				// and only one region.
				return;

			}

			// Create a new div, give it the text of active, set class
			// to the class of active, and insert it before menu.
			var newActive = $('<div />')
				.text(active.text())
				.attr('class', active.attr('class'))
				.insertBefore(menu);

			// Now we can remove active, since we have a copy.
			active.remove();

			// When the active element is clicked, the dropdown is
			// shown, and the wrapper gets a visible clas.
			$(newActive).click(function () {
				menu.show();
				wrap.addClass('dropdown-visible');
			});

			// When the mouse leaves the wrapper, the dropdown is
			// hidden, and the visible class is removed from the wrap.
			$(wrap).mouseleave(function () {
				wrap.removeClass('dropdown-visible');
				menu.hide();
			});
		}

		QuinyxSelectMenu.prototype = {};

		return QuinyxSelectMenu;
	})($);
	new QuinyxSelectMenu($('#region-select'));

	$('h1,h2,h3,h4').each(function(){
		// add 10px margin to the end of all paragraphs followed by a
		// h1, h2, h3 or h4
		$(this).prev('p').css('margin-bottom', '10px');

		// add 23px margin to the end of all uls followed by a
		// h1, h2, h3 or h4
		$(this).prev('ul').css('margin-bottom', '23px');
	});

	/*
	var w = 0;
	$("div#menu ul li").each(function(){
		w += $(this).width() + 15;


	});
	$("div#menu ul").css({"width": w + "px", "margin":"0 " + (w/2) + "px"});
	*/
});

