jq(document).ready(function() {
    // Move heading and description up to featured content container.
    // If a carousel was added, then use this instead.
    if (jq(".carouselWrapper").length == 0) {
        jq("#featured-content").addClass("banner");
        jq("h1.documentFirstHeading").appendTo("#featured-content");
        if (jq("body").hasClass("template-translate_item") == false) {
            jq("p.documentDescription").appendTo("#featured-content");
        }
    } else {
        jq("#featured-content").addClass("carousel-banner");
        jq(".carouselWrapper").appendTo("#featured-content");
    }
    
    // If 'Slider Content View' was selected add markup and functionality.
    if (jq(".slider-content").length > 0) {
        var html = '<div class="slider-control"><a href="#" >details</a></div>';
        jq(".slider-content h2.slider-headline").after(html);
        jq(".slider-content .slider-detail").hide();
        
        jq(".slider-control").each(function() {
            jq(this).bind("click", function() {
                jq(this).find("a").toggleClass("active");
                jq(this).parent().find(".slider-detail").slideToggle();
                return false;
            })
        });
    }

    // Add functionality to package views    
    if (jq(".package-detail").length > 0) {
        // First hide all detail boxes.
        jq(".package-detail").hide();
        
        // Then bind the click event to the package links
        jq(".package-link").each(function() {
            jq(this).bind("click", function() {
                jq(".package-detail").hide();
                var target = jq(this).attr('href');
                jq(target).fadeIn();
                return false;
            })
        });
    }


/*
    // Open pipbox links in a new tab
    jq('.pipbox-iframe').each(function() {
        jq(this).attr('target', '_blank');
    });
*/
    // Show pipbox links as overlay
    jq('.pipbox-iframe').prepOverlay({
        subtype:'ajax',
        urlmatch:'$',urlreplace:' #content > *',
        config: {
            expose:{color:'black', opacity:0.7},
        }
    });

});