var SlideShow=function(container1,opt){
	if(!container1)throw new Error('...');
	var r=this;
	var timer;
	var current=0;
	var delay=2e3;
	var Animate=true;
	var t=jQuery('> *',container1).each(function(i){
		jQuery(this).css({'z-index':10}).hide();
		if(i==current){
			$(this).css({'z-index':20}).show();
		}
	});
	if(opt&&opt.controls){
		jQuery('<div></div>')
			.css({position:'absolute',top: 0, right: 0, 'z-index':100, background:'white'})
			.attr('class','controls')
			.appendTo(container1);
	}
	var Do=function(current,next){
		clearTimeout(timer);
		jQuery(t.get(next)).css({'z-index':10}).show();
		jQuery(t.get(current)).fadeOut(function(){
			$(this).css({'z-index':10});
			$(t.get(next)).css({'z-index':20});
			if(Animate)timer=setTimeout(r.Next,delay);
		});
	}
	r.Next=function(){
		var next=current+1;
		next%=t.size();
		Do(current,next);
		current++;
		current%=t.size();
	}
	r.Prev=function(){
		var next=current-1;
		if(next<0)next+=t.size()
		Do(current,next);
		current--;
		if(current<0)current+=t.size();
	}
	r.Pause=function(x){
		clearTimeout(timer);
		Animate=false;
		if(x){Animate=true;this.Next();}
	}
	r.Paused=function(){
		return!r.Animate;
	}
	setTimeout(r.Next,delay);
}
jQuery(function(){
	new SlideShow(jQuery('#prezentacja1'),{controls:true});
});

