var SlideShow = {
	cont: null,
	pics: [],
	count: 0,
	dir: '/i/top_gallery/',
	current: 1,
	
	idle_time: 5000,
	fade_time: 1800,

	Start: function(count) {
		this.count = count;
		
		this.cont = $('#top_gallery');
		this.pics[0] = this.cont.children();
		this.pics[0].css('z-index', 10);
		
		this.pics[1] = $("<img src='" + this.dir + "1.jpg'>").css({position: 'absolute', top: 0, left: 0, 'z-index': 0}).appendTo(this.cont);
		
		var t = this;
		setTimeout(function(t){return function() {t.Slide();}}(this), 1000);
	},
	
	Slide: function() {
		var t = this,
		first = (this.pics[0].css('z-index') == 10) ? 0 : 1, second = (first == 0) ? 1 : 0;
		
		this.pics[first].animate({opacity: 0}, this.fade_time, 'linear', function() {
			var next_pic = t.GetNext(t.current);
			$(this).css({'z-index': 0, 'opacity': 1}).attr('src', '/i/top_gallery/' + next_pic + '.jpg').siblings().css({'z-index': 10, 'opacity': 1});
			
			t.current = next_pic;
			setTimeout(function(t){return function() {t.Slide();}}(t), t.idle_time);			
		});		
	},
	
	GetNext: function(i) {
		return (++i >= this.count) ? 0 : i;
	}
}
