$(document).ready(function() {
 
    $('.next').click(function() {
           $(this).parent().parent().parent().parent().parent().fadeOut('slow', function() {
            $(this).next("table").fadeIn('slow', function() {
            });
        }); 
        
    });
    $('.prev').click(function() {
        $(this).parent().parent().parent().parent().parent().fadeOut('slow', function() {
            $(this).prev("table").fadeIn('slow', function() {
            });
        }); 
    });
    
    
    $('.table_gallery img').hover(function(e) {
        var offsetX;

            x = e.pageX-350;
            if (e.pageY > 350){
                y = e.pageY-380;
            }
            else{
                y = e.pageY+60;
            }
            
        
        var zoom = "<div class='zoom' style='top:"+y+";left:"+x+";z-index:100;width:100px'>"+$(this).attr('alt')+"<br /><img src='"+$(this).attr('src')+"' /></div>";
        $('body').prepend(zoom);
         $(this).mouseleave(function(e){
           $(".zoom").remove();
        });
        
    });
    
    $('.table_gallery img').not(".imgSelected").click(function() {
        if ($(this).attr('class')!='imgSelected') {
            var html = "<img src='"+$(this).attr('src')+"' width='60' height='40' style='margin:2px' id='"+$(this).attr('id')+"'/>";
            $(this).addClass('imgSelected');
            $("#basket .content").append(html);
            $.ajax({
            	async: false,
            	type: "POST",
   				url: "../index.php",
   				data: "id=71&add=1&img="+$(this).attr('src'),
			  	success: function(msg) {
			    	return '';
			  	}
			});
            $('.content img').click(function() {
                $(this).remove();  
                id=$(this).attr('id');
                $("#"+id).removeClass('imgSelected');
                $.ajax({
	            	type: "POST",
	   				url: "../index.php",
	   				data: "id=71&delete=1&img="+$(this).attr('src'),
				  	success: function(msg) {
				    	return '';
				  	}
				});
                return false;
            });
        }  
        return false;
    });
    $('.content img').click(function() {
                $(this).remove();  
                id=$(this).attr('id');
                //$("#"+id).removeClass('imgSelected');
                var urlImg = $(this).attr('src');
                var urlIm = urlImg.replace('http://instant-vole.ch/.','')
				$('img[src*='+urlIm+']').removeClass('imgSelected');
                $.ajax({
	            	type: "POST",
	   				url: "../index.php",
	   				data: "id=71&delete=1&img="+$(this).attr('src'),
				  	success: function(msg) {
				    	return '';
				  	}
				});
                return false;
            });
    $('#basket .commande').click(function() {
        $('.table_gallery').fadeOut('slow', function() {
            $("#commande").fadeIn('slow');
        });
        return false;
    });

    	$('#retourGalerie').click(function() {
       		$('#commande').fadeOut('slow', function() {
	         		$("#table_gallery").fadeIn('slow');
	        	});
        		return false;
    	});
}); 
