var nv = 0;

var vr = new Array("#ykkosnosto", "#kakkosnosto", "#kolmosnosto");

function slideSwitch() {
	
	var active = $('.mainpage_animation_images .active');
	if ( active.length == 0 ) active = $('.mainpage_animation_images IMG:last');
	
	var url = active.attr("data-link");
	
	// use this to pull the images in the order they appear in the markup
	var next =  active.next().length ? active.next() : $('.mainpage_animation_images IMG:first');

	active.addClass('last-active');
	
	next.css({opacity: 0.0})
		.addClass('active')
		.click(function() {
				//alert('Handler for .click(' +url+ ') called.');
				document.location = url;
			})
		.delay(slideDelay+200)
		.animate({opacity: 1.0}, animTime,
		function() {
			slideDelay = 3000;
			active.removeClass('active last-active');
			$(".mainpage_animation_images").append(active);
			slideSwitch();
		});
	
	$(vr[nv]).delay(slideDelay+200).animate({ backgroundColor: '#fff' }, animTime);
	nv++;
	if(nv==3) { nv = 0 };
	
	$(vr[nv]).delay(slideDelay+200).animate({ backgroundColor: '#eee' }, animTime);
	
}

var slideDelay = 1500;
var animTime = 2000;


// $(vr[nv]).animate({ backgroundColor: '#eee'}, 200); });	
