$('.homepage.promo.block').concrete({
  enable: function() {
    $(this).tabs({
      event: 'mouseover',
      fx: {
        opacity: 'toggle',
        duration: 150
      }
    });
    $(this).startrotate();
    $(this).find('.pane.hidden').removeClass('hidden');
  },
  disable: function() {
    $(this).tabs('destroy');
  },
  startrotate: function() {
    $(this).tabs('rotate', 5000, false);
  },
  onmatch: function() {
    $(this).enable();
  }
});

$('.homepage.promo.block ul li').concrete({
  onmouseout: function() {
    $('.homepage.promo.block').startrotate();
  }
});

$('.homepage.promo.block a.create-homepage-promo').concrete({
  onclick: function() {
    // Get the pane that has been selected
    // and hide the others
    pane = $(this).closest('.pane');
    $('.pane').not(pane).hide();

    // Disable the tabs
    $('.homepage.promo.block').disable();
    
    // 
    $(this).closest('.manage-homepage-promos').append('<div class="homepage-promo-form"></div>');
    $(this).parent('.tools').next('.homepage-promo-form').load('/hornet/homepage_promos/new', null,
    function(){

    });
    return false;
    
  }
});

$('.homepage.promo.block a.edit-homepage-promo').concrete({
  onclick: function() {
    // Get the pane that has been selected
    // and hide the others
    pane = $(this).closest('.pane');
    $('.pane').not(pane).hide();
    // Disable the tabs
    $('.homepage.promo.block').disable();
    $(this).closest('.manage-homepage-promos').append('<div class="homepage-promo-form"></div>');
    $(this).parent('.tools').next('.homepage-promo-form').load($(this).attr('href'), null,
    function(){
    
    });
    return false;
  }
})

$('.homepage.promo.block form#new_homepage_promo').concrete({
  onsubmit: function() {
    $('input#homepage_promo_image_attributes_name', $(this)).val($('input#homepage_promo_name', $(this)).val());
  }
})

$('.listen-live a').concrete({
  onclick: function() {
    window.open($(this).attr('href'), 'niufm', 'width=560,height=265,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,dialog=no');
    return false;
  }
})

$('.right-column .whos-on-air .next li').concrete({
  onmouseover: function() {
    $('.right-column .whos-on-air .next-description p').hide();
    $('.right-column .whos-on-air .next-description p#next-desc-'+$('a', this).attr('id')).show();
  },
  onmouseout: function() {
    $('.right-column .whos-on-air .next-description p').hide();
    $('.right-column .whos-on-air .next-description p:first').show();
  }
})

$(document).ready(function() {
  
  // Superfish menus
  $('#header > ul.navigation')
  .supersubs({
    extraWidth: 2,
    maxWidth: 50
  })
  .superfish({
    autoArrows: false,
    animation: {height: 'show'}
  });
  
  // Image gallery thumbnail clicks
  var full_images = $('.image-gallery textarea#full_images').val();
  full_images = eval('('+full_images+')');
  $('.image-gallery .thumbs .items a').click(function() {
    id = $(this).attr('id');
    src = full_images[id];
    $('.image-gallery .full-image').attr('src', src);
    return false;
  });
  
  // Image gallery scrollable thumbs
  $('.main-content .node .image-gallery .thumbs').scrollable({
    size: 5,
    clickable: false
  });

  var frequency_timer = setInterval(function() {
    next = $('#header ul.frequencies li.visible + li:not(.visible):first');
    if (next.length == 0) {
      next = $('#header ul.frequencies li:first');
    } 
    $('#header ul.frequencies li.visible').fadeOut(200, function() {
      $(this).removeClass('visible');
      next.fadeIn(200, function() {
        next.addClass('visible');
      });
    })
  }, 5000);
  
  $('.islandbeats form').attr('target', 'islandbeats');
  $('.islandbeats form').submit(function() {
    window.open($(this).attr('action'), 'islandbeats');
  });
  
});