docLoaded = false;

function testForGalleryCarousel() {
	
	if(document.getElementById('gallery_carousel')) {
		
		document.getElementById('gallery_carousel_holder').style.background = "url(/i/cn-ajax-loader.gif) no-repeat center";
		
		document.getElementById('gallery_carousel').style.display = "none";
		
		clearInterval(galleryCarouselInt);
		
	} else if (docLoaded === true) {
		
		clearInterval(galleryCarouselInt);
		
	}
	
}

galleryCarouselInt = setInterval('testForGalleryCarousel()',10);

$('#gallery_carousel').ready(function() {
	
	docLoaded = true

	if($('#gallery_carousel').children()) {
	
		$('#gallery_carousel').show('fast');
	
		$('#gallery_carousel_holder').css('background','white')
	
		$('#gallery_carousel_holder').prepend('<div class="prev"><a href="" title="Previous"><span></span>Previous</a></div> <div class="next"><a href="" title="Next image"><span></span>Next</a></div>');

		$("#gallery_carousel").jCarouselLite({
		    btnNext: "#gallery_carousel_holder .next",
		    btnPrev: "#gallery_carousel_holder .prev",
		    scroll: 1,
			speed: 300,
			visible: 4
		});
		
/*		$("#gallery_carousel a").click(function(){
			
			imgSrc = cleanSrc($(this).children('img').attr('src'));
			linkSrc = $(this).attr('href');
			caption = $(this).children('img').attr('alt');
			
			
			$('#gallerybox_popup_image img').attr({
												'src':imgSrc,
												'alt':caption
												});
			$('a#gallerybox_popup_image').attr('href',linkSrc);
			$('a#gallerybox_popup_image').next('p').text(caption);

			return false;
			
		})
		*/
	}
	
})

	function cleanSrc(path){
	
	srcPath = path.replace('_45','_220');
	
	return srcPath;
	
	}

