var IlSlideshow = function () {
}
IlSlideshow.prototype.speed = 250;
IlSlideshow.prototype.easing = "linear";
IlSlideshow.prototype.autoslide = false;
IlSlideshow.prototype.delay = 5000;

IlSlideshow.init = function (obj) {
	if (obj.speed != null) {
		IlSlideshow.prototype.speed = obj.speed;
	}
	if (obj.easing != null) {
		IlSlideshow.prototype.easing = obj.easing;
	}
	if (obj.autoslide != null) {
		IlSlideshow.prototype.autoslide = obj.autoslide;
	}
	if (obj.delay != null) {
		IlSlideshow.prototype.delay = obj.delay;
	}
}

$(document).ready(function () {
	
	var no = 0;
	var array = new Array();
	
	var ilSlideshow = new IlSlideshow();
	var id;
	
	if (ilSlideshow.autoslide) {
		id = setTimeout(next, ilSlideshow.delay);
	}
	
	$(".il_slideshow").css({
		"position":"relative"
	});
	
	for (var i = 0; i < $(".il_slideshow li").length; i++){
		
		var element = $(".il_slideshow li")[i];
		array.push($(element));
		$(element).css({
			"position":"absolute",
			"top":0,
			"left":0
		});
		if (i != 0) {
			$(element).css({
				opacity:0
			});
		}
		
	}
	
	$(".prev, .next").css({
		"cursor":"pointer"
	});
	$(".prev").click(function () {
		
		prev();
		
	});
	$(".next").click(function () {
		
		next();
		
	});
	
	function prev () {
		
		array[no].stop();
		array[no].animate({"opacity":0}, ilSlideshow.speed, ilSlideshow.easing);
		array[no].css({"z-index":0});
		
		no--;
		if (no < 0) {
			no = array.length - 1;
		}
		
		array[no].stop();
		array[no].animate({"opacity":1}, ilSlideshow.speed, ilSlideshow.easing);
		array[no].css({"z-index":1});
		
		if (ilSlideshow.autoslide) {
			clearInterval(id);
			id = setTimeout(next, ilSlideshow.speed + ilSlideshow.delay);
		}
		
	}
	
	function next () {
		
		array[no].stop();
		array[no].animate({"opacity":0}, ilSlideshow.speed, ilSlideshow.easing);
		array[no].css({"z-index":0});
		
		no++;
		if (no > array.length - 1) {
			no = 0;
		}
		
		array[no].stop();
		array[no].animate({"opacity":1}, ilSlideshow.speed, ilSlideshow.easing);
		array[no].css({"z-index":1});
		
		if (ilSlideshow.autoslide) {
			clearInterval(id);
			id = setTimeout(next, ilSlideshow.speed + ilSlideshow.delay);
		}
		
	}
	
});
