     $(function() {

     	$(".mainitem").click(function () {
    		$(this).children(".subitems").show("fast");
		$(this).addClass("active");
    		});


        $(".item, .subitem").click(function() {
        		var contentTheme = $(this).attr("id");
                        $("#merker").hide();
                        $(".slideshow").empty();
    			$(".static").hide();
                        $("." + contentTheme).fadeIn(function(){
                        	if (!$(this).hasClass("subitem")){
				$(".subitems").hide("fast");
				};
                        });
                        $(".mainitem, .item, .subitem").removeClass("active");
			$(this).addClass("active");
                        });


     	$(".galleryitem").click(function() {
			$(".static").hide();
			$(".slideshow").empty();
			$(".firstshow").empty();
			$("#merker").hide();
			$("#merker > .Gallery").remove();
			$(".Gallery").clone().appendTo("#merker", function(){
                        	$("#merker > .Gallery > .thumbs").attr("id","thumbs_1");
				});

                	$("#loader").show();

			var theme = $(this).attr("id");
			var themeLG = $(this).text();

			$.ajax({
                 		type: "GET",
                 		url: "galleries/" + theme + "/gallery.xml",
                 		dataType: "xml",
                 		success: function(xml) {

                                if (!$(this).hasClass("subitem")){
					$(".subitems").hide("fast");
				};

                                var totalImgs = $(xml).find("image").size();
                                var count = 1;
                                $(xml).find("image").each(function(){
                         		var orgImg = $(this).attr("imageURL");
                         		var thumbImg = $(this).attr("thumbURL");
                         		var captTxt = $(this).find("caption").text();
                         		$("<li class='" + count + "'><img src='galleries/" + theme + "/" + thumbImg + "' alt='galleries/" + theme + "/" + orgImg + "' title='" + captTxt + "' name='" + themeLG + "'></li>")
                         		.appendTo("#merker > .Gallery > #thumbs_1");
                         		count++;
                     			});

                     		var firstImg = $(".1 > img").attr("alt");

				$("<img id='first'/>").attr("src", firstImg).appendTo(".firstshow");

                     			$(document).ready(function(){

                     				$("#first").load(function(){
            						var firstImgHeight = $(".firstshow > img").height();
							var firstImgWidth = $(".firstshow > img").width();
							$("#loader").hide();
							$("#merker").show();
                     					$("#merker > .Gallery").flickrGallery({
                     						firstHeight: firstImgHeight,
                     						firstWidth: firstImgWidth
                     						});
                     				});
                     			});
                		}
                	});
    		$(".mainitem, .item, .subitem, .galleryitem").removeClass("active");
    		$(this).addClass("active");

         });
});




