﻿/* Berkeley Law Homepage-only Effects (requires jQuery) */
/* by White Whale Web Services */

$(document).ready(function() {
    /* Portals */
    $('#content').after('<div id="portals_content"></div>');    
    $('#portals_content').load('/783.htm?2008-05-30 .portal');
    $('#portals>li>a').click(function() {
        $(this).parent().toggleClass('selected').siblings().removeClass('selected');
        if($(this).parent().hasClass('selected')) {
            $('#portals_content').show().find('#'+$(this).parent().attr('id')+'_content').show().siblings().hide();
            $('#search').addClass('inside');
            $('#q').val('').css('font-weight','normal');
        } else {
            $('#portals_content').hide().children().hide();    
            $('#search').removeClass('inside');
            $('#q').each(function() { if(!$(this).val()) $(this).val('Search Berkeley Law').css('font-weight','bold'); });
        }
        return false; // cancel the link click
    });
    /* Line-up news and sidebar areas */
    var news = $('#news'),
        sidebar = $('#thesidebar'),
        featurearea = $('#thesidebar_features');
        features = featurearea.children().css({position:'absolute',top:0,left:0,display:'block',opacity:0}), // get the sidebar features, show them, and position them absolutely
        featureheight = 0;
    features.each(function() { // Find the tallest feature
        var height = $(this).height();
        if(height>featureheight) featureheight = height;
    }).height('100%'); // then set them all to 100% height
    featurearea.height(featureheight); // fix the feature are aheight
    news.add(sidebar).css({minHeight:'0',height:'auto'}) // first remove any fixed height
        .height(Math.max(news.height(),sidebar.height())); // then set the height of both to the greater of the two
    /* Sidebar */
    features.eq(0).addClass('current').css('opacity',1); // move the first one to the top and show it
    $('#thesidebar_next').click(function() { // when clicking next
        var next = features.filter('.current').next(); // get the feature after the topmost feature
        if(!next.length) next = features.eq(0); // if there's no next, start back at the first item
        features.stop().removeClass('current'); // stop all feature animations
        next.addClass('current').fadeTo(500,1,function() { // fade it in
                $(this).siblings().css({opacity:0}); // after which we can safely hide the siblings again
            }); // immediately move the siblings lower in the stack
        return false; // cancel the link click
    });
    
    /* Tabs */
    $('.tabs a').click(function() { // when clicking a tab
        $(this).parent().addClass('active').siblings().removeClass('active'); // give it the active class, and remove the other active classes
        $($(this).attr('href')).show().siblings('.tab_content').hide(); // and show its contents, and hide the other tabs
        return false; // cancel the link click
    }).eq(0).click(); // click the first tab immediately

    /* Accordion In Brief */
    $(".accordion h4").eq(0).addClass("active");
    $(".accordion p").eq(0).show();
    $(".accordion h4").click(function(){
     $(this).next("p").slideToggle("fast")
     .siblings("p:visible").slideUp("fast");
     $(this).toggleClass("active");
     $(this).siblings("h4").removeClass("active");
    });

});
