$(document).ready(function(){ 
	
	//alert(document.getElementById('discography-page').style.display);

	// Gallery
	if(jQuery("#originals-gallery").length){
	//alert(jQuery("#originals-gallery").length);
		
		// Variables aren't use properly due to Webkit
		var totalImages = jQuery("#originals-gallery > li").length, 
			imageWidth = jQuery("#originals-gallery > li:first").outerWidth(true),
			totalWidth = imageWidth * totalImages,
			visibleImages = Math.round(jQuery("#originals-gallery-wrap").width() / imageWidth),
			visibleWidth = visibleImages * imageWidth,
			stopPosition = (visibleWidth - totalWidth);
			//alert(jQuery("#originals-gallery > li").length);
			
		jQuery("#originals-gallery").width(totalWidth);
		
		jQuery("#originals-gallery-prev").click(function(){
			if(jQuery("#originals-gallery").position().left < 0 && !jQuery("#originals-gallery").is(":animated")){
				jQuery("#originals-gallery").animate({left : "+=" + imageWidth*4 + "px"});
			}
			return false;
		});
		
		jQuery("#originals-gallery-next").click(function(){
			if(jQuery("#originals-gallery").position().left > stopPosition && !jQuery("#originals-gallery").is(":animated")){
				jQuery("#originals-gallery").animate({left : "-=" + imageWidth*4 + "px"});
			}
			return false;
		});
	}
	
	if(jQuery("#remix-gallery").length){
	//alert(jQuery("#remix-gallery").length);
		
		// Variables aren't use properly due to Webkit
		var totalImages = jQuery("#remix-gallery > li").length, 
			imageWidth = jQuery("#remix-gallery > li:first").outerWidth(true),
			totalWidth = imageWidth * totalImages,
			visibleImages = Math.round(jQuery("#remix-gallery-wrap").width() / imageWidth),
			visibleWidth = visibleImages * imageWidth,
			stopPosition = (visibleWidth - totalWidth);
			//alert(jQuery("#remix-gallery > li").length);
			
		jQuery("#remix-gallery").width(totalWidth);
		
		jQuery("#remix-gallery-prev").click(function(){
			if(jQuery("#remix-gallery").position().left < 0 && !jQuery("#remix-gallery").is(":animated")){
				jQuery("#remix-gallery").animate({left : "+=" + imageWidth*4 + "px"});
			}
			return false;
		});
		
		jQuery("#remix-gallery-next").click(function(){
			if(jQuery("#remix-gallery").position().left > stopPosition && !jQuery("#remix-gallery").is(":animated")){
				jQuery("#remix-gallery").animate({left : "-=" + imageWidth*4 + "px"});
			}
			return false;
		});
	}
	
	if(jQuery("#picturesgigs-gallery").length){
	//alert(jQuery("#remix-gallery").length);
		
		// Variables aren't use properly due to Webkit
		var totalImages = jQuery("#picturesgigs-gallery > li").length, 
			imageWidth = jQuery("#picturesgigs-gallery > li:first").outerWidth(true),
			totalWidth = imageWidth * totalImages,
			visibleImages = Math.round(jQuery("#picturesgigs-gallery-wrap").width() / imageWidth),
			visibleWidth = visibleImages * imageWidth,
			stopPosition = (visibleWidth - totalWidth);
			//alert(jQuery("#remix-gallery > li").length);
			
		jQuery("#picturesgigs-gallery").width(totalWidth);
		
		jQuery("#picturesgigs-gallery-prev").click(function(){
			if(jQuery("#picturesgigs-gallery").position().left < 0 && !jQuery("#picturesgigs-gallery").is(":animated")){
				jQuery("#picturesgigs-gallery").animate({left : "+=" + imageWidth*4 + "px"});
			}
			return false;
		});
		
		jQuery("#picturesgigs-gallery-next").click(function(){
			if(jQuery("#picturesgigs-gallery").position().left > stopPosition && !jQuery("#picturesgigs-gallery").is(":animated")){
				jQuery("#picturesgigs-gallery").animate({left : "-=" + imageWidth*4 + "px"});
			}
			return false;
		});
	}
	
	$(".mediagallery").fancybox({
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.4
	});	
		
});
