// JavaScript Document
var headline_count;
var headline_interval;
var old_headline = 0; 
var current_headline=0;

window.isActive = true
$(window).focus(function() { this.isActive = true; });
$(window).blur(function() { this.isActive = false; });

//////////////////////////////haber
$(document).ready(function(){
  headline_count = $("div.duyurular").size();
  $("div.duyurular:eq("+current_headline+")").css('top','0px');
  
  headline_interval = setInterval(headline_rotate,4000); //time in milliseconds
});

function headline_rotate() {
	if (  window.isActive == true) {
  current_headline = (old_headline + 1) % headline_count; //remainder will always equal old_headline until it reaches headline_count - at which point it becomes zero. clock arithmetic
  $("div.duyurular:eq(" + old_headline + ")").animate({top: -350},"slow", function() {
    $(this).css('top','350px');
    });
  $("div.duyurular:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
  old_headline = current_headline;
	}
}

