$(document).ready(function(){
	$('a[rel=fancy-image]').fancybox({
		'titleShow'     : false
	});
	
	// Image Crossfade Plugin
	
	// Check if product page
	if($('.products-preview').attr("src") != undefined){
		
		$('.pictureDetails').click(function(){			
			
			// Prevent Fancybox to open the image (using weblication standart image element)
			$.fancybox.cancel();
			$.fancybox.close();
			
			// Get the url from clicked image and resize it.
			var src = $(this).attr("href");
			var load = "/dick-kuechen-wGlobal/wGlobal/scripts/eit/imageLoader.class.php?src=" + src;
			var url = $.get(load,function(data){
				
				// Clone the old image to create cross-fade effekt
				var imgCloned = $('.products-preview').clone();
				$(imgCloned).attr("class","products-preview-cloned");
				$(imgCloned).appendTo('.fancy-image');
				$('.products-preview').hide();
				$('.products-preview').attr("src",data);
				$('.fancy-image').attr("href",src);
				// Fade in the new image
				$('.products-preview').fadeIn('slow',function(){
					
				})
				
				// Fade out the old one and remove it from dom
				$('.products-preview-cloned').fadeOut('slow',function(){
					$('.products-preview-cloned').remove;
				})
			});
		});
		
	}
	
})

