jQuery(function($){
	
	$(document).ready(function() {
		
		$(".block-custom-options.rv a").fancybox({
			'width'				: '711',
			'height'			: '620',
			'padding'           : '30',
			'autoScale'     	: false,
			'autoDimensions'    : false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'href'				: 'http://www.prodottiunicef.it/skin/frontend/unicef/default/html/rplv-modal.html',
			'overlayColor'      : '#00c1ff'
		});

		$(".block.rpv a").fancybox({
			'width'				: '711',
			'height'			: '620',
			'padding'           : '30',
			'autoScale'     	: false,
			'autoDimensions'    : false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'href'				: 'http://www.prodottiunicef.it/skin/frontend/unicef/default/html/rplv-modal.html',
			'overlayColor'      : '#00c1ff'
		});
		
		$(".block-custom-options.sv a").fancybox({
			'width'				: '711',
			'height'			: '650',
			'padding'           : '30',
			'autoScale'     	: false,
			'autoDimensions'    : false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'href'				: 'http://www.prodottiunicef.it/skin/frontend/unicef/default/html/san-val.html',
			'overlayColor'      : '#00c1ff'
		});

		$(".link_ecard").fancybox({
			'width'				: '711',
			'height'			: '650',
			'overlayColor'      : '#00c1ff'
		});
		
		if($.cookie("cart-state")=='open'){	
			$('.bottom-cart-close-wrapper').css('bottom', '0');
			$('.bottom-cart-aux').css('bottom', '-112px');
			$('.bottom-cart-close p').addClass('open');
			$('.bottom-cart-close p').text('Apri anteprima carrello');
			$('.bottom-cart-wrapper').css('height', 'auto');
		};
		
		$('.bottom-cart-close p').live('click', function(e) {
			e.preventDefault();
			if ($(this).attr('class') == 'open') {
				$('.bottom-cart-close p').removeClass('open');
				$('.bottom-cart-close p').text('Chiudi anteprima carrello');
				$.cookie("cart-state","closed");
				$('.bottom-cart-close-wrapper').stop().animate({
					bottom: '112px'
				}, 300, function(){
					$('.bottom-cart-wrapper').css('height', '130px');
				});
				$('.bottom-cart-aux').stop().animate({
					bottom: '0'
				}, 300);
			} else {
				$('.bottom-cart-close p').addClass('open');
				$('.bottom-cart-close p').text('Apri anteprima carrello');
				$.cookie("cart-state","open");
				$('.bottom-cart-close-wrapper').stop().animate({
					bottom: '0'
				}, 300, function(){
					$('.bottom-cart-wrapper').css('height', 'auto');
				});
				$('.bottom-cart-aux').stop().animate({
					bottom: '-112px'
				}, 300);
			};
		});
		
		/*
		if($.cookie("privatipopup")!='enter' && $('#notice-link').length)
			{	
			$.cookie("privatipopup","enter");
			$("#notice-link").fancybox({
				'width'				: '480',
				'height'			: '300',
				'padding'           : '30',
				'autoScale'     	: false,
				'autoDimensions'    : false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'href'				: 'http://www.prodottiunicef.it/skin/frontend/unicef/default/html/notice_privati.html',
				'overlayColor'      : '#00c1ff'

			}).trigger('click');
			}
         
		
		if($.cookie("aziendepopup")!='enter' && $('#notice-link-aziende').length)
			{	
			$.cookie("aziendepopup","enter");
			$("#notice-link-aziende").fancybox({
				'width'				: '480',
				'height'			: '300',
				'padding'           : '30',
				'autoScale'     	: false,
				'autoDimensions'    : false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'href'				: 'http://www.prodottiunicef.it/skin/frontend/unicef/default/html/notice_aziende.html',
				'overlayColor'      : '#00c1ff'

			}).trigger('click');
			}
		*/
		// FB LIKE
		window.fbAsyncInit = function() {
			FB.init({ apiKey: FB_API_KEY, status: true, cookie: true, xfbml: true});
		};
	    
		(function() {
			var e = document.createElement('script');
	        e.type = 'text/javascript';
	        e.src = document.location.protocol +
	          '//connect.facebook.net/it_IT/all.js#xfbml=1';
	        e.async = true;
	        document.getElementById('fb-root').appendChild(e);
		}());
		// END FBLIKE
		
		$('.cms .jqzoom').jqzoom({
			zoomType: 'standard',
			lens:true,
			preloadImages: false,
			alwaysOn:false
		});
		
		if ($('.cms-supporto-donatori, .cms-supporto-aziende').length) {
			
			$('.col-right.sidebar').append('<div class="block block-anchors"><div class="block-title"><strong>Indice</strong></div><div class="block-content"><ul></ul></div></div>');
			
			$(window).scroll(function(e){ 
				$el = $('.block-anchors'); 
				if ($(this).scrollTop() > 189 && $el.css('position') != 'fixed'){ 
					$('.block-anchors').css({'position': 'fixed', 'top': '0'}); 
				} else if ($(this).scrollTop() < 189){
					$('.block-anchors').css({'position': 'absolute', 'top': '189px'}); 
				}
			});
			
			$('.cms h2').each(function(index) {
				var title = $(this).text();
				$(this).attr('id', 'anchor'+index);
				$('.block-anchors ul').append('<li><a href="#anchor'+index+'">'+title+'</a></li>');
			});
			
			$('.block-anchors a').live('click', function(e) {
				e.preventDefault();
				$(this).parent().siblings().children('a').removeClass('active');
				$(this).addClass('active');
				var el = $(this).attr('href');
				$('html,body').animate({
					scrollTop: $(el).offset().top
				}, 400);
			});
		};
		
		// Se l'elemento corrente è visibile allora è obbligatorio
		$.validator.addMethod("requiredVisible", function(value, element) {
			if ($(element).is(':visible')) {
				return (value !== '0' && value !== 'null' && !this.optional(element));
			}
			return "dependency-mismatch";
		}, $.validator.messages.required);
		
		$.validator.addMethod("required-entry", function(value, element) {
			if ($(element).is(':visible')) {
				return (value !== '0' && value !== 'null' && !this.optional(element));
			}
			return "dependency-mismatch";
		}, $.validator.messages.required);
		
		if ($('.slideshow-category ul li').size() >= 2) {
			$('.slideshow-category ul').cycle({
			    pause: true,
				fx: 'fade',
				speed: 1900,
				pager:  '#slideshow-pager'
			});
		}
		
		if ($('.category-products.natale .products-grid').length) {
			$('.category-products.natale .products-grid li')
				.mouseover(function(){
					$(this).children('.content').children('.continue').children('span').stop().animate({
						backgroundColor: '#A20318',
						marginLeft: '15px'
					}, 150, 'easeOutQuad');
				})
				.mouseout(function(){
					$(this).children('.content').children('.continue').children('span').stop().animate({
						backgroundColor: '#DA001F',
						marginLeft: '0'
					}, 150, 'easeOutQuad');
				})
		};
		
		$('.other-info a')
			.mouseover(function(){
				$(this).children('.hover').stop().animate({
					opacity: '1'
				}, 400, 'easeOutQuad');
			})
			.mouseout(function(){
				$(this).children('.hover').stop().animate({
					opacity: '0'
				}, 400, 'easeOutQuad');
			})
		
		if ($('.other-info').length) {
			$('.other-info ul li a').each(function(index, value) {
				$('<div class="hover"></div>').appendTo(value);
			});
			$('.other-info .hover').animate({ opacity: '0'}, 0);
			$('.other-info a')
				.mouseover(function(){
					$(this).children('.hover').stop().animate({
						opacity: '1'
					}, 400, 'easeOutQuad');
				})
				.mouseout(function(){
					$(this).children('.hover').stop().animate({
						opacity: '0'
					}, 400, 'easeOutQuad');
				})
		};
		
		if ($('.category-products.pigotte .products-grid').length) {
			$('.category-products.pigotte .products-grid li')
				.mouseover(function(){
					$(this).children('.product-image').children('img').stop().animate({
						right: '-20px'
					}, 200, 'easeOutQuad');
				})
				.mouseout(function(){
					$(this).children('.product-image').children('img').stop().animate({
						right: '-60px'
					}, 200, 'easeOutQuad');
				})
		};
		
		if ($('.homepage .nav-container .tooltip').length) {
			$(".homepage #nav li a").hover(
				function () {
					var num = $(this).parent().index()+1;
					$('.nav-container .tooltip .link_'+num).fadeIn(80);
				},
				function () {
					var num = $(this).parent().index()+1;
					$('.nav-container .tooltip .link_'+num).fadeOut(80);
				}
			);
		};
		
		if ($('.aziende-store.cms-home .nav-container .tooltip').length) {
			$("#nav li a").hover(
				function () {
					var num = $(this).parent().index()+1;
					$('.nav-container .tooltip .link_'+num).fadeIn(80);
				},
				function () {
					var num = $(this).parent().index()+1;
					$('.nav-container .tooltip .link_'+num).fadeOut(80);
				}
			);
		};

		$(".overlay dd select").msDropDown().data("dd");
		
		$(".product-view .options-content-info").hover(
			function () {
				$('.product-view .options-content').fadeIn(80);
			},
			function () {
				$('.product-view .options-content').fadeOut(80);
			}
		);
		
		updateCart();
		
		//initAddAjaxToCart();
		
		$('.products-list .product-link').animate({
			opacity: 0
		}, 0);
		
		$('.products-list .view').animate({
			opacity: 0.13
		}, 0);
		
		$(".products-list li").hover(
			function () {
				$('.product-link', this).animate({
					opacity: 1
				}, 300, 'easeOutQuad');
			},
			function () {
				$('.product-link', this).animate({
					opacity: 0
				}, 300, 'easeOutQuad');
			}
		);
		
		$('.category-products.default li').each(function(index, value) { 
			var listHeight = $(value).height()+38;
			$(value).children('.product-link').css('height', listHeight);
			$(value).children('.product-link').children('.view').css('height', listHeight);
		});
		
		$('.category-products.default .product-link').animate({
			opacity: 0
		}, 0);
		
		$('.category-products.default .view').animate({
			opacity: 0.13
		}, 0);
		
		$('.category-products.default li')
			.mouseover(function(){
				$(this).children('.product-link').stop().animate({
					opacity: '1'
				}, 300, 'easeOutQuad');
			})
			.mouseout(function(){
				$(this).children('.product-link').stop().animate({
					opacity: '0'
				}, 300, 'easeOutQuad');
			})
		
		$('#comment-area .continue a').live('click', function(e) {
			e.preventDefault();
			if ($('#comment-area .hidden').size() == 0) {
				$('#comment-area .continue a').text('tutti i commenti sono visibili');
			};
			$('#comment-area .hidden').slice(0,10).fadeIn('200').removeClass('hidden');
		});
		
		$('.category-products.aziende li')
			.mouseover(function(){
				$(this).children('.product-image').children('img').stop().animate({
					width: '255px',
					height: '278px',
					marginLeft: '-15px',
					marginTop: '-15px'
				}, 200, 'easeOutQuad');
				$(this).children('.product-name').stop().animate({
					paddingLeft: '40px'
				}, 200, 'easeOutQuad');
			})
			.mouseout(function(){
				$(this).children('.product-image').children('img').stop().animate({
					width: '225px',
					height: '248px',
					marginLeft: '0px',
					marginTop: '0px'
				}, 200, 'easeOutQuad');
				$(this).children('.product-name').stop().animate({
					paddingLeft: '20px'
				}, 200, 'easeOutQuad');
			})
		
		$('.block-custom-options ul').carouFredSel({
			scroll: {
				items: 1,
				fx: 'slide',
				duration : 400,
				pauseOnHover : 'true'
			},
			auto: true
		});

		$('.product-view #move-to-options').live('click', function(e) {
			e.preventDefault();
			$('html,body').animate({
				scrollTop: $("#product-options-wrapper").offset().top
			}, 1200);
		});
		
		$('.more-views li:first-child a').addClass('active');
		$('.more-views a').removeAttr("onclick");
		$('.more-views a').live('click', function(e) {
			e.preventDefault();
			var image = $(this).attr('href');
			var link = $(this).attr('rel');
			if ($(this).attr('class') == 'active') {
			} else {
				$(this).parent().siblings().children('a').removeClass('active');
				$(this).addClass('active');
				$('#image').attr('src', image);
				$('#image').parent('a').attr('href', link);
				if ($('.product-image-zoom a').width() == '512'){
					$('.product-image-zoom .large').attr('src', link);
				} else {
					
				}
			};
		});
		
		if ($('.product-image-zoom a').length) {
			$('.magnify', this).stop().animate({
				opacity: '0'
			}, 0);
		};
		
		$('.product-image-zoom a')
			.mouseover(function(){
				$('.magnify', this).stop().animate({
					opacity: '1'
				}, 400, 'easeOutQuad');
			})
			.mouseout(function(){
				$('.magnify', this).stop().animate({
					opacity: '0'
				}, 400, 'easeOutQuad');
			})

		$('.product-image-zoom a').live('click', function(e) {
			e.preventDefault();
			if ($(this).width() == '512') {
				$('.close').remove();
				$('.product-image-zoom .large').fadeOut(300, function(){
					$('.product-image-zoom .large').remove();
					$('.product-image').animate({
						width: '229px',
						height: '229px',
						marginTop: '0'
					}, 300);
					$('.product-image a').animate({
						width: '229px'
					}, 300);
					$('#image').animate({
						width: '229px'
					}, 300, function(){
						$('.product-image-zoom .magnify').removeClass('hidden').animate({opacity: '0'}, 0);
					});
				});
			} else {
				$('.product-image-zoom .magnify').addClass('hidden');
				var image = $(this).attr('href');
				$(this).parent('.product-image').animate({
					width: '518px',
					height: '518px',
					marginTop: '-50px'
				}, 300);
				$(this).animate({
					width: '512px'
				}, 300);
				$(this).children('img').animate({
					width: '512px'
				}, 300, function(){
					$('<span class="close">chiudi zoom</span>').appendTo('.product-image a');
					$.preload(image, {
						onFinish: showImage(image),
						threshold: 1
					});
				});
			};
		});
		
		if ($('.alert-message-wrapper').length) {
			setTimeout(function(){
				$('.alert-message-wrapper').fadeIn(300).delay(4000).fadeOut(300);
			}, 800);
		};

		if ($('.cart .messages li').length) {
			fadeMessages('.cart .messages');
		};

		$(".other-1 a, .other-2 a").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'padding'           : '30',
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'overlayColor'      : '#00c1ff'
		});
        
		$(".testobomboniere").fancybox({
			'autoDimensions'    : false,
			'width'				: '100px',
			'padding'           : '30',
			'autoScale'     	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
	  		'overlayColor'      : '#00c1ff'
		});


		$('#avatarList li').live('click', function(e) {
			e.preventDefault();
			$(this).addClass("active");
			$(this).siblings().removeClass("active");
			$(this).children('input').attr('checked', 'checked');
		});
		
		$('.cart-layout .checkout-types .btn-update').click(function(e) {
			e.preventDefault();
			$('.updade-form').submit();
		});
		
		$.preload( '.slide-1 a img', {
			onFinish: view(1),
			threshold: 1
		});
	
		function view(slide){
			$('.slide-'+slide).fadeIn(300, function(){
				$('.slide-'+slide).carouFredSel({
					scroll: 1,
					auto: false,
					prev: '.products-prev',
					next: '.products-next'
				});			
			});
		};
		
		if ($('#products-list-container').length) {
			$('#products-list-container').append('<div id="subtitle"><h3></h3></div>');
		};
		
		$('.products-categories > li > a').live('click', function(e) {
			e.preventDefault();
			if ($(this).attr('href') != '') {
				if ($(this).parent().attr('class') != 'selected') {
					$(this).parent().siblings('li').removeClass('selected');
					$(this).parent().siblings('li').children('ul').children('li').removeClass('active');
					$(this).parent().addClass('selected');
					$("#subtitle h3").html('');
					var slide = $(this).attr('class');
					var link = $(this).attr('href');
					$('.products-slide .view-all p a').attr('href', link);
					slide = slide.substr(1);
					$('#products-list-container .caroufredsel_wrapper').fadeOut(300, function(){
						$.preload( '.slide-'+slide+' a img', {
							onFinish: view(slide),
							threshold: 1
						});
					});
				};
			};
		});
		
		$('.products-categories > li > ul a').live('click', function(e) {
			e.preventDefault();
			if ($(this).attr('href') != '') {
				if ($(this).parent().attr('class') != 'selected') {
					$(this).parent().parent().parent().siblings('li').removeClass('selected');
					$(this).parent().parent().parent().addClass('selected');
					$(this).parent().siblings('li').removeClass('active');
					$(this).parent().addClass('active');
					var title = $(this).text();
					$("#subtitle h3").html('<span>'+title+'</span>');
					var slide = $(this).attr('class');
					var link = $(this).attr('href');
					$('.products-slide .view-all p a').attr('href', link);
					slide = slide.substr(1);
					$('#products-list-container .caroufredsel_wrapper').fadeOut(300, function(){
						$.preload( '.slide-'+slide+' a img', {
							onFinish: view(slide),
							threshold: 1
						});
					});
				};
			};
		});
		
		
	
		
		
		if ($('#slideshow ul li').size() >= 2) {
			$('#slideshow ul').cycle({
			    pause: true,
				fx: 'fade',
				speed: 1500,
				pager:  '#slideshow-pager'
			});
		};
		
		$('#home-slideshow ul').cycle({
		    pause: true,
			fx: 'fade',
			speed: 1500,
			next: '#home-next',
			pager:  '#home-slideshow-pager'
		});
		
		$('.block-banner a, .social-networks a')
			.mouseover(function(){
				$("img", this).stop().animate({
					opacity: 0.6
				}, 200);
			})
			.mouseout(function(){
				$("img", this).stop().animate({
					opacity: 1
				}, 200);
			})
			
		$('.main-search #search').focus(function () {
			if (this.value == 'cerca nel sito') {this.value = '';}
		});

		$('.main-search #search').blur(function () {
			if (this.value == '') {this.value = 'cerca nel sito';}
		});

		$('.category-products.subcategory .product-link')
			.mouseover(function(){
				$(this).siblings('.product-image').children('img').stop().animate({
					right: '0'
				}, 200, 'easeOutQuad');
				$(this).siblings('.product-name').children('a').stop().animate({
					backgroundColor: '#538B16'
				}, 200);
			})
			.mouseout(function(){
				$(this).siblings('.product-image').children('img').stop().animate({
					right: '-20px'
				}, 200, 'easeOutQuad');
				$(this).siblings('.product-name').children('a').stop().animate({
					backgroundColor: '#7AB732'
				}, 200);
			})
			
		$('.block-recommended a')
			.mouseover(function(){
				$("img", this).stop().animate({
					opacity: '0.5'
				}, 300, 'easeOutQuad');
			})
			.mouseout(function(){
				$("img", this).stop().animate({
					opacity: '1'
				}, 300, 'easeOutQuad');
			});
		
		if ($('#bottom-cart-carousel ul li').size() > 6) {
			jQuery("#bottom-cart-carousel ul").removeClass('noCarousel');
		} else {
			jQuery("#bottom-cart-carousel ul").addClass('noCarousel');
		};
		
		if($('.bottom-cart-wrapper').hasClass('hidden')) {
			$('.footer').removeClass('footer-cart');
		} else {
			$('.footer').addClass('footer-cart');
		}
		
	});
		
	function showImage(image){
		$('<img class="large" src="'+image+'" />"').appendTo('.product-image a').fadeIn(300);
	}

	/*function initAddAjaxToCart() {
		
		if(jQuery('#product_addtocart_form').length > 0) {
			
			// Aggiungo evento ajax su bottone
			addForm = jQuery('#product_addtocart_form');
			if(addForm.find('button.btn-cart').length > 0) {
				
				addButton = addForm.find('button.btn-cart');
				addButton.attr('onclick', '');
				addButton.click(function(){
					ajaxAddToCart('product_addtocart_form');
				});
			}		
		}
		
	}*/
	
    jQuery('.bubbleInfo').each(function () {
        var distance = 10;
        var time = 250;
        var hideDelay = 500;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = jQuery('#weddingRegistryLink');
        var info = jQuery('.popup', this).css('opacity', 0);
        var main = jQuery('#webtexweddingregistrybox');


        jQuery([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                return;
            } else {
                beingShown = true;

                main.css('display', 'block');

                info.css({
                    top: 0,
                    left: -33,
                    display: 'block'
                }).animate({
                    top: '+=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });


});

function updateCart(){
	if (jQuery('#bottom-cart-carousel ul li').size() > 6) {
		jQuery("#bottom-cart-carousel ul").removeClass('noCarousel');
		jQuery("#bottom-cart-carousel ul").carouFredSel({
			circular: false,
			infinite: false,
			width: 588,
			align: "left",
			items: {
				visible: 6,
				minimum: 1
			},
			scroll: {
				items: 1,
				easing: "linear"
			},
			auto: false,
			prev : {	
				button	: "#bottom_prev",
				key		: "left"
			},
			next : { 
				button	: "#bottom_next",
				key		: "right"
			}
		});
	} else {
		jQuery("#bottom-cart-carousel ul").addClass('noCarousel');
		jQuery('#bottom_prev, #bottom_next').addClass('disabled');
		
	};
};

function loadCart(){
	jQuery("#bottom-cart-container").fadeOut(300, function(){
		jQuery(".bottom-cart").addClass('loading');
	})
};

function showCart(){
	jQuery(".bottom-cart").removeClass('loading');
	jQuery("#bottom-cart-container").fadeIn();
};

function ajaxAddToCart(formid) {
	
	// Valido secondo lo standard Magento
	var validateAddToCartForm = new VarienForm(formid);
	if(validateAddToCartForm.validator.validate()) {
		
		// Submit form via ajax
		form = jQuery('#' + formid);
		formAction = form.attr('action');
		formAction = formAction.replace('/add/', '/addAjax/');
		formAction = formAction.replace('/updateItemOptions/', '/updateItemOptionsAjax/');
		
		// Mostro loader
		if(jQuery('div.bottom-cart-wrapper').hasClass('hidden')) {
			jQuery('div.bottom-cart-wrapper').removeClass('hidden');
			jQuery('.footer').removeClass('footer-cart');
		}
		
		loadCart();
		jQuery.post(formAction, form.serialize(), function(data){
			
			// Sostituisco carrello bottom
			result = jQuery(data);
			newCart = result.find('div.bottom-cart-wrapper');
			messageCart = result.find('div.alert-message-wrapper');
			
			// Aggiungo messaggi
			if(jQuery('#messages_product_view').length > 0 && messageCart.find('li').length) {
				jQuery('#messages_product_view').html('');
				jQuery('#messages_product_view').append(messageCart);
				fadeMessages('.alert-message-wrapper');
			}				
			
			// Setto nuovo HTML
			jQuery('div.bottom-cart-wrapper').html(newCart.html());
			
			if(jQuery('div.bottom-cart-wrapper').find('li').length > 0) {
				
				// Aggiorno qta in top-link-cart
				qty = jQuery('div.bottom-cart-wrapper').find('p.bottom-cart-info span.qty strong')
				if(qty.length > 0) {
					qtyCart = qty.text();
					
					topLinkCartText = jQuery('a.top-link-cart').text();
					topLinkCartText = topLinkCartText.substr(0, topLinkCartText.indexOf("("));
					topLinkCartText += '(' + qtyCart + ')';
						
					jQuery('a.top-link-cart').text(topLinkCartText);
				}
				
			} else {
				if(!jQuery('div.bottom-cart-wrapper').hasClass('hidden')) {
					jQuery('div.bottom-cart-wrapper').addClass('hidden');
					jQuery('.footer').addClass('footer-cart');
				}
			}
							
			// Reiniti carousel
			updateCart();
			showCart();
	});
	} else {
		
		if(jQuery('.product-options-bomboniera').length > 0) {
			jQuery.scrollTo('.product-options-bomboniera', 800);
		}
		
	}
	
	return false;
	
}

function fadeMessages(messages){
	setTimeout(function(){
		jQuery(messages).fadeIn(300).delay(4000).fadeOut(300);
	}, 800);
}

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : cookie_encode(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

function cookie_encode(string){
	//full uri decode not only to encode ",; =" but to save uicode charaters
	var decoded = encodeURIComponent(string);
	//encod back common and allowed charaters {}:"#[] to save space and make the cookies more human readable
	var ns = decoded.replace(/(%7B|%7D|%3A|%22|%23|%5B|%5D)/g,function(charater){return decodeURIComponent(charater);});
	return ns;
}

