function activarZoom() {
	//Activar el fancyzoom sobre los a con class jszoom. Especial para productos.
	$('a.jszoom_producto').fancybox({
		'hideOnContentClick': false,
		'overlayShow': false,
		'titlePosition' : 'over',
		'padding': 1,
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
			var html = '';
			if (title != '') {
				var title_array = title.split('||');
				
				if (title_array[2] == '1') {
					html += '<span id="fancybox-title-over"><a id="product_title_popup" href="' + title_array[1] + '">' + title_array[0] + '</a></span>';
					html += '<span class="fancybox_cart_icon"><a href="' + title_array[1] + '"><img src="html/images/carrito_jszoom.png" /></a></span>';
				}
				else {
					html += '<span id="fancybox-title-over"><span id="product_title_popup">' + title_array[0] + '</span></span>';
				}
			}
			return html;
		},
		'onComplete':function(currentArray,currentIndex,currentOpts){
            var src = $('#fancybox-img').attr('src')
			var src_array = src.split('&');
			var src_new = src_array[0];
			
			var content = $('#fancybox-content').html();
			var new_content = '<a id="single_image_zoom" title="' + $('#product_title_popup').html() + '" rel="galeria_single" href="' + src_new + '&w=682&.jpg">' + content + '</a>';
			$('#fancybox-content').html(new_content);
			
			var options = {
	            zoomType: 'standard',
	            lens:true,
	            preloadImages: true,
	            alwaysOn:false,
	            preloadText:$('body').data('preloadtext')
	        };
			$('#single_image_zoom').jqzoom(options);
        }
	});
	
	//Activar el fancyzoom sobre los a con class jszoom
	$('a.jszoom').fancybox({
		'hideOnContentClick': false,
		'titlePosition' : 'over',
		'overlayShow': false,
		'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Imagen ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$('a.jszoomgaleria').fancybox({
		'hideOnContentClick': true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition' : 'over',
		'overlayShow': false,
		'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Imagen ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$('a.jszoomslideshow').fancybox({
		'hideOnContentClick': true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition' : 'over',
		'cyclic'        : true, 
		'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Imagen ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		},
		'onComplete' : function() {
			var t = setTimeout(function() {
				clearTimeout(t);
				$.fancybox.next();
			}, 4000);
		}
	});
	
	
}

function sendAjax(button) {

	// Formulario
    var f = button.form;

    // Dirección de envío
    var url = 'form.sendAjax';

    // Deshabilitar el botón
	button.disabled = true;
	
	$.ajax({
		url: url,
		type: "POST",
		data: $(f).serialize(),
		success: function(msg){
			try {
				var data = jQuery.parseJSON(msg);
				var messages = data.messages;
				var errores = [];
				
				if (messages) {
					$.each(messages, function(key, val){
						$.each(val, function(key2, val2){
							if((key2=='isEmpty') || (key2=='emailAddressInvalidFormat') || (key2=='hostnameLocalNameNotAllowed') || (key2=='fileUploadErrorNoFile')) {
								errores.push('  - ' + val.title + ' - ' + $('body').data(key2));
							}
						});
					});
				}
				if (errores.length == 0) {
					alert($('body').data('form_ok'));
					f.reset();
				} else {
					alert('Por favor, compruebe los siguientes datos:\n\n' + errores.join('\n'));
				}
			} catch (e) {
				alert($('body').data('form_ko'));
			}
			button.disabled = false;
		},
		error: function(){
			alert($('body').data('form_ko'));
			button.disabled = false;
		}
	});

	// Cancelar el submit
	return false;
}

/**
 * Mover los productos de la portada
 */
function homeBottomSlider(to) {
    var bloque = $('#main_bloque_portada_images');
	var step = 981;

	var item = 0;
	if (bloque.attr('_current')) {
		item = parseInt(bloque.attr('_current'),10);
	}

	if (to == 'next') {
		item++;
	} else {
		item--;
	}
	var margin_new = item * step;

	if (item<0) {
		bloque.animate({'margin-left':'50px'}, {duration: 100, queue: false, complete: function() {
			bloque.animate({'margin-left':'0px'}, {duration: 500, easing: 'easeOutBounce', queue: false});
		}});
        return false;
	}else if (margin_new >= bloque.width()) {
		var bounce_start = ((item-1) * step) + 50;
		var bounce_end = bounce_start - 50; 
		bloque.animate({'margin-left': '-'+ bounce_start + 'px'}, {duration: 100, queue: false, complete: function() {
			bloque.animate({'margin-left': '-'+ bounce_end + 'px'}, {duration: 500, easing: 'easeOutBounce', queue: false});
		}});
        return false;
	}
	bloque.attr({'_current': item});
	bloque.animate({'margin-left': '-'+ margin_new + 'px'}, {duration: 2000, easing: 'easeInOutSine', queue: false});
}
