//SET INTERVAL TO TOGGLE THE TABS
var test = window.setInterval("toggle()", 10000);
//TOGGLE FUNCTION
function toggle(){
  var activeTab = $("#content .box_teaser ul.pagenavi li.active").attr("id");
  activeTab = activeTab.substring(8);
  if (activeTab < myslides) {
    nextTab = parseInt(activeTab) + 1;
  }else{
    nextTab = 1;
  }
  $("#position1, #position2, #position3, #position4").removeClass("active");
  $("#position"+nextTab).addClass("active");
  switchImage(nextTab, '0');
}
//FUNCTION TO SWITCH THE BIG IMAGE
function switchImage(num, timer){
  if (timer == '0') {
    $("#disnavi").css("z-index", "600");
    $("#imageBox div.teaser_active").stop(true, true).fadeOut(1500, function(){
      $("#imageBox div.teaser_active img").css("z-index", "100");
      $("#imageBox div.teaser_active").hide();
      $(this).removeClass("teaser_active");
    });
    $("#imageBox #teaser" + num).stop(true, true).fadeIn(1500, function(){
      $("#imageBox div.teaser_active").css("z-index", "200");
      $("#imageBox #teaser" + num).addClass("teaser_active");
      $("#disnavi").css("z-index", "400");
    });
    window.clearInterval(test);
    test = window.setInterval("toggle()", 10000);
  } else {
    $("#disnavi").css("z-index", "600");
    $("#imageBox div.teaser_active").stop(true, true).fadeOut(1500, function(){
      $("#imageBox div.teaser_active img").css("z-index", "100");
      $("#imageBox div.teaser_active").hide();
      $(this).removeClass("teaser_active");
    });
    $("#imageBox #teaser" + num).stop(true, true).fadeIn(1500, function(){
      $("#imageBox div.teaser_active").css("z-index", "200");
      $("#imageBox #teaser" + num).addClass("teaser_active");
      $("#disnavi").css("z-index", "400");
    });
    window.clearInterval(test);
  }
}
$(document).ready(function(){
  //TAB ON MOUSEOVER
  $("#position1, #position2, #position3, #position4").click(function(){
    $("#disnavi").css("z-index", "600");
    if ($(this).attr("class") == "active") {
      window.clearInterval(test);
    } else {
      $("#position1, #position2, #position3, #position4").removeClass("active");
      $(this).addClass("active");
      var num = $("ul.pagenavi li").index(this) + 1;
      switchImage(num, '1');
    }
  });
  $("#imageBox").mouseover(function(){
    window.clearInterval(test);
  });
  //TAB ON MOUSEOUT
  $("#position1, #position2, #position3, #position4").mouseout(function(){
    window.clearInterval(test);
    test = window.setInterval("toggle()", 10000);
  });
  $("#imageBox").mouseout(function(){
    window.clearInterval(test);
    test = window.setInterval("toggle()", 10000);
  });
});
