/*
 * bootstrap.js - basic JQuery bootstrap
 *
 * by Michael Guitton (michael/at/guitton/dot/name)
 *
 */

'function' == typeof jQuery && (function(global, $) {

   $.fn.extend({
      scrollTo: function(speed, easing) {
         return this.each(function() {
            var targetOffset = $(this).offset().top,
                        page = ['html', 'body'];
            if ($.browser.opera) {
               page.pop();
            }
            $(page+'').animate({scrollTop: targetOffset}, speed, easing);
         });
      }
   });

   $(document).ready(function() {

      function jump(e) {
         $(this).blur();
         $(this.hash).scrollTo(800);
         e.preventDefault(); // prevent FOUC-like FX - mg :-/
      }

      function nop(e) {
         $(this).blur()
         e.preventDefault();
      }

      function toggle(e) {
         var target = $(this);
         target
            .toggleClass('collapse')
            .next('ul')
   /*@cc_on
   // prevent animation bug in IE7 - mg
            .css('position', 'relative')
   @*/
            .slideToggle('normal')
   /*@cc_on
            .css('position', 'static')
   @*/
            .blur();
         if (e.data && e.data['sitemap']) {
            var type = target.hasClass('collapse') ? 'circle' : 'disc';
            target.parent().css('list-style-type', type);
         }
      }

      $('#subnav ul').hide();
      $('#subnav li span')
         .addClass('menu')
         .click(toggle);
      $('#subnav .selected')
         .parent()
         .siblings('span')
         .trigger('click');
      $('#subnav .selected a').click(nop);

      $('.sitemap #root ul').hide();
      $('.sitemap #root li span')
         .addClass('menu')
         .append('/')
         .bind('click', { sitemap: true }, toggle)
         .parent()
         .css('list-style-type', 'disc');

      if ($.fn.lightbox) {
         $('#photos a').lightbox({
            data: {
               'min-width': '120px',
               'min-height': '90px'
            },
            overlay: {
               'opacity': 0.65
            },
            img: {
               'border': '#d6dfe1 4px solid'
            }
         });
      }

      $('#highlights a.more, #leads a.more').each(function() {
         var href = this.href,
             $li  = $(this).parents('li');

         function go(e) {
            if ((e.target.nodeName + '').toLowerCase() == 'a' && e.target.href) {
               return;
            }
            global.location = href;
         }

         function over() {
            global.status = href;
            return true;
         }

         function out() {
            global.status = '';
         }

         $li.addClass('js').hover(over, out).click(go);
      });

      $('a[href^=#][href!=#][href!=#self]').click(jump);
      $('a[href=#self],a[href=#]').click(nop);
   });

})(this, jQuery);
