//jquery gallery

(function($) {
	$.fn.galimg = function() {
		return this.each(function() {
			var idGal = $(this).attr("id");
			$("a", this).click(function() {
				
				//active
				$("#" + idGal + " a:first").addClass("active");
				$("#" + idGal + " a").removeClass("active");
				$(this).addClass("active");
				
				//core
				var pathImg = $(this).attr("href");
				$("#" + idGal + " .stage img").fadeOut("fast").remove();
				var objImg = new Image();
				
				$(objImg).load(function() {
					$(this).hide();
					$("#" + idGal + " .stage").append(this);
					$(this).fadeIn("slow");
				});
				
				$(objImg).attr("src", pathImg);
				
				//caption
				$("#" + idGal + " .stage .caption").remove();
				$("#" + idGal + " .stage").append("<div class='caption'><span>"+ this.title +"</span></div>");
				$("#galimg .caption").css("opacity",0.5);
				
				return false;
			});
		});
	};
})(jQuery);

$(function() {
	$("#galimg").galimg();
	$("#galimg .caption").css("opacity",0.5);
});



