var rotoTimer;
var delay = 7000;

function selectNext() {
  var active = $('#featured_content a.active');
  var id = active.html();
  var next = (id % 5) + 1;
  active.removeClass('active');
  $('#featured_content .roto-link_' + next).addClass('active');
  $('#featured_content #roto li').css('display', 'none');
  $('.featured_content_' + next).css('display', 'block');
  rotoTimer = setTimeout('selectNext()', delay);
}

function selectPrev() {
  var active = $('#featured_content a.active');
  var id = active.html();
  var next = id - 1;
  if (0 == next) {
    next = 5;
  }
  active.removeClass('active');
  $('#featured_content .roto-link_' + next).addClass('active');
  $('#featured_content #roto li').css('display', 'none');
  $('.featured_content_' + next).css('display', 'block');
  rotoTimer = setTimeout('selectNext()', delay);
}

$(document).ready(function () {
  $('#featured_content .roto-control-link').click(function () {
    var id = $(this).html();
    $(this).siblings('.active').removeClass('active');
    $(this).addClass('active');
    $('#featured_content #roto li').css('display', 'none');
    $('.featured_content_' + id).css('display', 'block');
    clearTimeout(rotoTimer);
    rotoTimer = setTimeout('selectNext()', delay);
    return false;
  });
  $('#featured_content .roto-control-prev').click(function () {
    clearTimeout(rotoTimer);
    selectPrev();
    return false;
  });
  $('#featured_content .roto-control-next').click(function () {
    clearTimeout(rotoTimer);
    selectNext();
    return false;
  });
  rotoTimer = setTimeout('selectNext()', delay);
});

function checkTest() {
  var value = $('.edit_box form input#recommended:checked').val();
  if (null == value) {
    $('#rec_image_url').attr('readonly', 'readonly');
    $('#rec_image_url').css('background-color', '#ccc');
  }
  else {
    $('#rec_image_url').removeAttr('readonly');
    $('#rec_image_url').css('background-color', '#fff');
  }
}

$(document).ready(function () {
  checkTest();
  $('.edit_box form input#recommended').change(function () {
    checkTest();
  });
});

