/**
 * This is the main javascript module for the site.
 */

$(document).ready(
    function() {
	// Set background gradient
        $('#contentsBox').gradient({ from: 'b96518', to: 'ecd559' });
	
	$(".menu_left").each(
	    function() {
		$(this).corner("round right 6px");
	    });

	$(".menu_mid").each(
	    function() {
		$(this).corner("round 6px");
	    });

	// Expand includes; call finishMenus when done
	$(".js_include").each(
            function() {
		var uri = document.URL;
		uri = uri.replace(/[^\/\\]+?(\?.*)?$/, "");
		uri += $(this).attr("include");//debug + "?t=" + Math.random();
		var menubar = $(this).hasClass("menubar") ? $(this) : null;
		$(this).removeClass("js_include");
		$(this).load(
                    uri, '',
                    function (responseText, textStatus, XMLHttpRequest) {
			if (menubar)
			    menubar.buildMenu({
				template:"menu.htm",
				openOnRight:false,
				menuSelector: ".menuContainer",
				iconPath:"images/",
				hasImages:true,
				fadeInTime:100,
				fadeOutTime:300,
				adjustLeft:2,
				minZindex:"auto",
				adjustTop:10,
				opacity:.95,
				shadow:true,
				openOnClick:false,
				closeOnMouseOut:true,
				closeAfter:1500,
				hoverIntent: 100
			    });
                    });
            });

	// Link postcodes to google maps
	$('span.postcode').each(function() {
	    $(this).after('<a class="map" href="http://maps.google.co.uk/maps?q='
				+ $(this).text() + '"> map</a>');
	});

	// Link google maps references to google maps
	$('span.gmap').each(function() {
	    $(this).replaceWith('<a class="map" href="http://maps.google.co.uk/maps?q='
				+ $(this).text() + '"> map</a>');
	});
    });

