syntops.gallery = (function($) {
	function init(gallery, container, width, height, time, easing)
	{
		var $gallery = $(gallery);
		var $container = $(container);
		
		running = false;
		Stack = new Array();
		$container.css({
			position: 'relative',
			width: width + 'px',
			height: height + 'px'
		});
		var $images = $container.find('.items .item');
		$images.css({
			position: 'absolute',
			top: '0px',
			left: '0px',
			zIndex: '0',
		});
		$images.css({
			zIndex: 0
		});
		var $akt = $images.first();
		$akt.css({
			zIndex: 1
		})
		
		function nextImg(){
			if(running==true){
				return;
			}
			running = true;
			var $old_akt = $akt;
			$akt = $akt.next();
			if ($akt.length == 0)
				$akt = $images.first();
			$akt.css({
				zIndex: 2,
				left:width + 'px'
			})
			$akt.animate({
				left:'0px'
			}, time, easing, function() {
				$old_akt.css({
					zIndex: 0
				})
				$akt.css({
					zIndex: 1
				})
				running = false;
			});
			/*
			$old_akt.stop().delay(25).animate({
				left:'-' + width + 'px'
			}, time, easing);
			*/
		};
		
		function prevImg(){
			if(running==true){
				return;
			}
			running = true;
			var $old_akt = $akt;
			$akt = $akt.prev();
			if ($akt.length == 0)
				$akt = $images.last();
			$akt.css({
				zIndex: 2,
				left:'-' + width + 'px'
			})
			$akt.animate({
				left:'0px'
			}, time, easing, function() {
				$old_akt.css({
					zIndex: 0
				})
				$akt.css({
					zIndex: 1
				})
				running = false;
			});
			/*
			$old_akt.stop().delay(25).animate({
				left: + width + 'px'
			}, time, easing);
			*/
		};

		$gallery = $('.gallery');
		$gallery.find('.prev').bind('click', prevImg);
		$gallery.find('.next').bind('click', nextImg);
		$gallery.bind('dblclick', function (e) {
			e.preventDefault();
			e.stopPropagation();
		});
	}
	
	return {
		init: init
	}
})(jQuery);

