/* *************************************************************************** *
* Code written and maintained by Peter Fingler (aka Gwellin)                   *
* *************************************************************************** */
$ = jQuery;
$('#bios').ready(function () {
  $('ul.bios-links li a').click(function () {
    this.blur();
    if (!$('div#bio-'+this.rel).hasClass('show')) {
      biosImage($('div#bio-'+this.rel+' div.bio-image img'), true);
      $('div.bio-block.show').animate(
        { 'opacity': 0 }, 500,
        function() { $(this).removeClass('show'); }
      );
      $('div#bio-'+this.rel).css('opacity', 0);
      $('div#bio-'+this.rel).addClass('show');
      $('div#bio-'+this.rel).animate(
        { 'opacity': 1 }, 500
      );

      $('html,body').animate({scrollTop: 315}, 900);

    }
    return false;
  });
  $('div.bio-image img').click(function () { biosImage(this); });
  function biosImage(subject, reset) {
    var subParent = $(subject).parent();
    var info = $('+ div.bio-info', subParent).get();
    if (reset) {
      $(subParent).removeClass('wide');
      $(subParent).css('width', '');
      $(info).css('opacity', 1);
      $(info).css('display', 'block');
    } else if ($(subParent).hasClass('wide')) {
      $(subParent).animate(
        { 'width': '49%' }, 500,
        function() { $(subParent).removeClass('wide'); }
      );
      $(info).css('opacity', 0);
      $(info).css('display', 'block');
      $(info).animate(
        { 'opacity': 1 }, 500
      );
    } else {
      $(info).animate(
        { 'opacity': 0 }, 500,
        function() { $(info).css('display', 'none'); }
      );
      $(subParent).animate(
        { 'width': '100%' }, 500,
        function() { $(subParent).addClass('wide'); }
      );
    }
    return false;
  }
});
$('body').ready(function () {
  if (bios_ages) {
    var ageElm, bio;
    for (bio in bios_ages) {
      ageElm = $('div#bio-'+bio+' span.bio-age').get();
      if (ageElm) $(ageElm).text(bios_ages[bio]);
    }
  }
});
