function hideVideo(e){
  if(e)
    e.preventDefault();
  $('video').each(function(){
    $(this)[0]
      .pause();
  });
  $('#video , #splash')
    .delay(2000)
    .slideToggle('slow');
}

$(function(){  

  var idx = -1;

  if( document.location.hash.length>1 ){
    request = window.location.hash.substring( 1 );
    $request = $( 'a[href$="'+request+'"]:first' );
    if( $request.closest( '#thumbnails' ).length ){
     // Project
      idx = $( '#thumbnails li' ).index( $request.closest( 'li' ) );
    }
  }

  $( '#thumbnails' )
    .show(function(){
      $( this ).jcarousel({
        start : ( idx<0 ? 0 : idx )
      });
    })
    .find( 'a' )
      .each(function(){
        $t = $( this );
        link = $t.attr( 'href' );
        if( link!='#' ){
          slug = /[=\/]([^\/\=]+)$/gi.exec( link );
          thumb = slug[1]+'_thumb.jpg';
        }else{
          thumb = 'placeholder.gif';
        }
        $t
          .attr( 'title' , $t.text() )
          .css({
            'background-image' : 'url("/images/'+thumb+'")' ,
            'text-indent'      : '-9999px'
          });
      })
      .live( 'click' , function( e ){
        e.preventDefault();
        $t = $(this);
        if( $t.attr( 'href' )!='/' ){
         /* Load the Page Content */
          $( '#sample' )
            .load(
              $t.attr( 'href' )+' #sampleContent' ,
              function(){
                _gaq.push( [ '_trackPageview' , $t.attr( 'href' ) ] );
              }
            );
         /* Update the Link Highlights */
          $( '#thumbnails a' )
            .removeClass( 'current' );
          $t
            .addClass( 'current' );
          window.location.hash = $t.attr( 'href' ).split( '?' )[1];
        }else{
          window.location = window.location.href.replace( /#.*/ , '' );
        }
      });
  if( idx>=0 ){
    $( '#thumbnails li:eq('+idx+') a' ).click();
  }

  $( '#categories a' )
    .live( 'click' , function( e ){
      e.preventDefault();
      $t = $(this);
      if( !$t.hasClass( 'current' ) ){
        $( '#categories a' )
          .removeClass( 'current' );
        $t.addClass( 'current' );
        slugs = $t.attr( 'href' ).split( '#category=' );
        if( slugs[1] ){
          show = slugs[1];
          $( '#thumbnails li' )
            .hide();
          $( '#thumbnails li a.'+show ).closest( 'li' )
            .show();
        }else{
          $( '#thumbnails li' )
            .show();
        }
        _gaq.push( [ '_trackPageview' , $t.attr( 'href' ) ] );
      }
    });

  $( '.pages a' )
    .live( 'click' , function( e ){
      e.preventDefault();
      $t = $(this);
      $( '#sample' )
        .load(
          $t.attr( 'href' )+' #sampleContent' ,
          function(){
            _gaq.push( [ '_trackPageview' , $t.attr( 'href' ) ] );
          }
        );
      $( '#thumbnails a' )
        .removeClass( 'current' );
      window.location.hash = $t.attr( 'href' ).split( '?' )[1];
    });

});

