remplazarFuentes();

$(window).load(function () {
	gestionSombras();
	//remplazarFuentes();
	ayco_control_rollover();
	control_nextStep();
	control_tabs();
	muestra_fecha();
	lanzarFancyBox();
	controla_tooltip();
	control_slide();
	
	$.preLoadImages('img/show_bt_atras_on.gif', 'img/show_bt_avanti_on.gif');
	
});

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

function gestionSombras(){
	
//	$("a.actPag span").dropShadow({left: 0, top: 1, opacity: 1, blur: 0, color: "#ffffff"});
	
}

var api;

function control_slide() {
	$("#tabsCabecera").tabs("#imgCabecera > div", {
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow();
	setTimeout(function () {
		$("#tabsCabecera").data("slideshow").play();
	},3500);
	
	if ($("#tabsProductos").length!=0) {
		api = $("#tabsProductos").tabs("#slideProductos > div", {
			effect: 'fade',
			fadeOutSpeed: "slow",
			rotate: true
		})
		
		api.slideshow();
		setTimeout(function () {
			if (typeof(api)!="undefined") {
				api.data("slideshow").play();
			};
		},5000);
	}
	
	$(".forwardProductos").click(function () {
		api.data("slideshow").getTabs().prev();
		return false;
	})
	$(".backwardProductos").click(function () {
		api.data("slideshow").getTabs().next();
		return false;
	})
	
}



function remplazarFuentes(){
	
		Cufon.replace('#menu a', { fontFamily: 'Nilland_R', hover: true });
		Cufon.replace('#menu a.activo', { fontFamily: 'Nilland_R', hover: true });
		
		Cufon.replace('#pie', { fontFamily: 'Nilland_B' });
		Cufon.replace('a.pieLink', { fontFamily: 'Nilland_B', hover: true });
		Cufon.replace('.submenu', { fontFamily: 'Nilland_B', hover: true });
		Cufon.replace('.submenuAct', { fontFamily: 'Nilland_B', hover: true });
		Cufon.replace('.titSeccion', { fontFamily: 'Nilland_R', textShadow: '#134288 1px 1px 0px' });
		Cufon.replace('p.blqDestacaUp', { fontFamily: 'Nilland_R', textShadow: '#285798 1px 1px 0px' });
		Cufon.replace('a.btProducto', { fontFamily: 'Nilland_R', textShadow: '#720000 1px 1px 0px' });
		Cufon.replace('div.prodCategoria', { fontFamily: 'Nilland_B', textShadow: '#3362a7 1px 1px 0px', color: '-linear-gradient( #60a9e7,#c1ddff)'});
		
		Cufon.replace('H1', { fontFamily: 'Nilland_B', textShadow: '#285798 1px 1px 0px' });
		Cufon.replace('H2', { fontFamily: 'Nilland_R'});
		Cufon.replace('H3', { fontFamily: 'Nilland_B'});
		Cufon.replace('H4', { fontFamily: 'Nilland_R'});
		Cufon.replace('H5', { fontFamily: 'Nilland_R', textShadow: '#285798 1px 1px 0px' });
}

function control_tabs () {
	$("div.tabs").tabs(".images > div", {
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow();
}

function control_nextStep () {
	$("#nextStep a").hover(
		function () {
			var $elsToFadeOut	= $("span#swap span:visible:not(#" + $(this).find("img").attr("rel") + ")");
			var $elToFadeIn		= $("span#" + $(this).find("img").attr("rel"));
			
			if ($elsToFadeOut.length>0) {
				$elsToFadeOut.stop(true,true).fadeOut('normal', function () {
					$elToFadeIn.fadeIn("normal");
				});
			} else {
				$elToFadeIn.fadeIn("normal");
			}
		},
		function () {
			var $elToFadeOut	= $("span#" + $(this).find("img").attr("rel"));
			$elToFadeOut.stop(true,true).fadeOut('normal');
		}
	);
}

function ayco_control_rollover () {
	$(".rollover[src*=_off]").unbind('hover').hover(
		function () {
			off_src	= $(this).attr("src");
			on_src	= off_src.replace("_off","_on");
			$(this).attr("src",on_src);
		},
		function () {
			on_src	= $(this).attr("src");
			off_src	= off_src.replace("_on","_off");
			$(this).attr("src",off_src);
		}
	);
}

function ayco_alertar (txt,callback) {
	var alertar_id = "info_" + new Date().getTime();
	$('<div id="' + alertar_id + '">' + txt + '</div>').dialog({
		bgiframe: true,
		modal: true,
		title: "Informaci&oacute;n",
		resizable: false,
		buttons: {
			Aceptar: function() {
				$("#" + alertar_id).dialog('close');
			}
		},
		beforeclose: function(event, ui) {
			switch (typeof(callback)) {
				case "function":
					callback.call();
					break;
				case "string":
					eval(callback);
					break;
			}
			$("#" + alertar_id).dialog('destroy').remove();
		}
	});
}

function ayco_confirmar (txt,callback_ok,callback_ko) {
	var confirmar_id = "info_" + new Date().getTime();
	$('<div id="' + confirmar_id + '">' + txt + '</div>').dialog({
		bgiframe: true,
		modal: true,
		title: "Informaci&oacute;n",
		resizable: false,
		buttons: {
			Aceptar: function() {
				switch (typeof(callback_ok)) {
					case "function":
						callback_ok.call();
						break;
					case "string":
						eval(callback_ok);
						break;
				}
				$("#" + confirmar_id).dialog('close');
			},
			Cancelar: function() {
				switch (typeof(callback_ko)) {
					case "function":
						callback_ko.call();
						break;
					case "string":
						eval(callback_ko);
						break;
				}
				$("#" + confirmar_id).dialog('close');
			}
		},
		beforeclose: function(event, ui) {
			$("#" + confirmar_id).dialog('destroy').remove();
		}
	});
}

function muestra_fecha(){
	
	$(".fechaNot").css({opacity:.1});
	
	$(".noticia").hover(
		function () {
			var $fechaNot = $(".fechaNot",$(this));
			$fechaNot.stop(true,true).animate({opacity:1},"slow");
			//$infoNot.siblings(".infoNot").animate({opacity:"1", width:"560"},"slow");
		},
		function () {		
			var $fechaNot = $(".fechaNot",$(this));
			$fechaNot.stop(true,true).animate({opacity:.1},"slow");
		}
	);
}

function lanzarFancyBox () {
	if ($.isFunction($.fancybox)) {
		$("a.fancyImg").fancybox({'titlePosition'  : 'outside'});
	}

}

function validarFormularioContacto() {
	$(document).ready(function(){
		$("#boton_enviar").click(function(){
			$("#fcontacto").submit();
		});
	
		$("#fcontacto").validate({
			rules: {
				nombre: {
					required: true
				},
				email: {
					email: true,
					required: true
				},
				telefono: {
					required: true
				}
			},
			messages: {
				nombre: {
					required: "Por favor, introduzca aquí su nombre"
				},
				email: {
					email: "Por favor, introduzca una dirección de E-Mail válida",
					required: "Por favor, introduzca aquí su E-Mail"
				},
				telefono: {
					required: "Por favor, introduzca aquí su teléfono"
				}
			}
		});	
	});
}

function controla_tooltip () {
	var $tooltip = $(".tooltip");
	$("#subMenu a.deshabilitado").hover(
		function () {
			$tooltip.stop(true,true).remove();
			
			$tooltip = $('<div class="tooltip"><div class="ttCornerLeft"></div><div class="ttMain">' + $(this).attr("rel") + '</div><div class="ttCornerRight"></div></div>').css({display: "none"}).appendTo($(this).parent());
			
			tooltip_left	= (((($(this).offset().left + $(this).width()) - $(this).offset().left) / 2) + $(this).offset().left) - ($tooltip.width()/2);
			tooltip_top	= $(this).offset().top - 45;
			$tooltip.css({left: tooltip_left, top: tooltip_top, display: 'block', opacity: 0}).animate({opacity: 1, top: '+=10'},'slow','');
		},
		function () {
			$tooltip.animate({opacity: 0, top: '-=5'},'fast','',function () {
				$tooltip.remove();
			});
		}
	).click(function () {
		return false;
	});
}

function tabModule () {
	var $contenedorTab		= $(".tabModInfo");
	var $contenedorLinks	= $("#tabLinks");
	var $tabsInfo			= $(".tabInfo",$contenedorTab);
	//var maxHeight			= 0;
	
	$tabsInfo.map(function () {
		$("<a href='#'></a>").appendTo($contenedorLinks);
		
		//maxHeight	= ((maxHeight<$(this).height()) ? $(this).height() : maxHeight );
		
		if ($tabsInfo.index($(this))>0) {
			$(this).css('display','none');
		} else {
			$("a:eq(" + $tabsInfo.index($(this)) + ")",$contenedorLinks).toggleClass("tabAct",true);
			$contenedorTab.height($(this).height());
		}
	});
	
	//$contenedorTab.height(maxHeight);
	
	var $tabControls	= $("a",$contenedorLinks);
	
	$tabControls.click(function () {
		$tabControls.toggleClass("tabAct",false);
		$(this).toggleClass("tabAct",true);
		
		$tabsInfo.fadeOut();
		$(".tabInfo:eq(" + $tabControls.index($(this)) + ")",$contenedorTab).fadeIn();
		$contenedorTab.animate({height: $(".tabInfo:eq(" + $tabControls.index($(this)) + ")",$contenedorTab).height() + "px"})
		
		return false;
	})
};

function change_idioma (id_idioma) {
	document.fidioma.idioma.value	= id_idioma;
	document.fidioma.submit();
}












