$.fn.extend({
    ajaxLoad: function(speed, callback) {
        if (typeof($(this).attr('href')) == "undefined") {
            return false;
        }

        if (typeof(speed) == "undefined") {
            speed = "slow";
        }

        $.post($(this).attr('href'), {_requested: true}, function(data) {
            $('#submenu').crossFade($(data).find('#submenu').children(), speed);
            $('#content').crossFade($(data).find('#content').children(), speed, function() {
                var source = data;
                var scripts = new Array();
     
                // Strip out tags
                while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
                    var s = source.indexOf("<script");
                    var s_e = source.indexOf(">", s);
                    var e = source.indexOf("</script", s);
                    var e_e = source.indexOf(">", e);
         
                    // Add to scripts array
                    scripts.push(source.substring(s_e+1, e));
                    // Strip from source
                    source = source.substring(0, s) + source.substring(e_e+1);
                }
     
                // Loop through every script collected and eval it
                for(var i=0; i<scripts.length; i++) {
                    try {
                        eval(scripts[i]);
                    }
                    catch(ex) {
                        // do what you want here when a script fails
                    }
                }
                
                if (typeof(callback) == "function") {
                    callback();
                }
            });
        });
    }
});

$(document).ready(function() {
    enableMenuLinks();
});

function enableMenuLinks() {
    $('#menu a').click(function(e) {
    /*
        var a = $(this);
        var headerContent = $('#header-content #header-' + ($(this).html()).toLowerCase() + '-page');
        var headerContentWrapper = $('#header-content');
        //Show the header content when needed
        if (headerContent.size() > 0) {
            $('#header-content .header-content-element').hide();
            headerContent.show();
            if (headerContentWrapper.height() == 0) {
                headerContentWrapper.animate({
                    height: headerContent.height() + "px"
                }, 1000);
            } else {
                var append = $('#header-content .header-content-element:not(#header-' + ($(this).html()).toLowerCase() + '-page');
                $('#header-content').crossFade($('#header-content #header-' + ($(this).html()).toLowerCase() + '-page'), 'slow');
                $('#header-content').append(append);
            }
            $('#menu li').removeClass('active');
            $(this).parent().addClass('active');
            e.preventDefault();
        } else if (headerContentWrapper.height() > 0) {
            e.preventDefault();
            headerContentWrapper.fadeOut("slow", function() {
                window.location = a.attr('href');
            });
        }
    */
    });
}
