var af_ban_id, af_last_id, af_timerID, af_ban;
var is_show_banner = 1; 
var mouse_under = 0; 
var user_look_time = 15000;

function fnBanRotate() {
  var box = $("#ban_rotate");
  if (box.length > 0) {    
    af_ban_id = $("#bban1").attr("ban")*1;
    af_last_id = $("#bban0").attr("ban")*1;
    click_next($("#ban"+af_ban_id+""), af_ban_id);

    $("#ban_rot_href a").click(function () {
      if (mouse_under == 1) {
        $(this).remove
        is_show_banner = 0;
        $('#ban_rotate div.rban').stopTime('timer1');
        $('#ban_rot_href a').removeClass('active').addClass('none').stopTime('timer_is_show_banner');
        $(this).addClass('active');
        var current_index = $(this).attr("ban")*1;
        current_delay = $('#ban'+current_index+'').attr('delay')*1;
        if (current_delay) { user_look_time = current_delay; }
        
        $("div.show", box).removeClass('show').addClass('hide');
        $('#ban'+current_index+'').removeClass('hide').addClass('show');
        
        $(this).oneTime(user_look_time, 'timer_is_show_banner', function() {
          $(this).stopTime('timer_is_show_banner');
          is_show_banner = 1;
          var banner_count = af_last_id;
          var current_index = $(this).next('a').attr("ban")*1;
          if (!current_index) {
            current_index = af_ban_id;
          }
          click_next($('#ban'+current_index+''), current_index);
        });
      }
      return false;
    });  
    $('#ban_rot_href a').hover( function () { mouse_under = 1; }, function () { mouse_under = 0; }  );    
  }
}

function click_next(obj, d) {
  
  var box = $("#ban_rotate");
  var current_delay = $('#ban'+d+'').attr('delay')*1;
  $("div.show", box).removeClass('show').addClass('hide'); 
  obj.removeClass('hide').addClass('show');
  $('#ban_rot_href a').removeClass('active').addClass('none');
  $('a.ab'+d+'', $("#ban_rot_href")).addClass('active');
  $(obj).oneTime(current_delay, 'timer1', function(i) {
    var banner_count = af_last_id;
    var current_index = $(this).next('div').attr("ban")*1;
    if (!current_index) {
      current_index = af_ban_id;
    }
    
    $(obj).stopTime('timer1');
    if (is_show_banner) {
      //$('#ban_rot_href ').find("li:eq("+current_index+")").children("a").click(); 
      click_next($('#ban'+current_index+''), current_index);
    }
  });
  return false;      
}

function fnSwitchBan(temp_id) {
  if (temp_id > 0) id = temp_id;
  clearTimeout(timerID);
  if (id == 1) {
    id = 2;
    $('#ban1').show();
    $('#ban2').hide();
    $('#dot1').html('<img src="dot2.gif" onClick="fnClick(1)" />');
    $('#dot2').html('<img src="dot1.gif" onClick="fnClick(2)" />');
    timerID = setTimeout("fnClick()", 4000);
  } else {
    id = 1;
    $('#ban2').show();
    $('#ban1').hide();    
    $('#dot1').html('<img src="dot1.gif" onClick="fnClick(1)" />');
    $('#dot2').html('<img src="dot2.gif" onClick="fnClick(2)" />');
    timerID = setTimeout("fnClick()", 7000);
  }  
}
