var item = 0;
var prev = 0;
var images;
var t;

var imageList = [ {
		"url" : "/Resources/images/slideshow/odins_new_01.jpg"	// image[0].url
	}, {
		"url" : "/Resources/images/slideshow/odins_new_02.jpg"	// image[1].url
	}, {
		"url" : "/Resources/images/slideshow/odins_new_03.jpg"	// image[2].url
	}, {
		"url" : "/Resources/images/slideshow/odins_new_04.jpg"	// image[3].url
	}, {
		"url" : "/Resources/images/slideshow/odins_new_05.jpg"	// image[4].url
	}, {
		"url" : "/Resources/images/slideshow/odins_new_07.jpg"	// image[6].url
	}
];

function animate() {
	prev = item;
	item++;
	
	//Get next image, when it reaches the end, rotate it back to the first image
	if (item >= imageList.length)
		item = 0;
	
	imagesbtn.eq(prev).removeClass("imgbtn-active")
	imagesbtn.eq(item).addClass("imgbtn-active");
	
	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 () {
	if (imageList.length > 0) {
		$("div.photo_front").prepend("<div id='rotate' style='position:relative;height:350px;'></div>");// style='position:relative;z-index:-1;'
		for (var i = 0; i < imageList.length; i++) {
            $("div#rotate").append("<div class='rotating-image' style='position:absolute;top:0;height:350px;width:600px;overflow:hidden; background:url(" + imageList[i].url + ") no-repeat scroll center top transparent;display:none;'></div>");
        }
		// Bæta inn img selection
		$("div#rotate").append("<div id='imageSelection' style='position:absolute;right:20px;bottom:20px;'></div>");
		for (var i = 0; i < imageList.length; i++) {
            $("div#imageSelection").append("<div class='imgbtn'></div>");
        }
		
		item = (imageList.length - 1);//Byrja á fyrstu myndinni
		images = $('div.rotating-image');
		imagesbtn = $('div.imgbtn');
		animate();//Byrja ferlið
	}
});
