function Gallery(gallery_options)
{
	var options = {images: [], preview: '', slide_container: ''};	/* Options / Settings:
																	images - list of images for all sizes
																	preview - preview node
																	slides - nodes with slides */
	var images = new Array();								//Array with images [[small_image, medium_image], ...]
	var image_count = 0;									//Image count
	var image_index = 0;									//Current image index
	var image_width = 0;
	var running = false;									//Animation in progress

	var slide_width = 176;
	var slide_control = 0;
	var slide_spacer = 0;

	var preview_items = [];									//Preview objects [[parent <a /> node, child <img /> node], ...]
	
	var _self = this;
	
	/**
	 * Initializes gallery
	 * @param {Object} gallery_options
	 */
	var initialize = function(gallery_options)
	{
		/* Setting gallery options */
			for(var i in gallery_options)
				if (gallery_options.hasOwnProperty(i))
					options[i] = gallery_options[i];
		
			image_count = options.images.length;
			
		/* Catch images */
			slide_control = $(gallery_options.slide_container);			//Slide container, which will be animated
			
			for(var i = 0; i < image_count; i++)
			{
				images[i] = new Image();
				images[i].src = options.images[i][1];
				
				slide_control.prepend('<a href="#"><img src="' + options.images[i][0] + '" alt="" /></a>');
				var a = $('a:first-child', slide_control);
				a[0]._index = i;
			}
			
			$('a', slide_control).click(function () {
				if (this._index < image_index)
					_self.prev();
				else
					_self.next();
					
				return false;
			});
		
		/* Initializing slides */
			var _margin = - (slide_width * (image_count - 2)) - 12
			slide_control.css('marginLeft', _margin + 'px');
			slide_control.append($('<div class="spacer">spacer</div>'));
			
			slide_spacer = $('div.spacer', slide_control);
			slide_spacer.width(570 - slide_width + 'px');
			slide_spacer.css('height', '100px');
		
		/* Initializing preview */
			options.preview = $(options.preview);

			for(var i = 0; i < 2; i++)
			{
				var el = $('<a title=""><img src="' + options.images[0][1] + '" alt="" /></a>');
				
				options.preview.append(el);
				preview_items[i] = [el, $('img', el)];		// [parent <a /> element, child <img /> element]
				
				//el.lightbox();
			}
			
			image_width = preview_items[0][0].width();
	}
	
	/**
	 * Shows next image
	 */
	this.next = function() {
		if (image_index + 1 >= image_count || running)
			return;
		
		running = true;
		image_index++;
		
		/* Preview */
			preview_items[0][0].css({marginLeft: '-' + image_width + 'px'});
			preview_items[0][1][0].src = images[image_index].src;
			
			preview_items[0][0].attr('title', options.images[image_index][3]);
			preview_items[1][0].attr('title', options.images[image_index][3]);
			
			preview_items[0][0].animate({marginLeft: '0px'}, function () {
				preview_items[1][1][0].src = preview_items[0][1][0].src;
				running = false;
			});
		
		/* Slider */
			slide_spacer.insertBefore(slide_spacer.prev());
			var _margin = - (slide_width * (image_count - 2 - image_index)) - 12;
			slide_control.animate({marginLeft: _margin + 'px'});
	};
	/**
	 * Shows previous image
	 */
	this.prev = function () {
		if (image_index <= 0 || running)
			return;
		
		running = true;
		image_index--;
		
		/* Preview */
			preview_items[0][0].css({marginLeft: '0px'});
			preview_items[1][1][0].src = images[image_index].src;

			preview_items[0][0].attr('title', options.images[image_index][3]);
			preview_items[1][0].attr('title', options.images[image_index][3]);
			
			preview_items[0][0].animate({marginLeft: '-' + image_width + 'px'}, function () {
				preview_items[0][1][0].src = preview_items[1][1][0].src;
				running = false;
			});
		/* Slider */
			var _margin = - (slide_width * (image_count - 2 - image_index)) - 12;
			slide_control.animate({marginLeft: _margin + 'px'}, function () {
				slide_spacer.insertAfter(slide_spacer.next());
			});
	};
	/**
	 * Returns current image index
	 */
	this.getImageIndex = function () {
		return image_index;
	};
	/**
	 * Returns image count
	 */
	this.getImageCount = function () {
		return image_count;
	};
	this.openLightbox = function () {
		preview_items[0][0].trigger('click');
	};
	
	
	initialize(gallery_options);
}

$(document).ready(function () {
	
	var gallery_options = {
		images: images || [],
		preview: 'div.preview div.content',
		slide_container: 'div.images div.inner'
	};
	
	var gallery = new Gallery(gallery_options);
	
	$('a.zoom').click(function () {
		gallery.openLightbox();
		return false;
	});
});