/**
 * Vizia Ltd.
 * @custom js scripts
**/

jQuery.preloadImages = function()
{
  var sources = new Array();
  
  sources = arguments[0];
  
  var completed = 0;
  
  for(var i = 0; i < sources.length; i++)
  {
    img = jQuery("<img>").attr("src", sources[i]);
  }
}

function preloadCarouselImages(container){
	 
	container = $(container);
	
	var images = container.find('img');
	var images_src = new Array();

	for(i = 0; i < images.length; i++){
		images_src[i] = $(images[i]).attr('alt');
		
	}
	
	$.preloadImages(images_src);
	
	 $('#blockPicture .itemImageArea a').click(function(e){
	    	
	 		hs.expand(null, {
				src: $('#'+$(this).attr('class')).attr('href'),
				slideshowGroup: 'carousel_slider'
			});

	    	e.preventDefault();
	    })
	
	$('#product_carousel a').hover(function(){
		alt_var = $(this).find("img").attr("alt");
		href_var = $(this).attr("href");
		var thisId = $(this).attr('id');
		if (href_var != $('#blockPicture .itemImageArea').find("img").attr("src")){
			if ($('#blockPicture .itemImageArea img').is(':animated')) {
				$('#blockPicture .itemImageArea img').stop().animate({opacity: 0}, 200, function(){
					$(this).attr("src", alt_var).animate({opacity: 1}, 400	);
					$('#blockPicture .itemImageArea a').attr("href", href_var);
					$("#blockPicture .itemManufacturer .zoom_in").attr("href", href_var);
					$("#blockPicture .itemImageArea a").removeClass();
					$("#blockPicture .itemImageArea a").addClass(thisId)
					
				});
			}
			else {
				$('#blockPicture .itemImageArea img').animate({opacity: 0}, 200, function(){
					$(this).attr("src", alt_var).animate({opacity: 1}, 400	);
					$('#blockPicture .itemImageArea a').attr("href", href_var);
					$("#blockPicture .itemManufacturer .zoom_in").attr("href", href_var);
					$("#blockPicture .itemImageArea a").removeClass();
					$("#blockPicture .itemImageArea a").addClass(thisId)
				});
			}
		}
	 		
	},function(){
		return false;
	});
	
	
}

/**********************************/
/* JQuery document ready function */
/**********************************/

jQuery(document).ready(function() {

	jQuery('#product_carousel').jcarousel({
		// Configuration goes here
		scroll: 1
	});
 	
	preloadCarouselImages('#product_carousel');
});
