var item = 0;
var prev = 0;
var images;
var t;

function animate() {
	prev = item;
	do
	{
		item = Math.floor(Math.random() * images.length);
	}
	while (prev == item);// Til að koma í veg fyrir að mynd verði valin tvisvar sinnum í röð
	
	images.eq(prev).fadeOut('slow');
	images.eq(item).fadeIn('slow', function () {
		//Kemur í veg fyrir að .fade loadast allt í einu þegar notandinn kemur aftur eftir svolítin tíma
		t = setTimeout("animate()", 7000);
	});
}

$(document).ready(function () {
	images = $('div.rotating-image');
	if (images.length > 0)
	{
		item = Math.floor(Math.random() * images.length);// Velja fyrstu myndina
		images.eq(item).fadeIn('slow');
		if (images.length > 1)//Not animate when there is only one image
			t = setTimeout("animate()", 7000);//Start slideshow after 7 sec
	}
});
