/**
 * @author imac
 * Document Jquery
 */

$(document).ready(function(){
	var agent=navigator.userAgent.toLowerCase();
	
	codeRegex = /mobile/i;

	//alert(codeRegex.test(agent));
		
	if(codeRegex.test(agent) == true){
		//alert('Mobile');
		menuMobile();
	}
	
	else{
		//alert('Ordinateur');
		//$('.module-menu-navigation li span').click(menuMobile);
	}


	
	function menuMobile(){
		
		$('.module-footer .mentions-legales').css({
			fontSize:'9px'
		})
		
		$('.module-menu-navigation li span p').click(function(){
			$('.module-menu-navigation li').removeClass('menu-mobile');
			$(this).parent().parent().addClass('menu-mobile');
		});
	}




	function changeVisuelProduct(){
		
		bigImageOldSrc = $('#module-produit .big-image img').attr('src')
		
		miniImageSrc = $(this).find('img').attr('src');
		
		bigImageSrc = miniImageSrc.replace('57x57','600x600');

		//alert(bigImageOldSrc +'\n'+bigImageSrc)
		
		
		if(bigImageOldSrc != bigImageSrc){
			$('#module-produit .big-image img').animate({
				opacity:0,
			},200, function(){
				$(this).attr('src',bigImageSrc);
				$(this).animate({
					opacity:1
				},200);
			})
		}

	}

	function initPageProduit(){
		$('#module-produit .mini-image').hover(changeVisuelProduct);
	}
	
	initPageProduit();
	
	function popupImageProduit(){
		imageProduitSrc = $(this).parent().find('a img').attr('src').replace('223x223','600x600');
		
		$('.bg-popup-image-produit .exit-left').css({
			width: '50%'
		})
		
		$('.bg-popup-image-produit .exit-right').css({
			width: '50%'
		})
		
		$('.popup-image-produit').append('<img src="'+ imageProduitSrc +'"/>');
		
		$('.bg-popup-image-produit').fadeIn(250);
		
	}
	
	$('#liste-products li .zoom-product').click(popupImageProduit);
	
	function closePopupImageProduit(){
		$('.bg-popup-image-produit').fadeOut(250, function(){
			$(this).find('img').remove();
		});
	}
	
	$('.bg-popup-image-produit .exit-left').click(closePopupImageProduit);
	$('.bg-popup-image-produit .exit-right').click(closePopupImageProduit);
	
});

