jQuery(function($) {

  $.ajaxSetup({traditional: true});
  $('body').addClass('js-enabled').ajaxSend(function() {
      $(this).addClass('ajax-loading');
  }).ajaxComplete(function() {
      $(this).removeClass('ajax-loading');
  });
  
  $('span.mailto').each(function(){
      exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
      match = exp.exec($(this).text());
      addr = match[1] ? match[1].replace(/ at /,'@').replace(/ dot /g,'.') : match[0].replace(/ at /,'@').replace(/ dot /g,'.');
      emaillink = match[2] ? match[2] : addr;
      subject = $(this).attr('title') ? '?subject='+$(this).attr('title').replace(/ /g,'%20') : '';
       $(this).after('<a href="mailto:'+addr+subject+'">'+ emaillink + '</a>');
      $(this).remove();
  });

  /* Latest news */
  $("#feature-output").cycle({
    pager: '#feature-list',
    pagerAnchorBuilder: function(idx, slide) {
      return '#feature-list li:eq(' + idx + ') a';
    },
    activePagerClass: 'current',
    pause: 1,
    pauseOnPagerHover: 1,
    speed: 1000,
    fx: 'fade'
  });

  /* Dropdown menu */
  $('ul.sf-menu').superfish({ 
    speed: 'fast',
    autoArrows: false, 
    dropShadows: false
  }); 

  /* Fancybox */
  $(".fancybox").fancybox({
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'speedIn'       : 500,
    'speedOut'      : 200,
    'overlayColor'  : '#000',
    'overlayOpacity': 0.6
  });

  $(".play").click(function() {
    $.fancybox({
      'padding'   : 0,
      'autoScale'   : false,
      'transitionIn'  : 'none',
      'transitionOut' : 'none',
      'title'     : this.title,
      'overlayColor'  : '#000',
      'overlayOpacity': 0.6,
      'width'     : 640,
      'height'    : 385,
      'href'      : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') +'&amp;autoplay=1',
      'type'      : 'swf',
      'swf'     : {
      'wmode'       : 'transparent',
      'allowfullscreen' : 'true'
      }
    });
    return false;
  });

  $.supersized({
    slides  :   [ {image : '/static/images/bg-body.jpg', title : ''} ]
  });
});


