$(document).ready(function()
{
    // enhance the navigation styling
    $('li#main-nav-homepage a').html('<img id="home-icon" src="/images/icon.home.png" alt="" />');
    
    // don't create the menu in IE6 so exit here
    if(typeof document.body.style.maxHeight === "undefined")
    {
        return false;
    }

    var menuloaded = false;

    // add dropdown menu
    whatwedo_html = $('li#main-nav-whatwedo a').html();
    $('li#main-nav-whatwedo a').html(whatwedo_html + '<img id="nav-menu" src="/images/nav.arrow.png" alt="" />');
    $('li#main-nav-whatwedo a').css('padding-right', '0');
    
    // add the menu icon
    $('img#nav-menu').css('vertical-align', 'middle');
    $('img#nav-menu').css('margin-left', '1em');
    $('img#nav-menu').css('border', '0');
    $('img#nav-menu').css('position', 'relative');
    $('img#nav-menu').css('top', '-1px');
    $('img#nav-menu').css('cursor', 'pointer');
    
    // load menu content via AJAX and insert into page
    menu = document.createElement('DIV');
    $(menu).attr('id', 'whatwedo-menu');
    $(menu).css('opacity', '0.99');
    
    $('body').prepend(menu);
    
    // show/hide menu and alter icon style
    $("img#nav-menu").mouseover(function()
    {
		// place menu correctly aligned to the menu icon
		coords = $('#nav-menu').offset();
		$('div#whatwedo-menu').css('top', coords.top + $('#nav-menu').height());
		$('div#whatwedo-menu').css('left', coords.left - 200);
		$('div#whatwedo-menu').fadeIn(200);
		
		if(!menuloaded)
		{
		    // menu independant file, can be served via http or https
		    $("#whatwedo-menu").load("/menu.php", '', function()
		    {
		        $("div#indicator").hide();
		        $("#whatwedo-menu ul").fadeIn();
		        menuloaded = true;
		    });
		}
		
        $(this).attr('src', '/images/nav.arrow.selected.png');
    });
    
    $("div#whatwedo-menu").bind('mouseleave', function()
    {
        $(this).fadeOut(200);
        $('img#nav-menu').attr('src', '/images/nav.arrow.png');
    });
});
