$(document).ready(function()
{

  // If #cycle available, add fading slideshow
  if( document.getElementById('cycle') )
  {
    $('#cycle').cycle({
      fx: 'fade',
      speed: 1000,
      timeout: 5000
    });
  }

  // If work page, add thumbnail switching functionality
  if( document.getElementById('main-image') && document.getElementById('thumbnails') )
  {
    $('#thumbnails a').click(function()
    {
      $('#main-image img').attr('src', $(this).attr('href') );
      $('#thumbnails li.current').removeClass('current');
      $(this).parent().addClass('current');
      return false;
    });
  }

  // If credentials page, make everything fancy
  if( document.getElementById('credentials') )
  {
    $('a#right').show();
    $('#credentials').css('height','600px');

    $('#credentials-frames').cycle({
      fx: 'scrollHorz',
      nowrap: true,
      timeout: 0
    });

    $('a.arrow').click(function()
    {
      var nf;

      switch( $(this).attr('id') )
      {
        case 'left':
          $('#credentials-frames').cycle('prev');
          nf = $('.current').prev();
          break;
        case 'right':
          $('#credentials-frames').cycle('next');
          nf = $('.current').next();
          break;
      }

      $('.current').removeClass('current');
      nf.addClass('current');

      $('a.arrow').show();
      if( nf.attr('id') == $('#credentials-frames li:first-child').attr('id') )
        $('a#left').hide();
      if( nf.attr('id') == $('#credentials-frames li:last-child').attr('id') )
        $('a#right').hide();

      return false;
    });
  }

  // Email subscription box
  $('#email_subscribe').labox({
    text: 'Enter your email address',
  });

  // Navigation pin
  var cpt = false;
  $('ul#menu li a').each(function(){
    if( window.location.href.match( $(this).attr('href') ))
      cpt = $(this);
  });
  if( cpt )
  {
    $('body').append('<div id=\"page-marker\"></div>');
    $('#page-marker').css('left', cpt.offset().left + (cpt.width()*0.5) ).css('top','148px');
  }

  // Fix PNGs
  $('document').pngFix();

});

