function init_gallery(only_gallery, gallery_width_class) {
	
	if(typeof(only_gallery) == 'undefined') {
		only_gallery = false;
	}
	
	if(typeof(gallery_width_class) == 'undefined') {
		gallery_width_class = '';
	}
	else{
		gallery_width_class = ' width_' + gallery_width_class;
	}
	
    $(".wordpress_post").each(function() {
        var list	= "";
        var i		= 1;
        if($(this).find(".gallery").length == 0 && only_gallery == false) {
        	// stack
        	$(this).find("img:not(.wp-smiley)").each(function(){
        		list = list+"<li><img src='" + $(this).attr("src") + "' /></li>";
        		$(this).remove();
        	});
        	if(list.length !== 0) {
        		$(this).find("h2").after('<div class="stack' + gallery_width_class + '"><ul>' + list + '</ul></div>');
        	}
        }
        else {
        	if($(this).find("img").length !== 0){
        		// gallery
        		$(this).find("img").each(function() {
        			var src = $(this).attr("src");
        			list = list+'<li><img src="' + src + '" rel="' + i + '" /></li>';
        			i = i+1;
        		});
        		$(this).find(".gallery,img").remove();
        		$(this).find("h2").after("<div class='slideshow" + gallery_width_class + "'><a href='#' onClick='return false' class='prev'></a><ul>" + list + "</ul><a href='#' onClick='return false' class='next'></a><div style='clear: both;'></div><div class='image_label'><span>bild <span class='no'>1</span>/<span class='total'></span></span></div></div>");
        		$(this).find(".slideshow .image_label span .total").html($(this).find(".slideshow ul li").size());
        		$(".slideshow ul li:first-child").addClass("active");
        	
        	}
        }
    });
    
    $(".slideshow .prev").click(function(){
        if($(this).siblings("ul").find("li.active").prev().length !== 0) {
        	$(this).siblings("ul").find("li").hide();
        	$(this).siblings("ul").find("li.active").removeClass("active").prev().addClass("active").show();
        	$(this).siblings(".image_label").find("span .no").html($(this).siblings("ul").find("li.active img").attr("rel"));
        }
        else {
        	$(this).siblings("ul").find("li").hide().removeClass("active");
        	$(this).siblings("ul").find("li:last-child").addClass("active").show();
        	$(this).siblings(".image_label").find("span .no").html($(this).siblings("ul").find("li.active img").attr("rel"));
        }
        emediateReload();
        return false;
    });
    
    $(".slideshow .next").click(function() {
        if($(this).siblings("ul").find("li.active").next().length !== 0) {
        	$(this).siblings("ul").find("li").hide();
        	$(this).siblings("ul").find("li.active").removeClass("active").next().addClass("active").show();
        	$(this).siblings(".image_label").find("span .no").html($(this).siblings("ul").find("li.active img").attr("rel"));
        }
        else {
        	$(this).siblings("ul").find("li").hide().removeClass("active");
        	$(this).siblings("ul").find("li:first-child").addClass("active").show();
        	$(this).siblings(".image_label").find("span .no").html($(this).siblings("ul").find("li.active img").attr("rel"));
        }
        emediateReload();
        return false;
    });
}
