// Core JavaScript functions for the Liberal Arts Career Services site

// This file should be included on all pages other than the home page.
$(document).ready(function() {

    $("ul.menu li:not(.active-trail)").find("ul:first").hide();
    
    // Extend the height of the left sidebar to match the height
    // of the mainContent div
    
    if ($("#sidebar1").height() < $("#mainContent").height()) {
        $("#sidebar1").height($("#mainContent").height());
    }
    
    
    // Hover functionality for left sidebar navigation, using
    // jquery.hoverIntent plugin to delay hover action
    // See http://cherne.net/brian/resources/jquery.hoverIntent.html
    // for documentation.

    // Callback for onMouseOver event
    function showMenu(event) {
        $(this).find("ul:first").show("fast");
    };
    
    // Callback for onMouseOut event
    function hideMenu(event) {
        $(this).find("ul:first").hide("fast");
    };
    
    // Config object for hoverIntent
    var hoverConfig = {
        sensitivity: 3,
        interval: 200,
        over: showMenu,
        timeout: 350,
        out: hideMenu
    };
    
    $("ul.menu li:not(.active-trail)").hoverIntent( hoverConfig );
    
    // Specific behaviors for the LACS Staff view page to hide and show bios.
    $(".views-field-field-lacs-staff-bio-value").hide();
    $(".views-field-body > .field-content > p").append(' <a href="#" class="bio-switch show">More...</a>');
    $("a.bio-switch").click(function(event) {
        $(this).parent().parent().parent().next().toggle();
        $(this).toggleClass('show').toggleClass('hide');
        if ($(this).hasClass('hide')) {
            $(this).text('Less...');
        } else {
            $(this).text('More...');
        }
        event.preventDefault();
    });

    // This standardizes all of the movie objects on the video
    // view page to a width of 250 pixels, and refactors the height
    // proportionally.
    var goalWidth = 250;
    $("div.video-preview-player").each(function() {
        var $featureObj = $(this).children(":first");
        var resizeFactor = goalWidth / $featureObj.attr('width');
        var goalHeight = $featureObj.attr('height') * resizeFactor;
        goalHeight = goalHeight | 0;
        $featureObj.attr('width', goalWidth);
        $featureObj.attr('height', goalHeight);
        $featureObj.find('embed').attr('width', goalWidth);
        $featureObj.find('embed').attr('height', goalHeight);
    });
    
});