$(document).ready(function() {
  
  $('body').addClass('js-enabled');
  
  $('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();
  });
  
  /* superfish navigation */
  $('ul.sf-menu').superfish({ 
    speed: 'fast',
    autoArrows: false, 
    dropShadows: false
  }); 
  
  $('.sf-menu li li a.active').parent('li').parent('ul').parent('li').find('a').addClass('active');
  
  /* open sportsresult links in new window */
  $('a[href*="live.ota.st-innovation.com"]').attr('target', 'tracking');
  
  /* media list - hoverover effect */
  $(".media-list li").hover(function(){
      $(this).find("img").fadeTo("fast", 0.5);
    },function(){
      $(this).find("img").fadeTo("fast", 1.0);
  });

  /* video list - hoverover effect */
  $(".videos li").hover(function(){
      $(this).find("img").fadeTo("fast", 0.5);
    },function(){
      $(this).find("img").fadeTo("fast", 1.0);
  });

  /* footer navigation */
  $("#footer .footer-menu > li").first().css('display', 'none');
  $("#footer .footer-menu > li:nth-child(2)").addClass("first");
  
  $("#footer a[href='#']").removeAttr("href").addClass("footer-no-link");

  /* slideshow */
  $("#slideshow").cycle({
    fx: 'fade'
  });

  /* load sponsor list */
  $("#sponsor-list").cycle({
    fx: 'fade'
  });

  /* table row hover */
  $("table tbody tr").mouseover(function() {
    $(this).addClass('active');
    }).mouseout(function() {
    $(this).removeClass('active');
  });

  /* Document list - hoverover effect */
  $(".documents li").hover(function(){
      $(this).find("img").fadeTo("fast", 0.5);
    },function(){
      $(this).find("img").fadeTo("fast", 1.0);
  });

    /* Document table hover link */
    $("table.documents tr").click(function(){
      window.location=$(this).find("a").attr("href"); return false;
    });

  /* profile list - hoverover effect */
  $(".profiles li").hover(function(){
      $(this).find("img").fadeTo("fast", 0.5);
    },function(){
      $(this).find("img").fadeTo("fast", 1.0);
  });

  /* Profile details */
  $("#profile-details li").first().addClass("first");

  /* News article - hoverover effect */
  $("#article-list li").hover(function(){
      $(this).find("img").fadeTo("fast", 0.5);
    },function(){
      $(this).find("img").fadeTo("fast", 1.0);
  });

  $("#most-recent-article dl").hover(function(){
      $(this).find("img").fadeTo("fast", 0.5);
    },function(){
      $(this).find("img").fadeTo("fast", 1.0);
  });

  /* Form - add class to checkbox */
  $(".form input:checkbox").addClass("cbox");

  /* News article -link block */
  $("#article-list li").click(function(){
    window.location=$(this).find("a").attr("href"); return false;
  });

  $("#most-recent-article dl").click(function(){
    window.location=$(this).find("a").attr("href"); return false;
  });

  $(".watch-youtube").click(function() {
    $.fancybox({
      'padding'   : 0,
      'overlayOpacity' : 0.7,
      'overlayColor'  : '#000',
      'autoScale'   : false,
      'transitionIn'  : 'none',
      'transitionOut' : 'none',
      'title'     : this.title,
      'width'     : 680,
      'height'    : 495,
      'href'      : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
      'type'      : 'swf',
      'swf'     : {
        'wmode'       : 'transparent',
        'allowfullscreen' : 'true'
      }
    });

    return false;
  });

});

