jQuery(document).ready(function(){        
	jQuery('.access-rapide li p').click(function() {
		if (jQuery(this).parent().hasClass("actif")) {
			jQuery(this).parent().children(".roll").css('display', 'none');
			jQuery(this).parent().removeClass('actif');
			return false;	
		}
		jQuery('.access-rapide .roll').css('display', 'none');
		jQuery(".access-rapide li").removeClass('actif');
		jQuery(this).parent().children(".roll").css('display', 'block');
		jQuery(this).parent().addClass('actif');
	});
	
	jQuery('.access-rapide .roll').mouseover(function() {
        jQuery(this).css('display','block');
    }).mouseout(function() {
        jQuery(this).css('display','none');
        jQuery(".access-rapide li").removeClass('actif');
    });
	
	/*
	 *	Menu  
	 */
	jQuery('.lv0-menu').mouseover(function() {
		jQuery(this).children('.lv1').css('display', 'block');
		jQuery(this).addClass('active');
	}).mouseout(function() {
		jQuery(this).children('.lv1').css('display', 'none');
		jQuery(this).removeClass('active');
	});
	
	jQuery('.lv0').mouseover(function() {
		jQuery(this).addClass('active');
	}).mouseout(function() {
		jQuery(this).removeClass('active');
	});
	

	jQuery('.smenu-lv1').mouseover(function() {
		id = jQuery(this).attr("id").substring(10);
		jQuery(this).parent().parent().children('.detail-smenu').css('display', 'none');
		jQuery('#detail-smenu-'+id).css('display', 'block');
		
		jQuery(this).parent().children('.smenu-lv1').removeClass('active');
		jQuery(this).addClass('active');
	});
	
	// carroussel catalogues home et footer
	jQuery('.bloc-catalogues .pager a').click(function() {
		if (jQuery(this).hasClass("actif")) {
			return false;
		}
		num = jQuery(this).attr("id").substring(2);
		jQuery('.bloc-catalogues .cata').css('display', 'none');
		jQuery(".bloc-catalogues .pager a").removeClass('actif');
		jQuery('.cat' + num).fadeIn();
		jQuery(".bloc-catalogues .pager a#bt" + num).addClass('actif');
		return false;
	});

	
	/*
	 * Popups et Images tournantes 
	 */
	jQuery('.photo').mouseover(function() {
		var p = jQuery(this).position();
		var nbImg = jQuery(this).attr("id").substring(13);	
		// pour la page rayon	
		if (jQuery(this).parent().attr("class") == "last") {
            jQuery("#popup-" + nbImg).css("left",p.left - 520).css("top",p.top -20).css("display","block");
		// pour la page rayon	
        } else if (jQuery(this).parent().attr("class") == "first") {
            jQuery("#popup-" + nbImg).css("left",p.left + 210).css("top",p.top  -20).css("display","block");
		// pour le bloc produit dans le menu du header	
        } else if (jQuery(this).parent().attr("class") == "push-product") {
            jQuery("#popup-" + nbImg).css("left",p.left + 212).css("top",p.top + 30).css("display","block");
		// pour le bloc produit de la home (ceux qui vont par 4)
        } else if (jQuery(this).parent().attr("class") == "push-home-bloc") {
            jQuery("#popup-" + nbImg).css("left",p.left + 136).css("top",p.top -20).css("display","block");
		// pour les bloc produits nouveau, promo en bas de la home
        } else if (jQuery(this).parent().attr("class") == "encart-produit-home produit-gauche" || jQuery(this).parent().attr("class") == "encart-produit-home produit-milieu") {
        	jQuery("#popup-" + nbImg).css("left",p.left + 175).css("top",p.top + -20).css("display","block");
		// pour le bloc meilleures ventes en bas de la home
        } else if (jQuery(this).parent().attr("class") == "encart-produit-home produit-droite") {
        	jQuery("#popup-" + nbImg).css("left",p.left - 516).css("top",p.top + -20).css("display","block");
		// truc de base
		} else {
        	jQuery("#popup-" + nbImg).css("left",p.left + 0).css("top",p.top + 0).css("display","block");
        }

		
//        console.log(jQuery(this).parent().attr("class"));
	}).mouseout(function(){
		jQuery(".popup-prod-rayon").css("display","none");
	});

    jQuery(this).everyTime(3000, function() {
    	//gallery-X-Y
    	var oldPdt = null;
        jQuery('.photo_product_gallery').each(function() {
        	var nbImg = jQuery(this).attr("id").substring(8).substring(jQuery(this).attr("id").substring(8).indexOf('-')+1);
        	var pdt = jQuery(this).attr("id").substring(8).substring(0, jQuery(this).attr("id").substring(8).indexOf('-'));

			if (jQuery(this).css("display") == 'block' && pdt != oldPdt) {
            	jQuery(this).css("display", "none");
            	el = document.getElementById("gallery-"+pdt+"-"+(parseInt(nbImg)+1));
            	if (el != null) {
	            	jQuery("#gallery-"+pdt+"-"+(parseInt(nbImg)+1)).css("display", "block");
				} else {
            		jQuery("#gallery-"+pdt+"-0").css("display", "block");
				}
				oldPdt = pdt;
			} 
        });

        //img-collection-grande-X-Y
        var oldPdt = null;
        jQuery('.photo_product_gallery_popup').each(function() {
        	var nbImg = jQuery(this).attr("id").substring(22).substring(jQuery(this).attr("id").substring(22).indexOf('-')+1);
        	var pdt = jQuery(this).attr("id").substring(22).substring(0, jQuery(this).attr("id").substring(22).indexOf('-'));

			if (jQuery(this).css("display") == 'block' && pdt != oldPdt) {
            	jQuery(this).css("display", "none");
            	el = document.getElementById("img-collection-grande-"+pdt+"-"+(parseInt(nbImg)+1));
            	if (el != null) {
	            	jQuery("#img-collection-grande-"+pdt+"-"+(parseInt(nbImg)+1)).css("display", "block");
				} else {
            		jQuery("#img-collection-grande-"+pdt+"-0").css("display", "block");
				}
				oldPdt = pdt;
			} 
        });
        
        // push home
        var oldPdt = null;
        jQuery('.photo_product_gallery_push_home').each(function() {
        	var nbImg = jQuery(this).attr("id").substring(18).substring(jQuery(this).attr("id").substring(18).indexOf('-')+1);
        	var pdt = jQuery(this).attr("id").substring(18).substring(0, jQuery(this).attr("id").substring(18).indexOf('-'));
            //alert(jQuery(this).attr("id").substring(18)+' | '+jQuery(this).attr("id") + ' | ' +nbImg +' | '+pdt+'#'+jQuery(this).attr("id"));
			if (jQuery(this).css("display") == 'block' && pdt != oldPdt) {
            	jQuery(this).css("display", "none");
            	el = document.getElementById("gallery-push-home-"+pdt+"-"+(parseInt(nbImg)+1));
            	if (el != null) {
	            	jQuery("#gallery-push-home-"+pdt+"-"+(parseInt(nbImg)+1)).css("display", "block");
				} else {
            		jQuery("#gallery-push-home-"+pdt+"-0").css("display", "block");
				}
				oldPdt = pdt;
			} 
        });

        //push home popup-grande-X-Y
        var oldPdt = null;
        jQuery('.photo_product_gallery_push_home_popup').each(function() {
        	var nbImg = jQuery(this).attr("id").substring(32).substring(jQuery(this).attr("id").substring(32).indexOf('-')+1);
        	var pdt = jQuery(this).attr("id").substring(32).substring(0, jQuery(this).attr("id").substring(32).indexOf('-'));

			if (jQuery(this).css("display") == 'block' && pdt != oldPdt) {
            	jQuery(this).css("display", "none");
            	el = document.getElementById("img-collection-grande-push-home-"+pdt+"-"+(parseInt(nbImg)+1));
            	if (el != null) {
	            	jQuery("#img-collection-grande-push-home-"+pdt+"-"+(parseInt(nbImg)+1)).css("display", "block");
				} else {
            		jQuery("#img-collection-grande-push-home-"+pdt+"-0").css("display", "block");
				}
				oldPdt = pdt;
			} 
        });
        
        
	}); 
    
    
    if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)<7) {
        var taille = document.body.scrollHeight;
        taille = taille - 1214;
        jQuery(".header-container").css("margin-top", "-"+taille+"px");
    }

	

	
});
