$(function(){
                    //$("#kvmain").hide( );
	activateitem = function(id) {
                                          if ($("#img2").length == 0) 
                                           {
                                           $("#img1").css("z-index", "10").show();
                                           }
                                          else
                                     {
		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");
                                  }		
	};

	activateitem(1);		

});

var aktiv = window.setInterval("changeImg()", 5000);
var active = true;
var lastactive = '';
var beforelastactive = '';
var count = 2;

function changeImg () {
if (active) {
		$(".uncontrolled-interval").html(count);

if ($("#img"+count).length == 0) {
 count = 1;
}



 if (count == 9) { activateitem(1); }
 else { activateitem(count);	 }
 count = count + 1;

  if (count >= 9){
  count = 1;
//window.clearInterval(aktiv);
  }
}

}
