var selectedImageID = 'id_0';
function PreviewPhoto(url, url2, id)
{
	//alert(123);
	var imgPhotoDetail = document.getElementById('abc');
	//var hlPhoto = document.getElementById('abcd_show');
	var simgPhoto = document.getElementById(id);
	var sselectedImageID = document.getElementById(selectedImageID);
	imgPhotoDetail.src = url;
	//imgPhotoDetail.data-zoomsrc = url2;
	//hlPhoto.href= url2;
	simgPhoto.style.border = '1px solid #cccccc';
	MojoZoom.init();
	
}
function OnmouseoutPhoto(id)
{	
	document.getElementById(id).style.border = '1px solid #cccccc';
}
function delete_pic(id){
	$.ajax({
		type: 'POST',
		url: '/vn/delete_pic.php',
		data: 'record_id='+id,
		success: function(msg){
		  if(msg!=''){
		  	alert( msg );
				$('#'+id).remove();
		  }
		}
	});
}

function trim_1(sString){
	while(sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while(sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
		return sString;
}
function checkblank_1(str){
	if(trim_1(str) == '') return true;
	else return false;
}	
function isemail_1(email) {
	var re = /^(\w|[^_]\.[^_]|[\-])+(([^_])(\@){1}([^_]))(([a-z]|[\d]|[_]|[\-])+|([^_]\.[^_])*)+\.[a-z]{2,3}$/i
	return re.test(email);
}

// phần ảnh hover ////

    (function($){

        //$("#categorie_product_box_ul li").css('display', 'none');
        // apparition effect
        if(navigator.userAgent.indexOf("MSIE 6") != -1) {
			$('.categorie_product_effet_apparition').css('display','block');
        }
        else {
	        var panier_duree=200;
	        var tot_prod = $('.categorie_product_effet_apparition').length;
	        for(var k=0; k< tot_prod ; k++) {
	            $($('.categorie_product_effet_apparition')[k]).delay(panier_duree).fadeIn(300);
	           	panier_duree = panier_duree + 100;
	        }
        }

        //effet hover produit
            var hover_product_info=false;
            var precedent_id;
            var timer;
            $(".categorie_product_li").mouseover(function(){
                hover_product_info=true;
                var id = $(this).attr('id');
                //$("#"+id+ " .img_product_image").css('display','none');
                //$("#"+id+ " .img_product_image_vue_2").css('display','block');
                //$("#"+id+ " .img_product_image_vue_2").fadeIn(50);
                $(this).css('background-position', 'top right');
                timer=setTimeout(function() {
                    $("#"+id+ " .product_info").fadeIn(150, function(){
                    });
                    if($(precedent_id) && precedent_id!=id){
                        $("#"+precedent_id+ " .product_info").fadeOut(100);
                    }
                    precedent_id=id;
                }, 10);

            });

            $(".categorie_product_li").mouseout(function(){
                clearTimeout(timer);
                hover_product_info=false;
                var id = $(this).attr('id');
                $(this).css('background-position', 'top left');
                //$("#"+id+ " .img_product_image_vue_2").css('display','none');
                //$("#"+id+ " .img_product_image").css('display','block');
                setTimeout(function() {
                    if(!hover_product_info) {
                        $("#"+id+ " .product_info").fadeOut(100);
                    }
                }, 10);

            });


			// achat rapide : Toujours le garder avant l'�couteur sur la class ".product_info"
			
			 var click_product_info_achat = false;
			 var Falg_product_info_achat = false;
			$('.link_product_achat_rapide').click(function() {
				if(!Falg_product_info_achat) {
					Falg_product_info_achat = true;
					click_product_info_achat=true;
					$(this).css("cursor","wait");
					$("#wrapper").css("cursor","wait");
					$('#overlay_achatRapide').css("opacity","0.5");
					if(navigator.userAgent.indexOf("MSIE 6") != -1) {
						$('#overlay_achatRapide').addClass("overlay_achatRapide_IE");
						$('#Container_box_achat_rapide').addClass("Container_box_achat_rapide_IE");
					}
					else {
						$('#box_achat_rapide').addClass("achat_rapide_center_vertical");
					}
					var id_product = $(this).parent().children('input').val();
					$.ajax({
						type: 'GET',
						processData: true,
						url: "http://www.nafnaf.com/fr/ajaxcart/catalog_product/achatrapide/id/"+id_product,
						data: id_product,
						dataType: 'php',
						success: function(data){
								$('#box_achat_rapide').html(data);
								if(navigator.userAgent.indexOf("MSIE 6") != -1) {
									$.scrollTo( "#wrapper", 'slow', function(){
										$('html').addClass("not_scroll");
									}); 
								}
								$('#Container_box_achat_rapide').fadeIn(400);
								$('#overlay_achatRapide').fadeIn(400);
								$('#moreDetails-rapide').css("display","block");
								
								$(".link_product_achat_rapide").css("cursor","pointer");
								$("#wrapper").css("cursor","default");
								click_product_info_achat=false;
								Falg_product_info_achat = false
			           	}
		            });
				}
				return false;
			});


            
            // lien on product info by js

            var click_product_info= false;

            $(".product_info").hover(function(){
                $(this).css('cursor', 'pointer');
            },function(){
            	$(this).css('cursor', 'default');
            });

            $(".categorie_colors_js").hover(function(){
              	click_product_info=true;
              	
            },function(){
            	click_product_info=false;
            });
			
            $(".product_info").click(function(){
                id=$(this).attr('id');
                href=$('#link_'+id).attr('href');
                if(href!=undefined && href!='' && !click_product_info && !click_product_info_achat)
                {
                    document.location.href= href;
                    return false;
                }
             });

            // transition entre les 2 images d'un produit

            $(".categorie_product").hover(function(){
                if(!$(this).hasClass('moyen_b') && !$(this).hasClass('moyen') && !$(this).hasClass('grand_b') && !$(this).hasClass('grand')) {
                	var id = $(this).attr('id');
                	if( ($("#"+id+ " .product_image_js").attr('src')!=$("#"+id+ " .product_image_js_vue_2").attr('src')) && ($("#"+id+ " .product_image_js").attr('title')==$("#"+id+ " .product_image_js_vue_2").attr('title')) ) {
	                	$("#"+id+ " .product_image_js").fadeOut(200);
	                	$("#"+id+ " .product_image_js_vue_2").fadeIn(200);
                	}
                }
            }, function() {
            	if(!$(this).hasClass('moyen_b') && !$(this).hasClass('moyen') && !$(this).hasClass('grand_b') && !$(this).hasClass('grand') ) {
	                var id = $(this).attr('id');
	                if( ($("#"+id+ " .product_image_js").attr('src')!=$("#"+id+ " .product_image_js_vue_2").attr('src')) && ($("#"+id+ " .product_image_js").attr('title')==$("#"+id+ " .product_image_js_vue_2").attr('title')) ) {
		            	$("#"+id+ " .product_image_js_vue_2").fadeOut(200);
	                	$("#"+id+ " .product_image_js").fadeIn(200);
	                }
            	}
            });


    })(jQuery);

    // function js ajout produit au wislist

	(function($){

			var cible;
			var catName = "robes du soir";
			var urladd =  "http://www.nafnaf.com/fr/ajaxwishlist/index/addajax/";
			var urlremove = "http://www.nafnaf.com/fr/ajaxwishlist/index/removeajax/";
			$('.product-love').click(function() {
					cible = this;
					var id = $(this).children('input').val();
					if(!$(cible).hasClass('sel')){
						_gaq.push(['_trackEvent', 'wishlist', 'Page Categorie', catName ]);
						$.post(urladd,'product='+id, function success(){
							$(cible).addClass('sel');
							$('.historique_product_'+id).append('<span class="histojaime">&hearts;</span>');
						}, "json");
					}
					else {
						$.post(urlremove, 'product='+id,function success(){
							$(cible).removeClass('sel');
							$('.historique_product_'+id+' span.histojaime').remove();
						}, "json");
					}
					$('#wrapper').css('cursor', 'default');
			});
	})(jQuery);

