/*
 * rj.js
 * Ryan Funduk
 *
 * Primary behavior stuff for ryanfunduk.com. Go ahead and do whatever you
 * like with this code if you find it interesting.
 *
 */

var collapse = "<tt><strong>-</strong> hide dashboard <strong>-</strong></tt>";
var expand =   "<tt><strong>+</strong> show dashboard <strong>+</strong></tt>";

jQuery.easing.ease = function( x, t, b, c, d ) {
  return c * ( ( t = t / d - 1 ) * t * t + 1 ) + b;
};

$(document).ready( function () {
  function toggleDashboard( e, only ) {
    if( only !== undefined && only != on ) { return false; }

    if( on == 'expand' ) {
      $('.attention_grabber').hide();
    }

    $('#info').slideToggle();

    if( on == 'collapse' ) { $('#fold').html( expand );   on = 'expand'; }
    else                   { $('#fold').html( collapse ); on = 'collapse'; }

    return false;
  }

  var initial = typeof(aboutPage) != 'undefined' ? [ 'collapse', collapse ] : [ 'expand', expand ];
  var on = initial[0];

  $('#nojs').hide();

  $('a[rel=external]').attr( 'target', '_blank' );

  $('table#contact tr td.eval').each( function () {
    $(this).html( eval( $(this).text() ) );
  } );

  $('#email_address').each( function () {
    var email = eval( $(this).text() );
    $(this).html( "<a href='mailto:" + email + "'>" + email + "</a>" );
  } );

  $('#fold').html( initial[1] ).show().click( toggleDashboard );
  if( typeof( aboutPage ) == 'undefined' ) {
    $('#info').hide();
  }

  $('#header, #expand_bar').click( toggleDashboard ).hover(
    function() { $('#fold').addClass( 'fake_hover' ); },
    function() { $('#fold').removeClass( 'fake_hover' ); }
  );

  $('#up').click( function () {
    $('html, body').animate(
      { scrollTop: '0px' },
      1000, 'ease',
      function() { toggleDashboard( null, 'expand' ); }
    );
    return false;
  } );

  if( $.fn.archiver ) { $('#archives').archiver(); }
} );
