var eika = eika || {};

eika.imgRotation = function() {
	
	var that = {},
		countImg,
		count,
		img,
		obj;
	
	that.init = function(o) {
		obj = o;
		countImg = obj.children().length;
		count = countImg;
		
		obj.find('li').eq(count - 1).find('img').clone().prependTo('.slideWrap');
		
		window.setInterval(function() { rotate(); }, 5000);
	};

	var rotate = function() {
		count--;
		if(count >= 0) {
			obj.find('li').eq(count).fadeOut(1000, function() { $(this).find('img').attr('style', ''); });
		} else {
			count = countImg;
			obj.find('li').show(); obj.find('li').find('img').attr('style', '');
			rotate();
		}
	};
	
	return that;
}();

$(function() {
	eika.imgRotation.init($('.slideshow'));
});


