$(document).ready(function(){


	$('#menu_top').find('ul').parent().each(function(){
		
		var submenu = $(this).find('ul:eq(0)');

		$(this).hover(
			function(){
				submenu.fadeIn('fast');
			},
			function(){
				submenu.fadeOut('fast');
			}
		);
	});

    /** Animation zoom */
        $("ul#produits li,ul.thumb li").each(function(){
        
            var Elem = $(this).find('img');
            Elem.load(function(){anime($(this));});
              
        });

    if ($("ul#produits").length > 0) {
        /** Défilement */
        var start = 10;
        var ulsize = $("ul#produits").width();
        
        $("ul#produits li").each(function(){
            $(this).css('left',start+'px');
            start += $(this).width() + 10;
            $(this).show('slow');
        });
        
        var ecart = start - ulsize;
        
        if (ecart > 0) {
            $('#arrow_left,#arrow_right').css('display','block');
            $('#arrow_right').live('click', function() {
                var posfirst = $("ul#produits li:first").position();
                
                if (ecart + (posfirst.left - 10) > 0) {
                    $("ul#produits li").each(function(){
                        var lipos = $(this).position();
                        $(this).animate({left: lipos.left - ($(this).width()+10)},500);
                    });
                }
            });
            
            $('#arrow_left').live('click', function() {
                var posfirst = $("ul#produits li:first").position();
                
                if (posfirst.left < 10) {
                    $("ul#produits li").each(function(){
                        var lipos = $(this).position();
                        $(this).animate({left: lipos.left + ($(this).width()+10)},500);
                    });
                }
            });
        }
        
    }

});

function anime(Elem)
{
 var size = [ Elem.width(), Elem.height()];
    var newsize = [size[0] * 1.2, size[1] * 1.2];

    
    Elem.hover(function(){
        $(this).stop().animate({
				marginTop: '0', 
				marginLeft: '-' + Math.round((newsize[0]  - size[0]) / 2),
				bottom: '0', 
				left: '0', 
				width: newsize[0]+'px', 
				height: newsize[1]+'px',
				padding: '0px' 
			}, 200);
    },
    
    function(){
        $(this).stop().animate({
				marginTop: '0', 
				marginLeft: '0',
				bottom: '0', 
				left: '0', 
				width: size[0]+'px', 
				height: size[1]+'px',
				padding: '0px' 
			}, 200);
    });
}
