function loadGallery() {
	var go = $('#gallery_objects');
	if ($.browser.msie && parseInt($.browser.version) <= 6)
	{
		clearInterval(gInterval);
		go.remove().appendTo('#gallery_wrapper');
	}
	else
	{
		$('#image_container').css('overflow','visible');
		if (go.length == 1)
		{
			clearInterval(gInterval);
			
			var bigImgWidth = 530;
			var bigImgQuality = 75;
			var lightBoxWidth = 850;
			var lightBoxQuality = 90;
			
			var visible = 3;
			
			$('.prev_static').hide();
			$('.next_static').hide();
		
			// Check the next and previous links to see which one should be disabled
			function checkNextPrev(index)
			{
				var cont = $('#image_container');
	        	$('a:not(.zoom)', cont).addClass('disabled');
		        $('a.overlay:not(.zoom)', cont).hide();
		        if (index > 0)
		        {
		        	$('a.prev', cont).removeClass('disabled');
		        	$('a.overlay.prev', cont).show();
		        }
		        if (index < total - 1)
		        {
		        	$('a.next', cont).removeClass('disabled');
		        	$('a.overlay.next', cont).show();
		        }
			}
			function switchImg(index, animate){
				// We can't give arguments defaults in the function declaration :(
				animate = (animate === false) ? false : true;
				
				// Cache the image container div
				var cont = $('#image_container');
				// Get the new image from the gallery_objects div
				var newImg = $('li:eq(' + index + ') img:first', go);
				// Get the new image's src and replace the dimensions and quality with the large versions
		        var newsrc = newImg.attr('src').replace(/(.*)-[0-9]{1,4}-([0-9]{1,3}).([a-zA-Z]{3}$)/gi , "$1-" + bigImgWidth + "-" + bigImgQuality + ".$3");
		        var newBigSrc = newImg.attr('src').replace(/(.*)-[0-9]{1,4}-([0-9]{1,3}).([a-zA-Z]{3}$)/gi , "$1-" + lightBoxWidth + "-" + lightBoxQuality + ".$3");
		        var pagetitle = $('li:eq(' + index + ') a', go).attr('title') + ' | MusicRadar.com';
		        // Stop all animations and remove all but the last img
		        $('.inner img', cont).stop();
		        // Create the new img element and animate it when it's finished loading
		        var newImgEl = $('<img>').attr('src', newsrc).attr('alt', newImg.attr('alt')).css({ opacity: 0 }).hide().appendTo(cont.find('.inner'));
		        newImgEl.load(function () {
		        	if (animate)
		        	{
			        	$('img:first', cont).animate({ opacity: 0}, {
			        		complete: function() {
				        		$('img:not(:last)', cont).remove();
					        	newImgEl.show().animate({ opacity: 1 }, {
							        speed: 'slow'
							    });
			        		},
			        		speed: 'slow'
			        	});
		        	}
		        	else
		        	{
		        		newImgEl.show().css('opacity', 1);
		        		newImgEl.siblings('img').remove();
		        	}
			        // Update the caption with the new caption
		        	alt = newImg.attr('alt');		        			        			        	
			        copy = alt.match(/\(\([A-z0-9:\\\/|\- ]*\)\)/gi);			        			        
			        alt_safe = alt.replace(/\(\([A-z0-9:\\\/|\- ]*\)\)/gi,'');
		        	
			        if(copy!=null) {
			        	copy = copy.toString().replace(/\(\(/,"").replace(/\)\)/,"");
			        	copy = '&copy; ' + copy;
			        }			        			        
			        $('p.copyright', cont).html(copy);			        
		        	$('#gallery_caption').text(alt_safe);
			        $('#gallery_title').text(newImg.attr('title'));
			        			        
			        document.title = pagetitle;
			         
			        $('#gallery_pagination span.count').text((index + 1));

		        });
		        // Select the new image in the gallery_objects div
		        newImg.parent().parent().siblings('li.slc').removeClass('slc');
		        newImg.parent().parent().addClass('slc');
		        // Check the next and previous links to see which ones should be enabled
		        checkNextPrev(index);

		        var data = $('a.zoom', cont).data('fancybox');
		        data.href = newBigSrc;
		        $('a.zoom', cont).data('fancybox', data);

		        // Change the image credits if they exist (they're defined in the page - a little ugly but it works and validates)
		        var ord = Math.ceil(Math.random() * 10000000),
	        	mpu = $('iframe.mpu'),
	        	//gallery_takeover = $('iframe.gallery_takeover'),
	        	top_banner = $('#header_ad'),
		        mpuSrc = mpu.attr('src'),
		        bannerSrc = top_banner.attr('src');
	        
		        // Refresh the MPU and banner
		        mpu.attr('src', mpu.attr('src'));
		        top_banner.attr('src', top_banner.attr('src'));
	        	//gallery_takeover.attr('src', gallery_takeover.attr('src'));
		        //top_banner.remove().attr('src', bannerSrc.replace(/ord=[0-9]+/, 'ord=' + ord)).appendTo('#top_banner');
		        		        
		        // Refresh the sitestat code - wait til the document is loaded as site stat is at the bottom
		        $(document).ready(function() {
		        	sitestat(ssurl);
		        });
	        
		        // Add the index to the page hash
		        window.location.hash = '#' + (index + 1);
			}
			
			// Make start the index of the current item, get the total number of items, and set the carousel start to the start index of the current item
		    var start = $('ul li', go).index($('ul li.slc:first', go)[0]), total = $('ul li', go).length, startC = start;
		    visible = (total < visible) ? total : visible;
			
		    if (go.find('li').length > visible)
			{
		    	go.prepend('<a class="btn btnPrev" href="#"><span></span>Previous</a>').append('<a class="btn btnNext" href="#"><span></span>Next</a>').find('#gallery_items').wrap('<div class="holder"></div>');
			}
			var refreshAd = true;
			
			var currImg = $('#image_container img');
			
			if (currImg.parent('a').length == 1)
			{
				currImg.unwrap();
			}
			currImg.wrap('<div class="inner"></div>');
			if (total > 1)
			{
				currImg.before('<a class="overlay prev" href="#"><span></span></a><a class="overlay next" href="#"><span></span></a>');
			}
			currImg.before('<a class="overlay zoom" href="#"></a>');
			
			$('li a', go).click(function() {
				switchImg($('ul li', go).index($(this).parent()[0]));
				return false;
			});
			
			$('#image_container a:not(.zoom)').click(function() {
				switchImg($('ul li', go).index($('ul li.slc', go)[0]) + ($(this).hasClass('prev') ? -1 : +1));
				if ($(this).hasClass('prev'))
				{
					$('a.btnPrev').click();
				}
				else
				{
					$('a.btnNext').click();
				}
				return false;
			});
			
			var data = $('#image_container a.zoom').fancybox({
				overlayShow: true,
				type: 'image',
				autoScale: true
			}).data('fancybox');
			data.href = $('#image_container img').attr('src').replace(/(.*)-[0-9]{1,4}-([0-9]{1,3}).([a-zA-Z]{3}$)/gi , "$1-" + lightBoxWidth + "-" + lightBoxQuality + ".$3");
			$('#image_container a.zoom').data('fancybox', data);
			var page = parseInt(window.location.hash.substr(1));
			if (page && page > 0 && page <= total)
			{
				switchImg(page - 1, false);
				start = page-1;
			}
			
			// If the current item is not in the first (visible / 2) or in the last (visible / 2), make it central
			if (start < Math.floor(visible / 2))
		    {
				startC = 0;
		    }
		    else if (start >= total - Math.floor(visible / 2))
		    {
		    	startC = total - visible;
		    }
		    else
		    {
		    	startC = start - Math.floor(visible / 2);
		    }
					
			var pagetitle = $('li:eq(' + start + ') a', go).attr('title') + ' | MusicRadar.com';
		    
			// Hide the previous or next buttons if required
			checkNextPrev(start);
			$('.holder', go).jCarouselLite({
				visible: visible,
				start: startC,
				circular: false,
				btnNext: '#gallery_objects .btnNext',
				btnPrev: '#gallery_objects .btnPrev'
			});
			
			// Check to see if we need to skip to another image
			
		}
		else
		{
			// Create a carousel on the article
			go = $('#gallery_thumbs');
			
			if (go.length == 1)
			{
				var visible = go.parents('#review_gallery').length > 0 ? 3 : 4;
				
				clearInterval(gInterval);
				
				if (go.find('li').length <= visible)
				{
					return;
				}
				
				go.wrap('<div id="gallery_objects"><div class="holder"></div></div>').attr('id', 'gallery_items');
				go = $('#gallery_objects');
				go.prepend('<a class="btn btnPrev" href="#"><span></span>Previous</a>').append('<a class="btn btnNext" href="#"><span></span>Next</a>');
				$('.holder', go).jCarouselLite({
					visible: visible,
					start: start,
					circular: false,
					btnNext: '#gallery_objects .btnNext',
					btnPrev: '#gallery_objects .btnPrev'
				});
			}
		}
	}
}

gInterval = setInterval('loadGallery()', 50);

$(function() {
	clearInterval(gInterval);
});
