$(document).ready(function() {  

  // Close the playlists plus set the cookie
  
  $('#recently-played .close').live('click', function(event) {
    $.cookie('state', 'hidden');
    $(this).text('View The Recently Played Tracks').addClass('open').removeClass('close');
    $('#recently-played .ad-banner').slideUp(1000);
    $('#recent-songs').slideUp(1000);
    $('.on-air').slideUp(1000);
    $('.full-playlist').fadeOut(1000);
    event.stopPropagation();
    return false;
  });

  // Open the playlists plus set the cookie
  
  $('#recently-played .open').live('click', function(event) {
    $.cookie('state', null);
    $(this).text('Close The Recently Played Tracks').addClass('close').removeClass('open');
    $('#recently-played .ad-banner').slideDown(1000);
    $('#recent-songs').slideDown(1000);
    $('.on-air').slideDown(1000);
    $('.full-playlist').fadeIn(1000);
    event.stopPropagation();
    return false;
  });

  // Hide or show the playlists based on cookie
  
  $(function() {
    if($.cookie('state') == 'hidden') {
      $('#recently-played .ad-banner, #recent-songs, .full-playlist, .on-air').hide();
      $('#recently-played .close').text('View The Recently Played Tracks').addClass('open').removeClass('close');
    } else {
      $('#recently-played .ad-banner, #recent-songs, .full-playlist').show();
    }
  });

  // Set the currently playing item to scroll if too long
  
  $('#marquee').marquee({
    showSpeed: 500,
    scrollSpeed: 18,
    pauseSpeed: 500,
    pauseOnHover: false
  }); 
 
  // Add classes to CMJ charts
    
  $("#cmj-charts .entry ol li").each(function (i) {
    i = i+1;
    var topArtistClass = 'top-artists-' + i;
    $(this).addClass(topArtistClass).addClass('numbered-list');
  });
   
  // Smooth Scroll for same page anchor links
  
  $(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
      && location.hostname == this.hostname) {
        var $target = $(this.hash);
       $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
        if ($target.length) {
          var targetOffset = $target.offset().top;
          $('html,body').animate({scrollTop: targetOffset}, 1000);
          return false;
        }
      }
    });
  });
  
  // Store lightbox
  
  $("#store .entry .store-image").each(function() {
    $(this).find('a').lightBox({imageLoading:'/images/lightbox-ico-loading.gif',imageBtnClose:'/images/lightbox-btn-close.gif',imageBtnPrev:'/images/lightbox-btn-prev.gif',imageBtnNext:'/images/lightbox-btn-next.gif',imageBlank:'/images/lightbox-blank.gif'});
  });

  // Checkout Page alternating Row Colors
  
  $('#yab-checkout-table tr').alternate({
    odd:'odd',
    even:'even'
  });
  
});