        (function($) {
        $.fn.customFadeIn = function(speed, callback) {
                if (jQuery.browser.msie)
                {
                    $(this).show();
                    if (callback != undefined)
                        setTimeout(callback, 500);
                }
                else
                {
                    $(this).fadeIn(speed, function() {

                        if (callback != undefined)
                            setTimeout(callback, 500);
                    });
                }
                return $(this);
            };
            $.fn.customFadeOut = function(speed, callback) {
                if (jQuery.browser.msie)
                {
                    $(this).hide();
                    if (callback != undefined)
                        setTimeout(callback, 500);
                }
                else
                {
                    $(this).fadeOut(speed, function() {
                        if (jQuery.browser.msie)
                            $(this).get(0).style.removeAttribute('filter');
                        if (callback != undefined)
                            setTimeout(callback, 500);
                    });
                }
                return $(this);
            };
        })(jQuery);

jQuery.fn.ajaxable = function() {
    $(this).unbind("click");
    $(this).click(function() {
        if ($(this).attr)
            $.nav.go($(this).attr("href"));
        return false;
    });
};
jQuery.nav = {};

jQuery.nav.disable = function() {
    $.nav.enabled = false;
}
jQuery.nav.enable = function() {
    $.nav.enabled = true;
}
$.nav.enabled = true;
jQuery.nav.go = function(url) {
    if (url == "javascript:;") return;
    if (url.indexOf(".pdf") > 0) {
        $.nav.launch(url);
        return;
    }
    
    var validbrowser = !($.browser.msie && $.browser.version < 7);

    if ($.nav.enabled&&validbrowser) {
        var loc = $.nav.relative(url);
        var rt = $.nav.findroot(loc);
        var it = $.nav.finditem(loc);
        var forceredirect = $.nav.current.attr("url") == null || !$.nav.current.parent().is("node") || !it.parent().is("node") || (!it.parent().parent().is("node")) || it.attr("root") == "true";

        if ($.address&&!forceredirect && rt.attr("url") == $.nav.root.attr("url")) {
            $.address.value($.nav.relative(loc));
            closeTier2();
        }
        else $.nav.launch(url);
    }
    else $.nav.launch(url);
}

jQuery.nav.launch = function(url) {
    if (url.indexOf(".pdf") >= 0) window.open(url, "_blank");
    else document.location = url;
}
jQuery.nav.xml = $("<node />");
jQuery.nav.relative = function(url,striphash) {
    url = url.replace("http://" + document.domain, "");
    if (striphash)
        url = url.split("#")[0];
    return url;
}

jQuery.nav.currentLocation = function() {
    var value = ($.address)?$.address.value():"";
    if (value == "" || value == "/") value = String(document.location);
    value = $.nav.relative(value,true);
    return value;
};
jQuery.nav.finditem = function(url) {
    var loc_str = url.replace(/\//g, "\/").replace(/\./g, "\.");
    var item = $.nav.xml.find("node[url=" + loc_str + "]");

    return item;
};
jQuery.nav.findroot = function(url) {
    var item = $.nav.finditem(url);
    if (item.parent().length == 0) return item;
    var cur = item;
    while (cur.attr("root") != "true" && cur.length > 0) {
        cur = cur.parent();
    }
    return cur;
};

var ajaxableFirstLoad = true;

jQuery.trim = function (value) {
    var temp = value;
    var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
    if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
    var obj = /  /g;
    while (temp.match(obj)) { temp = temp.replace(obj, " "); }
    return temp;
}
jQuery.ajaxableChange = function(value) {
    if (!ajaxableFirstLoad) {
        if (value == "" || value == "/") value = String(document.location);
        value = $.nav.relative(value);
        $.nav.nextprevout();
        $("#pagecontent").customFadeOut(400, function() {
            $("#ajaxloader").show();
            $.ajax({ url: value, context: document.body, error: function(request, status, error) {
             //   alert("error loading page " + value);
                $("#ajaxloader").hide();
                $("#pagecontent").customFadeIn(400);
            }, success: function(data) {

                var content = String(data)
                data = $(data);
                var r; // = new RegExp("<link[^>]*>([^>]*)\/>", "ig");
                var results; //  = content.match(r);
                var head; //  = $("head").html();
                //                for (var i = 0; results != null && i < results.length; i++) {
                //                    try {
                //                        if (head.indexOf(results[i]) < 0)
                //                            $("head").append($(results[i]));
                //                    } catch (e) { alert(e); }
                //                }
                var title_str = content.match(/(<title.*?>)([\s\S]*?)(<\/.*?title>)/ig);
                title_str = String(title_str).replace(/(<title.*?>)/ig, "").replace(/(<\/.*?title>)/ig, "");
                title_str = title_str.replace("\n","").replace("\r","");
                $.address.title(null);
                $.address.title($.trim(title_str.split(",")[0]));
                var pagecontent = $("#pagecontent");
                pagecontent.html(data.find("#pagecontent").html());

                $("#ajaxloader").hide();
                $("#nextlink").show();
                $("#prevlink").show();
                var nxt = data.find("#nextlink").first();
                var nxtlnk = nxt.find("a").first();
                var prv = data.find("#prevlink").first();
                var prvlnk = prv.find("a").first();

                var nxtc = $("#nextlink").first();
                var nxtclnk = nxtc.find("a").first();
                var prvc = $("#prevlink").first();
                var prvclnk = prvc.find("a").first();

                if (nxt.css("display") == "none" || nxtlnk.attr("href") == null) nxtc.hide();
                //else nxtc.show();
                if (prv.css("display") == "none" || prvlnk.attr("href") == null) prvc.hide();
                //else prvc.show();


                $("#prevlink a").unbind("mouseover").unbind("mouseout");
                $("#nextlink a").unbind("mouseover").unbind("mouseout");

                nxtc.html(nxt.html());
                prvc.html(prv.html());

                $("#prevlink a").mouseover($.nav.nextprevover).mouseout($.nav.nextprevout);
                $("#nextlink a").mouseover($.nav.nextprevover).mouseout($.nav.nextprevout);
                pagecontent.customFadeIn(400);
                if ($("#menuicon img").attr("src") != data.find("#menuicon img").attr("src")) {
                    $("#menuicon").hide("slide", { direction: "down" }, 500, function() {
                        $("img", this).attr("src", data.find("#menuicon img").attr("src"));
                        $(this).show("slide", { direction: "down" }, 500);
                    });
                }

                $("a.ajaxablelink").ajaxable();

                if (content) {
                    var regex = /(<style.*?>)([\s\S]*?)(<\/.*?style>)/ig;
                    var result = regex.exec(content);

                    while (result) {
                        var style = result[2];

                        if ($.trim(style).length > 0) {
                            pagecontent.append("<style>" + style + "</" + "style>");
                        }
                        result = regex.exec(content);
                    }

                    regex = /(<script.*?>)([\s\S]*?)(<\/.*?script>)/ig;
                    result = regex.exec(content);

                    while (result) {
                        var script = result[2];

                        if ($.trim(script).length > 0 && script.indexOf("google-analytics")<0) {
                            try { eval(script); } catch (e) { alert(e); }
                            pagecontent.append("<script type=\"text/javascript\">" + script + "</" + "script>");
                        }
                        result = regex.exec(content);
                    }

                }

            }
            });

        });
    }
    ajaxableFirstLoad = false;
    return false;
}

$.nav.nextprevover = function() {
    var title = $("#linkdesc");
    if (title.length == 0) {
        $("body").append("<div id=\"linkdesc\"></div>");
        title = $("#linkdesc");
    }
    $("#linkdesc").show();
    title.html($(this).attr("title"));
    var position = {};
    position.top = $(this).parent().offset().top + (title.height() / 2);
    if ($(this).parent().is("#prevlink"))
        position.left = $("#prevlink").offset().left + $("#prevlink").width() + 10;
    if ($(this).parent().is("#nextlink"))
        position.left = $("#nextlink").offset().left - title.width()-15;
    title.offset(position);
    
}
$.nav.nextprevout = function() {
    $("#linkdesc").hide();
}

var zindexswap = false;
function urlLoad(url) {
    $.nav.go(url);
}
function menuRollover() {
    if (zindexswap) {
        $("#flashmenu").css("z-index", "6");
        $("#contentCenterColumn").css("z-index", "2").height(530);
        $(".ajaxablecontent").height(530);
        $("#contentContainer").height(530);
    }
}
function menuRollout() {
    if (zindexswap) {
        $("#flashmenu").css("z-index", "2");
        $("#contentCenterColumn").css("z-index", "4").height(465);
        $("#contentContainer").height(465);
    }
}

$(document).ready(function() {
    if (!($.browser.msie && $.browser.version < 7)) {
        if ($.address) {
            $.address.init(function() {
                $.address.change(function(event) {
                    var value = event.value;
                    if ($.nav.enabled)
                        top.$.ajaxableChange(value);
                    if (value == "" || value == "/") value = String(document.location);
                    value = $.nav.relative(value);
                    if ($("#flashmenucontent")[0] && $("#flashmenucontent")[0].setUrl)
                        $("#flashmenucontent")[0].setUrl(value);
                });
            });
        }

        $.ajax({ url: "/site.xml", context: document.body, success: function(data) {
            $.nav.xml = $(data);
            // $.nav.roots = $.nav.xml.find("node[root=true]");
            var loc = $.nav.currentLocation();
            $.nav.current = $.nav.finditem(loc);
            $.nav.root = $.nav.findroot(loc);
        }
        });
    }

    $("#prevlink a").mouseover($.nav.nextprevover);
    $("#nextlink a").mouseover($.nav.nextprevover);
    $("#prevlink a").mouseout($.nav.nextprevout);
    $("#nextlink a").mouseout($.nav.nextprevout);
    menuRollout();

});
if ($.address!=null&&$.address.value() != "/" && $.address.value() != document.location) {
    document.location = $.address.value();
}

