jQuery(document).ready(function() {
    /**
     *Jquery Filter solde 
     */
    //price
     jQuery('#filtre_solde select#pricefiltersolde').change(function() {
         window.location = jQuery(this).val();
     });
     //catégories
     jQuery('#filtre_solde select#catFilter').change(function() {
		/**Make the option selected**/
		jQuery(this).attr('selected', 'selected');
		var filterVal = jQuery(this).val();	
		if(filterVal == 'all') {
			jQuery('ul.products-grid li.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			
			jQuery('ul.products-grid li').each(function() {
				if(!jQuery(this).hasClass(filterVal)) {
					jQuery(this).fadeOut('normal').addClass('hidden');
				} else {
					jQuery(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		
		return false;
	});
    /** end Filter solde**/ 
    jQuery("li.nav-2-1 a span").css({
        "color":"#D43451",
        "font-weight":"bold"
    });
    //click function menu left
    jQuery('#special_send').click(function() {
			  
        jQuery('#my_form').submit();	
					
			 
    });
		  
    jQuery("a.nav-show").click(function() {
        // note: do this first because the :hidden test fails if you
        // do it after triggering a slow animation
        jQuery(this).toggleClass("active").next().slideToggle("fast");
        return false; //Prevent the browser jump to the link anchor
    //jQuery("#id_cat37").toggle('fast');
    });
	  
    //form color
    jQuery('.pictolist a').click(function() {
        var idcolor = jQuery(this).attr('rel');
        var url_product = jQuery(this).parents('.listing_item').children('.imageprinproduct').attr('href');
        //appendform
        jQuery('input#color_value').val(idcolor);
        jQuery("#form_color").attr("action", url_product);
        jQuery("#form_color").submit();
			
        return false;										
    });
    jQuery('li.active').parent('ul.level0').show();
    //info bulle
    //info bulle
    jQuery(function() {
        jQuery('.infobulle,#qte_moin,#qte_plus').tipsy({
            gravity: 's',
            html: true
        });
    });
    jQuery('#hide_0').empty();
    jQuery('.col-left .dropcartea').remove();
    jQuery('.col-left .drop_cart').remove();
    jQuery('#hide_0').append('<strong>Mon compte</strong>');
    jQuery(function() {
        jQuery('#qte_moin,#qte_plus','.infobulle').tipsy({
            gravity: 's'
        });
    });
    jQuery('#country option:eq(0)').attr('selected', 'selected');
    jQuery('#country option:eq(0)').html('Choisissez votre destination');
    jQuery('#attribute949 option:eq(0)').html('Choisissez votre taille');
    jQuery('#qty').val('1');    
    jQuery('.qty').attr('readonly'); 
    //incrémente Qte
    jQuery('.qte_increment').click(function() {
        if(jQuery(this).attr('id') == 'qte_plus'){
            var newQty = +(jQuery(this).prev(".qty").val()) + 1; 
            jQuery(this).prev(".qty").val(newQty);
            jQuery('.drop_cart').show(); 
            jQuery('#form_panier').submit();
        }else{
            var newQty = +(jQuery(this).next(".qty").val()) - 1; 
            if(newQty < 0){
                newQty = 0;
                return false;
            }
            jQuery(this).next(".qty").val(newQty);
            jQuery('#form_panier').submit(); 
        }
    //alert('Handler for .click() called.'); 
    });
    //mondal
    //select all the a tag with name equal to modal
    function nl2br (str, is_xhtml) {   
        var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';    
        return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
    }
    jQuery('.btnshow').click(function(e) {
										
        var texte = nl2br(jQuery('#input_liste_cadeau').val());	
        if(texte == "") return false;
        jQuery('.settexte').empty();
        jQuery('.settexte').append(texte);
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = "#prev_message_soec";
	
        //Get the screen height and width
        var maskHeight = jQuery(document).height();
        var maskWidth = jQuery(window).width();
	
        //Set heigth and width to mask to fill up the whole screen
        jQuery('#mask').css({
            'width':maskWidth,
            'height':maskHeight
        });
		
        //transition effect		
        jQuery('#mask').fadeIn(1000);	
        jQuery('#mask').fadeTo("slow",0.8);	
	
        //Get the window height and width
        var winH = jQuery(window).height();
        var winW = jQuery(window).width();
              
        //Set the popup window to center
        jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
        jQuery(id).css('left', (winW/2-jQuery(id).width()/2)/1.5);
	
        //transition effect
        jQuery(id).fadeIn(2000); 
        jQuery('html, body').animate({
            scrollTop:120
        }, 'slow');
	
    });
    jQuery('a[name=modal]').click(function(e) {
													
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = jQuery(this).attr('href');
	
        //Get the screen height and width
        var maskHeight = jQuery(document).height();
        var maskWidth = jQuery(window).width();
	
        //Set heigth and width to mask to fill up the whole screen
        jQuery('#mask').css({
            'width':maskWidth,
            'height':maskHeight
        });
		
        //transition effect		
        jQuery('#mask').fadeIn(1000);	
        jQuery('#mask').fadeTo("slow",0.8);	
	
        //Get the window height and width
        var winH = jQuery(window).height();
        var winW = jQuery(window).width();
              
        //Set the popup window to center
        jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
        jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
        //transition effect
        jQuery(id).fadeIn(2000); 
        jQuery('html, body').animate({
            scrollTop:20
        }, 'slow');
	
    });
	
    //if close button is clicked
    jQuery('.window .closit').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
		
        jQuery('#mask').hide();
        jQuery('.window').hide();
    });		
	
    //if mask is clicked
    jQuery('#mask').click(function () {
        jQuery(this).hide();
        jQuery('.window').hide();
    });	
    //Change select Color call Ajax
    jQuery('select#attribute272').change(function() {
        var color_id = jQuery('select#attribute272').val();
        runajax(color_id);
    });
});
 
function runajax(color_id) {
    var product_id = jQuery('input#product_id_fix').val();
    //alert(product_id);
    jQuery.ajax({
        type: "GET",
        url: "http://www.1et1font3.com/Magentocreation-Imageswitch/index/index/prod_id/"+product_id+"/color_id/"+color_id,            
        beforeSend: function( xhr ) {
            jQuery('#product_media_content').empty();
            jQuery('#product_media_content').addClass('loading');
        },
        success: function(data) {
            jQuery('#attribute947 option:eq(0)').html('Choisissez votre taille ');
            jQuery('#product_media_content').empty();
            jQuery('#product_media_content').append(data);
            jQuery('#product_media_content').removeClass('loading');
				 
            setTimeout(MagicZoom.refresh,500);
        //opConfig.reloadPrice();
        //alert(data);
        }
    });
}
function monadl(){
    //Cancel the link behavior
    //e.preventDefault();
    //Get the A tag
    var id = "dialogtaille";
	
    //Get the screen height and width
    var maskHeight = jQuery(document).height();
    var maskWidth = jQuery(window).width();
	
    //Set heigth and width to mask to fill up the whole screen
    jQuery('#mask').css({
        'width':maskWidth,
        'height':maskHeight
    });
		
    //transition effect		
    jQuery('#mask').fadeIn(1000);	
    jQuery('#mask').fadeTo("slow",0.8);	
	
    //Get the window height and width
    var winH = jQuery(window).height();
    var winW = jQuery(window).width();
              
    //Set the popup window to center
    jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
    jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
    //transition effect
    jQuery(id).fadeIn(2000); 
    jQuery('html, body').animate({
        scrollTop:20
    }, 'slow');
	
		
	
}
function initCartDrop(){
    var duration = 350;
    var activeClass = 'active-cart';
    jQuery('ul.encart_content > li').each(function(){
        var holder = jQuery(this);
        var drop = jQuery('div.drop_cart',holder);
        if (drop.length) {
            var dropInner = jQuery('div.dropcart_container',drop);
            holder.mouseenter(function(){
                if (holder.hasClass(activeClass)) {
                    jQuery('div.dropcart_container').hide();
                    var h = dropInner.innerHeight();
                    dropInner.stop().animate({
                        marginTop:0
                    },duration);
                } else {
                    holder.addClass(activeClass);
                    jQuery('div.dropcart_container').show();
                    drop.css({
                        display:'block'
                    });
                    var h = dropInner.innerHeight();
                    dropInner.css({
                        marginTop:-h
                        }).stop().animate({
                        marginTop:0
                    },duration);
                }
            }).mouseleave(function(){
                var h = dropInner.innerHeight();
                dropInner.stop().animate({
                    marginTop:-h
                    },duration,function(){
                    drop.css({
                        display:'none'
                    });
                    holder.removeClass(activeClass);
                });
            });
        }
    });
}

;
(function($){

    $(function(){
        initCartDrop();
    });
})(jQuery);

