var timeout, _neverSlide;
runned = false;
var gallery = {
	images : new Array(),
	current : 0,
	loading : function() {
		$('#loading').hide();
		$('#imgSrc').fadeIn('slow');
		if (!runned)
			gallery.slideshow.start();
		gallery.slideshow.slide();		
	},
	registerImage : function(img) { 
		this.images[this.images.length] = jQuery('<img>').attr('src', img);
	},
	
	updateCount : function(num) {
		jQuery('#counter').html(num);
	},
	
	next : function() {
		if(this.current < this.images.length-1)
			this.current++;
		else 
			this.current = 0;
		
		this.show(this.current)
	},
	
	prev : function() {
		if(this.current > 0)
			this.current--;

		else 
			this.current = this.images.length-1;
		this.show(this.current);
	},
	
	show : function(a){
		this.current = a;
		jQuery('#loading').show();
		jQuery('#imgSrc').fadeOut('slow', 
			function() {
				gallery.updateCount(gallery.current+1);
				jQuery('#imgSrc').attr('src', gallery.images[gallery.current].attr('src'));
			}
		)
	},
	slideshow : {
		start : function() {
			this.chText('Stop slide-show');
			jQuery('#imgSrc').load (function() {return gallery.loading();})
			runned = true;
			
			this.slide();
		},
		stop : function() {
			this.chText('Start slide-show');
			if (timeout)
				clearTimeout(timeout);
			jQuery('#imgSrc').load (function() {return false;})			
		},
		chText : function(txt) {
			jQuery('#slideshow_div').html(txt);
		},
		
		slide : function() {
			if (_neverSlide) {
			 	clearTimeout(timeout);
			 	return false;
			 }
			if (timeout)
				clearTimeout(timeout);
			timeout = window.setTimeout("gallery.next()", 3000);
		}
	}
}
jQuery(document).ready(
	function() {
		$('#slideshow_div').toggle(
			function () {
				gallery.slideshow.stop();
			},
			function () {
				gallery.slideshow.start();
			}
		);
		if (myImg.length > 0) {
			for (var i in myImg) {
				gallery.registerImage(myImg[i]);
			}
		}
		jQuery('#imgSrc').click(
			function() {
				return gallery.next();
			}
		)
		jQuery('#imgSrc').hover(
			function() {
				gallery.slideshow.stop();
			},
			function() {
				gallery.slideshow.start();
			}
		);
	}
);
jQuery('#imgSrc').load (
	function() {
		return gallery.loading();
	}
)