//
// Galeria v1.3
// Autor: Oscar Linares
// http://www.innovacionweb.com/galeria-accesible-jquery.php
// http://code.google.com/p/galeria-jquery-jsgal/
//
// Gracias a:
// Ariel Flesler por su plugin jQuery.Preload, aunque al final no lo uso (muy potente, demasiado
// para lo que necesito aquí).
// http://flesler.blogspot.com/2008/01/jquerypreload.html
// Para la precarga me inspire en (muchas gracias)
// http://www.noth.es/2007/11/25/actualizacion-del-jquery-gallery-v-0-2/
//
$(function() {
    $(".gallery").gallery();

});


jQuery.log = function(message) {
	if(window.console) {
		console.debug(message);
  	} else {
     		alert(message);
  	}
};

(function($) {
    $.fn.gallery = function() {
        return this.each(function() {
            var itemId = $(this).attr("id");
            
            $("a", this).click(function() {
                $(".currThumb").removeClass("currThumb");
                $("#" + itemId + " .imgComment .jsgalpre").remove();
                var imageAddress = $(this).attr("href");
                var imageAlt = $(this).children("img").attr("alt");

                $("#" + itemId + " .imgComment").append("<div class='jsgalpre'>" + imageAlt + "</div>");
                $("#" + itemId + " .imgprin img").fadeOut("fast").remove();
                
                var objImagen = new Image(); 
                
                $(objImagen).load(function() {
                    $(this).hide();
                    $("#" + itemId + " .imgprin").append(this);
                    $(this).fadeIn("fast");
                });
                $(objImagen).attr("src", imageAddress);
                $(this).children("img").addClass("currThumb");
                // $("#" + itemId + " .imgprin .jsgalpre").remove();
                return false;
            });
        });
    };
})(jQuery);
