// JavaScript Document

jQuery(document).ready(function(){
	
	//next/prev prensa
	jQuery('.prev.noti').click(
		function()
		{
			jQuery('.boxplus-prev').click();
			return false;
		}
	);
	jQuery('.next.noti').click(
		function()
		{
			jQuery('.boxplus-next').click();
			return false;
		}
	);
	
	//deco imagenes prensa
	jQuery('.boxplus-slider a').wrap('<div class="cajita"/>');
	var nh = 0;
	jQuery('.cajita').each(
			function()
			{
				nh++;
				jQuery(this).prepend('<div class="numeracion">'+nh+'</div>');
				jQuery(this).append('<div class="selector"></div>');
			}
		);
	jQuery('.boxplus-viewport img').css('cssText', 'margin: 0px !important');
	
	//rotar etiqueta de tienda hindu
	jQuery('.moduletable_etiqueta a')
		.rotate({
			duration:6000,
			angle: 40, 
			animateTo:0
		});
	jQuery('.moduletable_etiqueta a')
		.hover(
			function()
			{
				jQuery(this).rotate({duration:2000, angle: 0, animateTo:10});
			},
			function()
			{
				jQuery(this).rotate({duration:2000, angle: 10, animateTo:0});
			}
		);
		
	//sub-menu productos
	jQuery('.sub-productos').detach().appendTo('.item2');
	jQuery(".item2").hover(
		function()
		{
			jQuery(this).find('.sub-productos').stop().fadeTo(200,1);
		},
		function()
		{
			jQuery(this).find('.sub-productos').stop().fadeOut(150);
		}
	);
	
	//btn next - prev productos detalle
	if(jQuery('.slide-productos > div').length < 2)
	{
		jQuery('.prev, .prev2, .next').detach();
	}
	jQuery('.prooductos-prev, .prooductos-next')
		.each(
			function()
			{
				var title = jQuery(this).attr('alt');
				jQuery(this).attr('title',title);
				jQuery(this).removeAttr('alt');
				
				if(jQuery('.pagenav_prev a').length == 0)
				{
					jQuery('.prooductos-prev').detach();
				}
				if(jQuery('.pagenav_next a').length == 0)
				{
					jQuery('.prooductos-next').detach();
				}
			}
		);
	jQuery('.prooductos-prev')
		.click(
			function()
			{
				if(jQuery('.pagenav_prev a').length > 0)
				{
					window.location = jQuery('.pagenav_prev a').attr('href');
				}
				return false;
			}
		);
	jQuery('.prooductos-next')
		.click(
			function()
			{
				if(jQuery('.pagenav_next a').length > 0)
				{
					window.location = jQuery('.pagenav_next a').attr('href');
				}
				return false;
			}
		);
	
	//sub-menu generico de menú principal
	jQuery('#menu ul.menu li.parent ul').prepend('<li class="selector"></li>');
	jQuery("#menu .parent").hover(		
		function()
		{
			var h = jQuery(this).find('ul').outerWidth();
			jQuery(this).find('ul')
			.fadeIn(200)
			.css({
						'left':'50%',
						'margin':'0 0 0 -'+(h/2)+'px'
					});
		},
		function()
		{
			jQuery(this).find('ul').fadeOut(150);
		}
	);
	
	//hover botonera (inferior - derecha)
	jQuery('.botonera ul').append('<li class="selector"></li>');
	jQuery(".botonera li").hover(
		function()
		{
			var h = jQuery(this).find('.submenu, .tooltip, #encuesta, .menu_lonuevo').outerWidth();
			jQuery(this).find('.submenu, .tooltip, #encuesta, .menu_lonuevo')
			.css({
						'left':'50%',
						'margin':'0 0 0 -'+(h/2)+'px'
				})
			.stop()
			.fadeTo(200,1);
		},
		function()
		{
			jQuery(this).find('.submenu, .tooltip, #encuesta, .menu_lonuevo').stop().fadeOut(150);
		}
	);
	
	//Efecto Hover de SubMenu Fundacion
	jQuery("#menu-productos li").hover(
		function()
		{
			var h = jQuery(this).find('.tooltip2').outerWidth();
			jQuery(this).find('.tooltip2')
			.fadeIn(200)
			.css({
						'left':'50%',
						'margin':'0 0 0 -'+(h/2)+'px'
					});
		},
		function()
		{
			jQuery(this).find('.tooltip2').fadeOut(150);
		}
	);
	
	//Tool-tip automático
	jQuery('a[rel=tooltip]').each(
		function()
		{
			var txt = jQuery(this).attr("title");
			jQuery(this).after('<div class="tooltip2">'+txt+'<div class="selector"></div></div>');
        }
	);
	jQuery('a[rel=tooltip]').hover(
		function()
		{
			var h = jQuery(this).next('.tooltip2').outerWidth();
			var h2 = jQuery(this).outerWidth();
			var x = jQuery(this).position().left;
			var y = jQuery(this).position().top;
			
			jQuery(this)
			.removeAttr('title')
			.next('.tooltip2')
			.css({
						'left':(x-((h/2)-(h2/2)))+'px',
						'top':y-40+'px'
				})
			.stop()
			.fadeTo(200,1);
		},
		function()
		{
			jQuery(this).next('.tooltip2').fadeOut(150);
		}
	);
	
	
	//Tool-tip automático idioma
	jQuery('#jflanguageselection a').each(
		function()
		{
			var txt = jQuery(this).find('img').attr("title");
			jQuery(this).after('<div class="tooltip2">'+txt+'<div class="selector2"></div></div>');
			jQuery(this).find('img').removeAttr("title");
        }
	);
	jQuery('#jflanguageselection a').hover(
		function()
		{
			var h = jQuery(this).next('.tooltip2').outerWidth();
			var h2 = jQuery(this).outerWidth();
			var x = jQuery(this).position().left;
			var y = jQuery(this).position().top;
			
			jQuery(this).next('.tooltip2')
			.fadeIn(200)
			.css({
						'left':(x-((h/2)-(h2/2)))+'px',
						'top':y+20+'px'
					});
		},
		function()
		{
			jQuery(this).next('.tooltip2').fadeOut(150);
		}
	);
	
	jQuery("ul.redes li a").hover(
		function()
		{
			var h = jQuery(this).find('.caja-videos').outerWidth();
			jQuery(this).find('.caja-videos')
				.fadeIn(200)
				.css({
						'left':'50%',
						'margin':'0 0 0 -'+(h/2)+'px'
					});
		},
		function()
		{
			jQuery(this).find('.caja-videos').fadeOut(150);
		}
	);
	jQuery('.tooltip-sabores').each(
		function()
		{
			var h = jQuery(this).outerWidth();
			jQuery(this)
					.css({
							'left':'50%',
							'margin':'0 0 0 -'+(h/2)+'px'
						});
		}
	);
	jQuery("a[rel^='img']").prettyPhoto();
	jQuery("a[rel^='prettyphoto']").prettyPhoto();
	jQuery("a[rel^='imagen']").prettyPhoto();
	jQuery('.slide-izq').cycle({ 
   		 fx:    'fade', 
   		 speed:  2500,
		 timeout:  10000 
	 });
	
	jQuery('.scroll-pane').jScrollPane({
		verticalDragMinHeight: 44,
		verticalDragMaxHeight: 44
	});
	/*
	*/	
	jQuery('.scroll-pane2').jScrollPane2({
		verticalDragMinHeight: 44,
		verticalDragMaxHeight: 44
	});
	jQuery(".bt-expertos").hover(
		function()
		{
			jQuery(this).css('height',"243px");
			jQuery(this).find('a').animate({
   			 bottom: "0px"}, 500 );
		},
		function()
		{
			jQuery(this).find('a').stop().animate({
   			 bottom: "-120px"}, 500,function(){jQuery(".bt-expertos").css('height',"125px");} );
		}
	); 
	
	jQuery('.utz-item, .utz-logo').hover(
		function()
		{
			jQuery('.utz-logo').stop(true,false).animate(
				{
					width:'173px',
					height:'173px',
					left:'469px',
					top:'28px'
				}, 150);
    	},
		function()
		{
			jQuery('.utz-logo').stop(true,false).animate(
				{
					width:'151px',
					height:'151px',
					left:'480px',
					top:'32px'
				}, 200);
    	}
	);	
	
	jQuery('.slideshow').cycle({
        fx: 'scrollHorz',
        'next': '.next',
        'prev': '.prev, .prev2' ,
        'timeout' : 5000
    });
	jQuery('.slideshow-sabores').cycle({
        fx: 'scrollHorz',
        'next': '.next',
        'prev': '.prev, .prev2',
		timeout: 0,
    });			   
});
