function SimpleScroller (selector,options){
	if(jQuery==undefined){alert('jQuery must be included for the scroller to work!');return;}
	if(selector==undefined){alert('No selector given!');return;}
	var t=this,$=jQuery;
	options=options || {cycleTime:3};
	t.scroller=$(selector).first();
	t.cycleTime=options.cycleTime;
	t.slide_tot=0;
	t.slide_prev=0;
	t.positions=new Array();
	t.timer=null;
	t.menu=null;
	t.autoAdvance=function(){
		if(t.slide_tot==0){clearInterval(t.timer);return false;}
		t.menu.children().eq((t.slide_prev+1)%t.slide_tot).trigger('click',[true]);
	};
	t.stop=function(){
		clearInterval(t.timer);
	};
	t.start=function(){
		if(console && console.log) console.log("started");
		t.timer=setInterval(t.autoAdvance,t.cycleTime*1000);
	};
	t.menu=t.scroller.children('.gallerymenu').first();
	t.scroller.children('.slides').hover(t.stop,t.start);
	if(t.menu.length==0){
		t.scroller.append('<div class="gallerymenu" />');
		t.menu=t.scroller.children('.gallerymenu');
	}
	t.menu.append('<ul />');
	t.menu=t.menu.children().first();
	t.scroller.children('.slides').children('.slide').each(function(i){
		t.positions[i]=$(this);
		t.positions[i].children('.slideimg').each(
			function(i){//vertically center
				var t=$(this);
				console.log(i+" "+t.parent().innerHeight()+" "+t.outerHeight());
				console.log(i+" "+t.parent().height()+" "+t.height());
				console.log(t);
				console.log(t.parent());
				t.css('margin-top',((t.parent().innerHeight()-t.outerHeight())/2)+'px');
			});
		if(t.slide_tot!=0)$(this).fadeOut(0);
		t.slide_tot++;
		if(!t.positions[i].width()){alert("Please, fill in width & height for all your slides!");return false;}
		$('<li><a href="#" title="Slide '+i+'"></a></li>')
			.click(function(e,keepScroll){
				var th=$(this),slide_cur=0;
				if(th.hasClass('act')) return;
				slide_cur=th.prevAll('li').length;
				t.menu.children().eq(t.slide_prev).removeClass('act').addClass('inact');
				th.removeClass('inact').addClass('act');
				t.positions[t.slide_prev].fadeOut(250,'linear');
				t.positions[slide_cur].fadeIn(500,'linear');
				t.slide_prev=slide_cur;
				e.preventDefault();
				/* Prevent the default action of the link */
				// Stopping the auto-advance if an icon has been clicked:
				if(!keepScroll) t.stop;
			}).appendTo(t.menu);
	});
	t.menu.children('li:first').addClass('act').siblings().addClass('inact');
	t.start();
	return t;
}
(function($){$.simpleScroller=SimpleScroller;})(jQuery);
