$(document).ready(function(){
						   
	var coll = $("select option:selected").attr("value");
	$("#up").click(function() {
		$('#preview').scrollTo('-=176px');											
	});
	$("#down").click(function() {
		$('#preview').scrollTo('+=176px');								
	});
	
	$(".arrowBtn").hover(
			function() {$(this).fadeTo("fast",0.5)}, function() {$(this).fadeTo("fast",1)}		  
	);
	
	//masquer les fleches
	if($("#preview img").length<10) {
		$(".arrowBtn").hide();	
	}
	
						   
	$.fn.image = function(src, f){ 
		return this.each(function(){ 
		var i = new Image(); 
		i.src = src; 
		i.onload = f; 
		this.appendChild(i);
		}); 
	} 
		
	$('#loading').hide();
	
	
	$('#preview > a').each(function(){
		$(this).click(function(){
			var path = $(this).find('img').attr('src');
			var altViews = $(this).attr("rel");
			var model = $(this).attr("href");
			
			path = path.replace(/tb/, "big");
			model = model.replace(/#mod/, "");
			
			
			//$('#imgHolder').fadeTo('slow',0) ;
			$("#imgHolder").empty();
			$("#loading").show();
			
			$("#imgHolder").image(path,function(){
				$("#loading").hide();
			});
			
			//update AltViews
			$('#altViews').empty();
			
			if (altViews > 1) {
				for(i=2;i<=altViews;i++) {
					$('#altViews').append('<a href="#mod'+model+'" rel="'+altViews+'"><img src="photos/'+coll+'/tb/mod'+model+'_'+i+'.jpg"></a>');
				}
				$('#altViews > a').each(function(){
					$(this).click(function(){
						var path = $(this).find('img').attr('src');
						path = path.replace(/tb/, "big");
						$("#imgHolder").empty();
						$("#loading").show('fast');
						
						$("#imgHolder").image(path,function(){
							$("#loading").hide('fast');
						});
					});
					$(this).hover(
						function() {$(this).fadeTo("fast",0.5)}, function() {$(this).fadeTo("fast",1)}		  
					);
				});
			
			}
			
			return false ;
			
			
			
			
		});
		$(this).hover(
			function() {$(this).fadeTo("fast",0.5)}, function() {$(this).fadeTo("fast",1)}		  
		);
		
		
	});	
});
