var banner_auto = null;

jQuery(document).ready(function(){

  //IE fixes - IE 8 and below don't like transparent fonts so just replace the unnecessary text with a non-breaking space
  $('.nav-banner-control a').each(function(){
    $(this).html('&nbsp;');
  });

  //Banner anim
  $('.nav-banner-desc').children().each(function(){ //Switch titles to something else. Titles are used for strict (compliance)
    $(this).attr('rel', $(this).attr('title'));
    $(this).attr('title', '');
  });
  $('.nav-banner-control-prev').click(function(){
    clearInterval(banner_auto);
    nav_banner(-1);
  });
  $('.nav-banner-control-next').click(function(){
    clearInterval(banner_auto);
    nav_banner(1);
  });
  banner_auto = setInterval("nav_banner(1)", 5000);

});

function nav_banner(val) {
  var the_list  = '.nav-banner-desc';
  var the_pic   = '#nav-banner-pic';
  var the_temp  = '#nav-banner-temp';
  
  if ((typeof($(the_pic).attr('rel')) != "undefined")) {
    var next = parseInt($(the_pic).attr('rel'));
  } else {
    var next = 1
  }
  
  //Calc next move
  var list = $(the_list).children().size();
//  var next = parseInt($(the_pic).attr('rel'));
  if (val > 0) {
    next++;
  } else {
    next--;
  }
  if (next < 1) {
    next = list;
  }
  if (next > list) {
    next = 1;
  }
  
  //Show new list item
  $(the_list).children().hide();
  $(the_list).children(':nth-child('+(next)+')').show();
  
  //Make a temporary copy of the pic and fade it out over the newly placed image
  var image = $(the_pic).clone();
  image.attr('id', 'nav-banner-temp');
  $(the_pic).attr('rel', next);
  $(the_pic).css('zIndex', 9);
  $(the_pic).attr('src', $(the_list).children(':nth-child('+(next)+')').attr('rel'));
  $(the_pic).after(image);
  $(the_temp).css('zIndex', 10);
  $(the_temp).fadeOut('slow', function(){
    $(this).remove();
  });
}

