$(function(){

  $("#outer-container2").hide();
  $("#homenews > h1").addClass("selected");

  $("h1").click( function() {
    $("h1").removeClass("selected").next().hide();

    $(this).addClass("selected").next().show();
  });

	activateitem = function(id) {
		if(lastactive != ''){
			$("#img" + lastactive).css("z-index", "5");		
			if(beforelastactive != ''){
				$("#img" + beforelastactive).hide();	
			}
			beforelastactive = lastactive;
		}
		lastactive = id;
		$("#img" + id).css("z-index", "10").animate({opacity: 'toggle'}, 'slow');	
  var top = -(id * 86) + 86;
//alert(top);
		$("#inner-container").animate({'top': top}, 6500);
		$("#inner-container2").animate({'top': top}, 6500);
	};


	activateitem(1);


scrollNews = function() {
  var scrollobj=document.getElementById("inner-container");
  var scrollobj2=document.getElementById("inner-container2");
  var top = 0;
  //var height = $("div.news").parent().parent().height();
  //var height = $("#outer-container").height();
  var height = 86;
  //var height2 = $("#outer-container2").height();
  if(- scrollobj.clientHeight != scrollobj.offsetTop - height){
    top = scrollobj.offsetTop - height;
  } else {
    top = 0;
  }

  /*if(- scrollobj.clientHeight != scrollobj.offsetTop - height){
    top = scrollobj.offsetTop - height;
  } else {
    top = 0;
  }
 if(- scrollobj2.clientHeight != scrollobj2.offsetTop - height2){
    top = scrollobj2.offsetTop - height2;
  } else {
    top = 0;
  }*/
  $(scrollobj).animate({'top': top}, 'slow');
  $(scrollobj2).animate({'top': top}, 'slow');
}	

});

var aktiv = window.setInterval("changeImg()", 4000);
var active = true;
var	lastactive = '';
var	beforelastactive = '';
var count = 2;

//var countImages = document.getElementById("countImages").value;
//alert(countImages);

function changeImg () {
	if (active) {
		$(".uncontrolled-interval").html(count);
	  if (count == 5) {
		activateitem(1);		
	  } else {
		activateitem(count);		
	  }
           //scrollNews();
		count = count + 1;
	  if (count >= 5){
		  count = 1;
		//window.clearInterval(aktiv);
	  }
	}
}

