/*
 * 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>";
var initial = [ 'expand', expand ];
var on = initial[0];

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

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;
}

$(document).ready( function () {
  if( !$.browser.msie ) { $('html').css( 'overflow', '-moz-scrollbars-vertical' ); }

  $('a[rel=external]').each( function( index, anchor ) {
                               anchor.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>" );
  } );

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

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

  $('#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(); }
} );
