﻿/*
 * jQuery MiniGallery plugin
 *
 */
;(function($) {

	// Write noscript style
	document.write("<style type='text/css'>.noscript{display:none}</style>");

	var image1;
	var image2;
	var image3;
	var image4;
	var fadeSpeed = 400;
	var images = [];
	var loading = false;

	$.fn.miniGallery = function(path, id, quantityOfImages)
	{
		$.extend(this,
		{
			initialize: function()
			{
				for (i = 1; i <= quantityOfImages; i++) {
					image = new Image();
					image.src = path + 'entityfiles/pictures/cms_products/pic' + i + '/med_' + id + '.jpg';
					images[i] = image;
				}
				return this;
			},

			fadeImage: function()
			{
				$("#mainPic").fadeTo(fadeSpeed, 0);
			},
			
			showImage: function(id)
			{
				$("[@id^='mainPic-image']").attr('class', 'hide');
				$("#mainPic-image"+id).attr('class', 'show');
				$("#mainPic").fadeTo(fadeSpeed, 1);
				return this;
			}
		});
		if (loading == false)
		{
			var gallery = this;
			$(".small a").click(function()
			{
				var id = $(this).attr('id');
				var ImageId = $("[@class^='show']").attr('id');
				ImageId = ImageId.substring(13);
				if (ImageId != id)
				{
					loading = true;
					gallery.fadeImage();
					setTimeout(function() { gallery.showImage(id); }, fadeSpeed);
					loading = false;
				}
			});
		}
	};

})(jQuery);
