$().ready(function() {

    // Using the current path (e.g. /Section/Page)
    var path = location.pathname;

    // Header
    var flashvars = {};
    var flashparams = { wmode: "transparent" };
    var flashatts = {};

    var flashFile = "CMLFheaderNOSOUND";
    if (path == "/") {
        flashFile = "CMLFheader";
    }

    swfobject.embedSWF("/App_Themes/CMLF/Flash/" + flashFile + ".swf", "cmlfboatheader", "920", "200", "7", false, flashvars, flashparams, flashatts, null);

    $(".highslide-gallery-items > a:first").remove();

    // Highslide

    // Global settings
    hs.graphicsDir = '/App_Themes/Default/highslide/graphics/';
    hs.outlineType = 'rounded-white';
    hs.showCredits = false;
    hs.align = 'center';
    hs.transitions = ['expand', 'crossfade'];
    hs.fadeInOut = true;
    hs.numberPosition = 'caption';
    hs.dimmingOpacity = 0.75;

    // Add the controlbar
    if (hs.addSlideshow) hs.addSlideshow({
        //slideshowGroup: 'group1',
        interval: 5000,
        repeat: false,
        useControls: true,
        fixedControls: 'fit',
        overlayOptions: {
            opacity: .75,
            position: 'bottom center',
            hideOnMouseOut: true
        }
    });



    // Kwicks
    $(".kwicks li .kwick_content").hide().wrapInner("<div class='kcw'></div>");
    $(".kwicks li img").each(function() {
        if ($(this).parents().find(".kwick_content").text()) {
            $(this).qtip({
                content: $(this).parents().find(".kwick_content").html(), show: { delay: 0 }, hide: { fixed: true, delay: 200 }, position: { corner: { target: 'rightMiddle', tooltip: 'leftMiddle' }, adjust: { x: 0, y: 0} }, style: { name: 'light', width: 500, background: 'url(/App_Themes/CMLF/Images/flyout-bg.png) no-repeat', border: { width: 6, radius: 8, color: "#20498B" }, tip: { corner: 'leftMiddle', color: '#20498B'} }
            });
        }
    });

    // Programs
    $("li div.popup", "#programs").hide();
    $("li div.map-icon", "#programs").each(function() {
        $(this).qtip({
            content: $(this).parent().find("div.popup").html(), show: { delay: 0 }, hide: { fixed: true, delay: 200 }, position: { corner: { target: $(this).attr('target'), tooltip: $(this).attr('tooltip') }, adjust: { x: 0, y: 0} }, style: { name: 'light', width: 430, background: '#FFFFFF', border: { width: 6, radius: 8, color: "#20498B" }, tip: { corner: $(this).attr('tooltip')} }
        });
    });

    // Tabs
    $('#tabs').tabs();

    // Handle links to the current path
    if (path) {
        $('a[href$="' + path + '"]').addClass('active');

        // Partial Match
        var partial = path.substring(0, path.lastIndexOf('\/'));

        // If not at the root
        if (partial != "") {
            $('a[href$="' + partial + '"]').addClass('active');
        }

        // Handle links to parts of the current path
        var parts = path.split('\/')
        for (i = 0; i < parts.length; i++) {
            if (parts[i].length > 0) {
                $('a[href$="/' + parts[i] + '"]').addClass('active');
            }
        }
    }
});