jQuery(function($) { 
				
		 $("ul.gallery").children('li').each(function(i) {
				
				// bring the scope
				var _container = $(this);
				
				// reference the original image as a variable and hide it
				var _img = $(this).find('img').css('display','none');
				
				var _src = _img.attr('src');
				var _title = _img.attr('title');
				
				// create loader image            
				var _loader = new Image();

				// begin loader
				$(_loader).load(function () {
					
					// try to bring the alt
					$(this).attr('alt',_img.attr('alt'));

					$(this).attr('class',_img.attr('class'));
					
					//-----------------------------------------------------------------
					// the image is loaded, let's create the thumbnail
					
					var _thumb = _img.clone(true).addClass('thumb').css('display','none');

					if (!_thumb.hasClass('noscale')) { // scaled tumbnails!
						var w = Math.ceil( _img.width() / _img.height() * _container.height() );
						var h = Math.ceil( _img.height() / _img.width() * _container.width() );
						// Switch the greater than symbol for proportioned crops
						if (w > h) {
							//alert('h')
							_thumb.css({ height: 'auto', width: _container.width()-6, marginTop: -(h-_container.height())/2 });
						} else {
							//alert('v')
							_thumb.css({ width: 'auto', height: _container.height()-5, marginLeft: -(w-_container.width())/2 });
						}
					} else { // Center thumbnails.
						window.setTimeout(function() {
							_thumb.css({
								marginLeft: -( _thumb.width() - _container.width() )/2, 
								marginTop:  -( _thumb.height() - _container.height() )/2
							});
						}, 1);
					}
					// add the rel attribute
					_thumb.attr('rel',_src);
					
					// add the title attribute
					_thumb.attr('title',_title);
					
					// prepend the thumbnail in the container
					_container.find('a').prepend(_thumb);

					// show the thumbnail
					_thumb.css('display','block');
					
	
					//-----------------------------------------------------------------
					
					// finally hide the original image
					_img.hide();
					
				}).error(function () {
					
					// Error handling
					_container.html('<span class="error" style="color:red">Error loading image: '+_src+'</span>');
				
				}).attr('src', _src);
			});
	 
	 	
		$("ul.galleryFeature").children('li').each(function(i) {
				
				// bring the scope
				var _container = $(this);
				
				// reference the original image as a variable and hide it
				var _img = $(this).find('img').css('display','none');
				
				var _src = _img.attr('src');
				var _title = _img.attr('title');
				
				// create loader image            
				var _loader = new Image();

				// begin loader
				$(_loader).load(function () {
					
					// try to bring the alt
					$(this).attr('alt',_img.attr('alt'));

					$(this).attr('class',_img.attr('class'));
					
					//-----------------------------------------------------------------
					// the image is loaded, let's create the thumbnail
					
					var _thumb = _img.clone(true).addClass('thumb').css('display','none');

					if (!_thumb.hasClass('noscale')) { // scaled tumbnails!
						var w = Math.ceil( _img.width() / _img.height() * _container.height() );
						var h = Math.ceil( _img.height() / _img.width() * _container.width() );
						// Switch the greater than symbol for proportioned crops
						if (w > h) {
							//alert('h')
							_thumb.css({ height: 'auto', width: _container.width()-6, marginTop: -(h-_container.height())/2 });
						} else {
							//alert('v')
							_thumb.css({ width: 'auto', height: _container.height()-5, marginLeft: -(w-_container.width())/2 });
						}
					} else { // Center thumbnails.
						window.setTimeout(function() {
							_thumb.css({
								marginLeft: -( _thumb.width() - _container.width() )/2, 
								marginTop:  -( _thumb.height() - _container.height() )/2
							});
						}, 1);
					}
					// add the rel attribute
					_thumb.attr('rel',_src);
					
					// add the title attribute
					_thumb.attr('title',_title);
					
					// prepend the thumbnail in the container
					_container.find('a').prepend(_thumb);

					// show the thumbnail
					_thumb.css('display','block');
					
	
					//-----------------------------------------------------------------
					
					// finally hide the original image
					_img.hide();
					
				}).error(function () {
					
					// Error handling
					_container.html('<span class="error" style="color:red">Error loading image: '+_src+'</span>');
				
				}).attr('src', _src);
			});
		
	 }); 
