$(document).ready(function(){
 
  $("a[rel='players']").colorbox({transition:"fade"});
  $("a[rel='players'].active-player").click();
   
  $('.off').click( function() { 
    alert('Our website is being updated. Please check back soon. For more information please contact info@arsenalhockey.com');
  });
  
  var photo_link = $('#gallery .pic:first a').attr('href');
  if (photo_link != ''){
    $('#gallery .container img').css('cursor', 'pointer');
    $('#gallery .photo-title span').css('cursor', 'pointer');
  }  
    
  $('#gallery .pic').click(function(e){
    $('#gallery .container img').attr('src', $('span', this).text());
    var title = $('a', this).text();
    var link = $('a', this).attr('href');
    $('#gallery .photo-title span').text(title);
    if (title == '')
      $('#gallery .photo-title').stop().fadeTo(1, 0);
    else
      $('#gallery .photo-title').stop().fadeTo(1, 1);
      
    photo_link = link;
    if (link == ''){
      $('#gallery .container img').css('cursor', 'default');
      $('#gallery .photo-title span').css('cursor', 'default');
    }
    else {
      $('#gallery .container img').css('cursor', 'pointer');
      $('#gallery .photo-title span').css('cursor', 'pointer');
    }
  }).mouseover(function(e){
    $(this).addClass('pic-hover');
  }).mouseout(function(e){
    $(this).removeClass('pic-hover');
  });
  
  $('#gallery .container img').click(function(e){
    if (photo_link != '')
      window.location = photo_link;
  });
  $('#gallery .photo-title span').click(function(e){
    if (photo_link != '')
      window.location = photo_link;
  });
  
  var scroll_pos = 0;
  var scroll_max = $('#gallery .thumbs .pic').size() - 5;
  if (scroll_max<0)scroll_max = 0;
  
  function do_scroll(){
    if (scroll_pos<0)scroll_pos = 0;
    if (scroll_pos>scroll_max)scroll_pos = scroll_max;
    $('#gallery .pics .inner').stop().animate({
      left: -scroll_pos*(150+23)+'px'
    });
    if (scroll_pos == 0)
      $('#gallery .left').addClass('disabled');
    else
      $('#gallery .left').removeClass('disabled');
    if (scroll_pos == scroll_max)
      $('#gallery .right').addClass('disabled');
    else
      $('#gallery .right').removeClass('disabled');
  }
  do_scroll();
  
  $('#gallery .left').click(function(e){
    e.preventDefault();
    scroll_pos -= 1;
    do_scroll();
  });
  $('#gallery .right').click(function(e){
    e.preventDefault();
    scroll_pos += 1;
    do_scroll();
  });
  
  //$('#gallery .thumbs-frame').css({'height': '0px', 'top': '483px'});
  //$('#gallery .photo-title').hide();
  
  var thumbs_visible = false;
  function show_thumbs(){
    thumbs_visible = true;
//    $('#gallery .thumbs-frame').stop().animate({'top': '323px', 'height': '160px'}, 500);
    if ($('#gallery .photo-title').text()!='')
      $('#gallery .photo-title').stop().fadeTo('fast', 1);
//    $('#gallery .thumbs-frame').stop().animate({'height': '160px'}, {
//      duration: 300,
//      easing: 'linear',
//      step: function(now, fx){
//        $(fx.elem).css('top', 483-parseInt(now)+'px');
//      }
//    });
  }
  function hide_thumbs(){
    thumbs_visible = false;
    $('#gallery .photo-title').stop().fadeTo('fast', 0);
//    $('#gallery .thumbs-frame').stop().animate({'height': '0px'}, {
//      duration: 300,
//      easing: 'linear',
//      step: function(now, fx){
//        $(fx.elem).css('top', 483-parseInt(now)+'px');
//      }
//    });
  }  
  
  $('#gallery').mouseover(function(e){
    show_thumbs();
  }).mouseout(function(e){
    hide_thumbs();
  });
});


$(document).ready(function(){
  $('#block-gallery .thumbs .pic').click(function(e){
    e.preventDefault();
    
    var photo = $('span', this).text();
    var link = $('a', this).attr('href');
    var title = $('a', this).text();
    var description = $('em', this).text();
    $('#block-gallery .photo img').attr('src', photo);
    $('#block-gallery .photo .link').text(link);
    $('#block-gallery .photo .title').text(title);
    $('#block-gallery .photo .description').text(description);
    if (link == '')
      $('#block-gallery .photo img').css('cursor', 'default');
    else
      $('#block-gallery .photo img').css('cursor', 'pointer');
  });
  
  $('#block-gallery .photo img').click(function(e){
    e.preventDefault();
    var link = $('#block-gallery .photo .link').text();
    alert(link);
    if (link == '')return;
    window.open(link, '_blank');
  });
  
  var link = $('#block-gallery .photo .link').text();
  if (link == '')
    $('#block-gallery .photo img').css('cursor', 'default');
  else
    $('#block-gallery .photo img').css('cursor', 'pointer');
  
});

$(document).ready(function(){
  $("a[rel='gallery-photo']").colorbox();
  
  $('.article table').each(function(i,table){
    $(table).attr('cellspacing', '0');
    $(table).attr('cellpadding', '4');
    $('tr:first', table).find('td').addClass('fr');
    $('tr').each(function(j, tr){
      $('td:first', tr).addClass('fc');
    });
  });
  
//  $('.block-news-list .row2').click(function(e){
//    e.preventDefault();
//    window.location = $('a', this).attr('href');
//  });
  
  $('#scores .smallbox:last').addClass('last');
});

$(document).ready(function(){
  $('.block .galleries .gallery').click(function(e){
    e.preventDefault();
    window.location = $('a', this).attr('href');
  });
});
