 var Site = {};
 Site.setup = function () {
    // scroll to top on request
    if (jQuery("a#totop").length) Site.scrollToTop("a#totop");

}
  // scrollToTop() - scroll window to the top
Site.scrollToTop = function (e) {
    jQuery(e).hide().removeAttr("href");
    if (jQuery(window).scrollTop() != "0") {
        jQuery(e).fadeIn("slow")
    }
    var scrollDiv = jQuery(e);
    jQuery(window).scroll(function () {
        if (jQuery(window).scrollTop() == "0") {
            jQuery(scrollDiv).fadeOut("slow")
        } else {
            jQuery(scrollDiv).fadeIn("slow")
        }
    });
    jQuery(e).click(function () {
        jQuery("html, body").animate({
            scrollTop: 0
        }, "slow")
    })
}
 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(".col-left div li").first().children('a').css({"color":"#D43451","font-weight":"bold"});
								 
								 
//slide home page
// Backwards navigation
/*	jQuery("#back").click(function() {
		stopAnimation();
		navigate("back");
	});
	
	// Forward navigation
	jQuery("#next").click(function() {
		stopAnimation();
		navigate("next");
	});
	
	var interval;
	jQuery("#control").toggle(function(){
		stopAnimation();
	}, function() {
		// Change the background image to "pause"
		jQuery(this).css({ "background-image" : "url(images/btn_pause.png)" });
		
		// Show the next image
		navigate("next");
		
		// Start playing the animation
		interval = setInterval(function() {
			navigate("next");
		}, slideshowSpeed);
	});
	
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {
		// Check if no animation is running. If it is, prevent the action
		if(animating) {
			return;
		}
		
		// Check which current image we need to show
		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
			}
		}
		
		// Check which container we need to use
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
		
	};
	
	var currentZindex = -1;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		
		// Make sure the new container is always on the background
		currentZindex--;
		
		// Set the background image of the new active container
		jQuery("#headerimg" + activeContainer).css({
			"background-image" : "url(" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		
		// Hide the header text
		jQuery("#headertxt").css({"display" : "none"});
		
		// Set the new header text
		jQuery("#firstline").html(photoObject.firstline);
		jQuery("#secondline")
			.attr("href", photoObject.url)
			.html(photoObject.secondline);
		jQuery("#pictureduri")
			.attr("href", photoObject.url)
			.html(photoObject.title);
		
		
		// Fade out the current container
		// and display the header text when animation is complete
		jQuery("#headerimg" + currentContainer).fadeOut(function() {
			setTimeout(function() {
				jQuery("#headertxt").css({"display" : "block"});
				animating = false;
			}, 500);
		});
	};
	
	var stopAnimation = function() {
		// Change the background image to "play"
		jQuery("#control").css({ "background-image" : "url(images/btn_play.png)" });
		
		// Clear the interval
		clearInterval(interval);
	};
	
	// We should statically set the first image
	navigate("next");
	
	// Start playing the animation
	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
*/
//**end slide home page**/
 // Site object setup
Site.setup();
  var text_description_one = jQuery('#mycarousel li').slice(0,1).children('span').slice(0,1).html(); 
  var src_images_one = jQuery('#mycarousel li').slice(0,1).children('img').attr('src') ;
  setpresse(text_description_one,src_images_one);
//presse
 jQuery('#mycarousel li').click(function() {
		var text_description = jQuery(this).children('span').slice(0,1).html(); 
		var src_images = jQuery(this).children('img').attr('src') ;
		//alert(text_description+'&nbsp;/'+src_images);
		setpresse(text_description,src_images)
		   
  });
  //click function menu left
		  jQuery('#special_send').click(function() {
			  
				   jQuery('#my_form').submit();	
					
			 
		 });
  
//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('#hide_0').empty();
	  jQuery('a.facebook').attr('title','Visitez notre page Facebook');
	  jQuery('.col-left .dropcartea').remove();
	  jQuery('.col-left .drop_cart').remove();
	 jQuery('#hide_0').append('<strong>Mon compte</strong>');
	 
//info bulle
	 jQuery(function() {
        jQuery('.infobulle,#qte_moin,#qte_plus').tipsy({gravity: 's',html: true });
	});
	  jQuery('#country option:eq(0)').attr('selected', 'selected');
	  jQuery('#country option:eq(0)').html('Choisissez votre destination');
	   jQuery('#attribute947 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');
	
	});
	  //mondal
	  //select all the a tag with name equal to modal
	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);
	});
	
	//set first selected
	//alert(jQuery('select##attribute272 option:eq(1)').val());
	//runajax(jQuery('select#attribute272 option:eq(1)').val());
});
 //for presse 
 function setpresse(text_description,src_images){
	 
	jQuery.ajax({
			type: "GET",
			url: "http://www.swildens.fr/ajax/presse.php?text_description="+text_description+"&src_images="+src_images,
			beforeSend: function( xhr ) {
             jQuery('.big_content_presse').empty();
			 jQuery('.big_content_presse').addClass('loading');
             },
			success: function(data) {
				 jQuery('.big_content_presse').empty();
				 jQuery('.big_content_presse').css("opacity","0.5");
				 jQuery('.big_content_presse').append(data);
				 jQuery('.big_content_presse img').load(function() {
				       jQuery('.big_content_presse').removeClass('loading');
					   jQuery('.big_content_presse').css("opacity","1");
				 });
				//opConfig.reloadPrice();
			//alert(data);
            }
      }); 
 }
function runajax(color_id) {
         var product_id = jQuery('input#product_id_fix').val();
        
	     jQuery.ajax({
			type: "GET",
			url: "http://www.swildens.fr/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('#product_media_content').empty();
				jQuery('#product_media_content').append(data);
				 jQuery('#product_media_content').removeClass('loading');
				 setTimeout(MagicZoom.refresh,500);
				//opConfig.reloadPrice();
			//alert(data);
            }
      });
		 //setTimeout(MagicZoom.refresh,500);
	 }


	 
function initCartDrop(){
	var duration = 350;
	var activeClass = 'active-cart';
	jQuery('.encart_content ul > 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);


(function(jQuery) {

    jQuery.organicTabs = function(el, options) {
    
        var base = this;
        base.jQueryel = jQuery(el);
        base.jQuerynav = base.jQueryel.find(".nav");
                
        base.init = function() {
        
            base.options = jQuery.extend({},jQuery.organicTabs.defaultOptions, options);
            
            // Accessible hiding fix
            jQuery(".hide").css({
                "position": "relative",
                "top": 0,
                "left": 0,
                "display": "none"
            }); 
            
            base.jQuerynav.delegate("li > a", "click", function() {
            
                // Figure out current list via CSS class
                var curList = base.jQueryel.find("a.current").attr("href").substring(1),
                
                // List moving to
                    jQuerynewList = jQuery(this),
                    
                // Figure out ID of new list
                    listID = jQuerynewList.attr("href").substring(1),
                
                // Set outer wrapper height to (static) height of current inner list
                    jQueryallListWrap = base.jQueryel.find(".list-wrap"),
                    curListHeight = jQueryallListWrap.height();
                jQueryallListWrap.height(curListHeight);
                                        
                if ((listID != curList) && ( base.jQueryel.find(":animated").length == 0)) {
                                            
                    // Fade out current list
                    base.jQueryel.find("#"+curList).fadeOut(base.options.speed, function() {
                        
                        // Fade in new list on callback
                        base.jQueryel.find("#"+listID).fadeIn(base.options.speed);
                        
                        // Adjust outer wrapper to fit new list snuggly
                        var newHeight = base.jQueryel.find("#"+listID).height();
                        jQueryallListWrap.animate({
                            height: newHeight
                        });
                        
                        // Remove highlighting - Add to just-clicked tab
                        base.jQueryel.find(".nav li a").removeClass("current");
                        jQuerynewList.addClass("current");
                            
                    });
                    
                }   
                
                // Don't behave like a regular link
                // Stop propegation and bubbling
                return false;
            });
            
        };
        base.init();
    };
    
    jQuery.organicTabs.defaultOptions = {
        "speed": 300
    };
    
    jQuery.fn.organicTabs = function(options) {
        return this.each(function() {
            (new jQuery.organicTabs(this, options));
        });
    };
    
})(jQuery);
