﻿/* Berkeley Law Effects (requires jQuery and sIFR 3) */
/* by White Whale Web Services */
var headers = new  Array('architecture','bark','boalt','books','face','facade','feet','journal','lamps','leaves','letters','night','sculpture','staircase','student-center'), subnavs, hoverTimer, hideTimer,navCollapseTimer;
$(document).ready(function() { // on DOM load

    var homeHeaderDir="";
    /* check for homepage, or flyout pages */
    if (location.pathname=="/572.htm" || location.pathname=="/814.htm" || location.pathname=="/8206.htm" || location.pathname=="/" || location.pathname=="/index.html") { homeHeaderDir="home/"; }
    $('#header').css('background-image','url(/images/headers/'+homeHeaderDir+headers[Math.floor(Math.random()*headers.length)]+'.jpg)'); // select a random header image

    /* Prep sIFR */
    var intro = $('#intro');
    intro.css('min-height',intro.height()+'px');
    equalColumns(); // equalize columns right now
    $('#search_query').css('font-weight','bold').val('Search Berkeley Law').click(function() { if($(this).val()=='Search Berkeley Law') $(this).val('').css('font-weight','normal'); }).blur(function() { if(!$(this).val()) $(this).val('Search Berkeley Law').css('font-weight','bold'); }); // Search box
    /* Flyouts */
    $('body').prepend('<div id="whiteout"></div>');
    subnavs = $('#subnavigation>li').filter(':not(:has(ul.subsubnavigation))'); // grab all subnavs, remove the currently open one
    subnavs.each(function() { $(this).find('ul').prepend('<li class="flyout_header"></a>'); $(this).find('ul li.flyout_header').append($(this).children().eq(0).clone()); });
    subnavs.hover( // the dumb flyout behavior (for instant satisfaction)
        function() { clearTimeout(hideTimer); $(this).addClass('selected').find('ul').show(); },
          function() { if($('#whiteout').is(':hidden')) $(this).removeClass('selected').find('ul').hide(); }
    );
    if(!($.browser.msie&&$.browser.version<=7)) subnavs.filter(':has(ul)').hover( // the 'smart' flyout behavior (applied only to subnavs with popup)
        function() {
            hoverTimer = setTimeout(function() {
                $('#whiteout').show();
            },
            300); // how long to wait before locking this menu on
        },
        function() {
            clearTimeout(hoverTimer);
            hideTimer = setTimeout(function() {
                subnavs.removeClass('selected').find('ul').hide();
                $('#whiteout').hide();
            },500); // how long to wait before hiding this menu
        }
    );
    
    /* Collapsed-style Nav*/
    $('#explore a').click(function() {
        $(this).parent().fadeOut(400).siblings().fadeIn(400);
        $('#navigation').animate({height:'48px'},400,function() { clearTimeout(navCollapseTimer); });
        return false;
    });
    $('.navigation_mini').hover(function() {
        clearTimeout(navCollapseTimer);
    },function() {
        navCollapseTimer = setTimeout(function() {
            $('#navigation li:not(#explore)').fadeOut(400);
            $('#explore').fadeIn(400);
            $('#navigation').animate({height:'15px'},400);
        },1000);
    });
    $(window).load(function() { setTimeout(equalColumns,750); }); // after _everything_ has loaded
});

function equalColumns() { // Equal height for subpage columns
    var content_height=$('#content').height('auto').height(); 
    var sidebar_height=$('#sidebar').height('auto').height(); 
    if(sidebar_height>content_height) $('#content').height(sidebar_height+'px'); 
    else $('#sidebar').height(content_height+'px');
};


/* sIFR text replacement */
parseSelector.pseudoClasses = {
  'not': function(nodes, selector) {
    var result = [];
    each: for(var i = 0, node; i < nodes.length; i++) {
      node = nodes[i];
      var ignore = parseSelector(selector, node.parentNode);
      for(var j = 0; j < ignore.length; j++) {
        if(ignore[j] == node) continue each;
      }
      result.push(node);
    }
    return result;
  }
}
var gill = {
    src: '/files/gill.swf',
    wmode:'transparent'
};
var gregular = {
    src: '/files/gregular.swf',
    wmode:'transparent'
};

sIFR.useStyleCheck = true; // useStyleCheck speeds up Safari and Opera
sIFR.activate(gill);
sIFR.activate(gregular);
/* Note that sIFR should be listed here from most-specific to least-specific CSS selector */
sIFR.replace(gill, {
    selector:'#intro, h2:not(.nosifr)',
    css:['.sIFR-root { color:#253359; background-color:#ffffff; font-size:26px; } .leading_line,h2 { font-family:"Gill Sans"; font-weight:normal; color:#000000; }'],
    ratios:[7,1.32,8,1.31,12,1.27,20,1.22,28,1.19,30,1.17,36,1.18,45,1.17,61,1.16,62,1.15,65,1.16,66,1.15,67,1.16,116,1.15,117,1.14,123,1.15,124,1.14,1.15]
});
sIFR.replace(gill, {
    selector:'h2, h2:not(.nosifr)',
    css:['.sIFR-root { font-family:"Gill Sans";color:#000000; background-color:#ffffff; font-size:26px; }'],
    ratios:[7,1.32,8,1.31,12,1.27,20,1.22,28,1.19,30,1.17,36,1.18,45,1.17,61,1.16,62,1.15,65,1.16,66,1.15,67,1.16,116,1.15,117,1.14,123,1.15,124,1.14,1.15]
});
