(function($) {
	$.fn.gallery = function(options) {
		var defaults = {
			image1_left: '-375px',
			image2_left: '5px',
			image3_left: '155px'
		};
		var options = $.extend(defaults, options);

		return this.each(function() {
			var obj = $(this);
			var images = $('img', obj);
			var length = images.length;

			// init
			$(images).each(function(index) {
				$(this).attr('status', index);
				$(this).css('z-index', '8');

				if (index == 0) {
					$(this).css('left', options.image1_left);
				} else if (index == 1) {
					$(this).css('left', options.image2_left);
					$(this).css('z-index', '9');
				} else if (index == 2) {
					$(this).css('left', options.image3_left);
				} else {
					$(this).css('display', 'none');
				}
			});

			// arrow left
			$('#galleryframe_arrow_left').click(function() {
				$(images).each(function(index) {
					var newStatus = parseInt($(this).attr('status')) - 1;
					if (newStatus < 0) {
						newStatus = length - 1;
					}

					$(this).attr('status', newStatus);
					$(this).css('z-index', '8');
					$(this).css('display', 'none');

					if (newStatus == 0) {
						$(this).css('left', options.image1_left);
						$(this).css('display', 'block');
					} else if (newStatus == 1) {
						$(this).css('left', options.image2_left);
						$(this).css('z-index', '9');
						$(this).css('display', 'block');
					} else if (newStatus == 2) {
						$(this).css('left', options.image3_left);
						$(this).css('display', 'block');
					}
				});
			});

			// arrow right
			$('#galleryframe_arrow_right').click(function() {
				$(images).each(function(index) {
					var newStatus = parseInt($(this).attr('status')) + 1;
					if (newStatus == length) {
						newStatus = 0;
					}

					$(this).attr('status', newStatus);
					$(this).css('z-index', '8');
					$(this).css('display', 'none');

					if (newStatus == 0) {
						$(this).css('left', options.image1_left);
						$(this).css('display', 'block');
					} else if (newStatus == 1) {
						$(this).css('left', options.image2_left);
						$(this).css('z-index', '9');
						$(this).css('display', 'block');
					} else if (newStatus == 2) {
						$(this).css('left', options.image3_left);
						$(this).css('display', 'block');
					}
				});
			});
		});
	};
})(jQuery);

