var lastGalleryId = null;

var galleries = {
	"feketezaj": { quantity: 16, path: "gallery/koncert-20090806" },
	"konzerv": { quantity: 12, path: "gallery/koncert-20090529" },
	"kiadvany": { quantity: 3, path: "gallery/kiadvany" },
	"szilveszter": { quantity: 14, path: "gallery/koncert-20081231" },
	"gotbal1": { quantity: 25, path: "gallery/koncert-20081018" },
	"deadbornpromo": { quantity: 3, path: "gallery/deadborn-dreams-promo" }
};

function populateGallery(id) {
	if (id == undefined) {
		for (var galleryId in galleries) {
			id = galleryId;
			break;
		}
	}

	var gallery = galleries[id];
	var list = $("#gallery-" + id);
	
	for (var pictureIndex=1; pictureIndex<=gallery.quantity; pictureIndex++) {
		if (pictureIndex < 10) {
			pictureIndex = "0" + pictureIndex;
		}
		
		var item = $("<li>");
		var picture = $("<img>").attr("src", gallery.path + "/" + pictureIndex + ".jpg");
		picture.appendTo(item);
		item.appendTo(list);
	}
	
	$('ul.gallery').galleria({
		history: false,
		clickNext: true,
		insert: "#galleria-container",
		onImage: function(image, caption, thumb) {
			image.css("display","none").fadeIn(750);
			
			var list = thumb.parents("li");
			list.siblings().children("img.selected").fadeTo(500, 0.3);
			thumb.fadeTo("fast", 1).addClass("selected");
			image.attr("title", "Következő »");
        },
        onThumb : function(thumb) {
            var list = thumb.parents("li");
            var target = list.is(".active") ? "1" : "0.3";
            thumb.css({ display: "none", opacity: target }).fadeIn(1500);
            thumb.hover(
                function() { thumb.fadeTo("fast", 1); },
                function() { list.not(".active").children("img").fadeTo("fast", 0.3); }
            )
    	}
	});

	$("#gallery-container").show();
	$("#gallery-" + id).find("li:first").find("img").click();
	lastGalleryId = id;
}

function showAlbum(id) {
	$("#album-" + lastGalleryId).removeClass("album-text-selected");
	$("#gallery-" + lastGalleryId).empty();
	$("#album-" + id).addClass("album-text-selected");
	$("#galleria-container").empty();
	
	populateGallery(id);
}

function onAlbumClicked(element) {
    var id = element.id.split("-")[1];
    showAlbum(id);
}
