(function($) {
    
    var images = new Array()
    function preload() {
	    for (i = 0; i < preload.arguments.length; i++) {
		    images[i] = new Image()
		    images[i].src = preload.arguments[i]
	    }
    }
    preload(
	    "images/mn_rollover.png",
	    "images/bg_subitem.png",
	    "images/tooltip_top.png",
	    "images/tooltip_bottom.png",
	    "images/tooltip_arrow.png",
	    "images/productos/bg_rolloverfamily.png"
    )

    $(document).ready(function() {

		if ($(".scroll").length > 0) {
			$(".scroll").cycle({ 
				fx:      'scrollUp',
				pause: 1,
				speed:    300,
				width: 297,
				height: 150,
				fit:1,
				slideResize: 0,
				timeout:  6000 
			});
		}

        if ($('#slider').find("a").length > 0) $('#slider').amdSlider({effect:"fade"});

		$(".abrir_tooltip").mouseenter(function() {
			var tooltip = $(this).find(".tooltip_cont");
			tooltip.show();
		});
		$(".abrir_tooltip").mouseleave(function() {
			var tooltip = $(this).find(".tooltip_cont");
			tooltip.hide();
		});
	
		// Lightbox mensajes
		$(".mensajes_inline").fancybox({
			padding:0,
			overlayColor:"#000",
			autoDimensions: true,
			onClosed: function() {
				window.location.hash = '';
			}
		});		

		var hashtag = window.location.hash;
		if (hashtag == "#registrado") {
			$("#lanza_lightbox2").attr("href", "#msj_registro").click().attr("href", "#");
		} else if (hashtag == "#registro-error") {
			$("#lanza_lightbox2").attr("href", "#msj_registro_error").click().attr("href", "#");
		} else if (hashtag == "#registro-confirmado") {
			$("#lanza_lightbox2").attr("href", "#msj_registro_confirmado").click().attr("href", "#");
		} else if (hashtag.indexOf("#pedido-realizado") === 0) {
			$("#lanza_lightbox2").attr("href", "#msj_pedido_ok").click().attr("href", "#");
		} else if (hashtag.indexOf("#pedido-error") === 0) {
			$("#lanza_lightbox2").attr("href", "#msj_pedido_no_ok").click().attr("href", "#");
		} else if (hashtag == "#contacto-ok") {
			$("#lanza_lightbox2").attr("href", "#msj_contacto_ok").click().attr("href", "#");	
		} else if (hashtag == "#recordar-contrasenya-error") {
			$("#lanza_lightbox2").attr("href", "#msj_recordar_contrasenya_error").click().attr("href", "#");	
		} else if (hashtag == "#recordar-contrasenya-error2") {
			$("#lanza_lightbox2").attr("href", "#msj_recordar_contrasenya_error2").click().attr("href", "#");
		} else if (hashtag == "#recordar-contrasenya") {
			$("#lanza_lightbox2").attr("href", "#msj_recordar_contrasenya").click().attr("href", "#");	
		} else if (hashtag == "#recordar-contrasenya-ok") {
			$("#lanza_lightbox2").attr("href", "#msj_recordar_contrasenya_ok").click().attr("href", "#");				
		}
	
    });
    
})(jQuery);
