$(document).ready(function(){
	//Flexbiles Content Element Typ 3
	$(".ce_type_3").each(function(){
		//"mehr..." Link dem Bild anhängen und verknüpfen
		$(this).find(".right .csc-textpic-imagecolumn ul li").append("<div class=\"read_more\"><a href=\"javascript:void(0);\">mehr...</a></div>");
		$(this).find(".right .csc-textpic-imagecolumn ul li .read_more a").click(function(){
			$(this).parent().prev("a").trigger("click")
		});
		
		//Bildgalerie Breite an Bildbreite orientieren
		$(this).find(".right .csc-textpic-imagecolumn ul li").each(function(index, element){
			width = $(element).find("a img").attr("width");
			$(element).css("width", width);
			$(element).parents(".csc-textpic-imagecolumn:first").attr("style", "width: " + width + "px !important");
			
			//Die Höhe des Liste orientiert sich nur an der Höhe des 1.Bildes
			if (index == 0)
			{
				$(element).parent("ul:first").css("height", $(element).outerHeight() + 10);
			}
		});
		
		$(this).find(".right .csc-textpic-imagecolumn ul li a img").each(function(){
			if ($(this).attr("alt") != "")
			{
				$(this).parent("a").attr("title", $(this).parent("a").attr("title") + "<div class=\"sbAlt\">" + $(this).attr("alt") + "</div>");
			}
		});
	});
	
	//Flexbiles Content Element Typ 4
	var ce_type_4_cache = null;
	
	//Alle CE Elemente auf der Seite durchgehen
	$(".ce_type_4").each(function(){
		
		//Aus der ersten Galerie werden die Bilder bei Mouseover/out getauscht
		$(this).find(".csc-textpic-imagecolumn ul li img:first").mouseover(function(){		
			//Bildpfad speichern
			ce_type_4_cache = $(this).attr("src");
			
			//Bildpfad vom 2.Bild nehmen
			$(this).attr("src", $(this).parents("ul:first").find("li:last img").attr("src"));
		});
		
		$(this).find(".csc-textpic-imagecolumn ul li img:first").mouseout(function(){
			//Bildpfad wiederherstellen
			$(this).attr("src", ce_type_4_cache);
			
			ce_type_4_cache = null;
		});
		
		//Wenn erstes Bild angeklickt wird, dann soll die Lightbox aus der verstecken
		//Galerie gestartet werden
		$(this).find(".csc-textpic-imagecolumn ul li img:first").click(function(){
			$(this).parents(".ce_type_4:first").find(".hidden_gallery .csc-textpic-imagecolumn ul li a:first").trigger("click");
		});
		
		$(this).find(".csc-textpic-imagecolumn ul li a img").each(function(){
			if ($(this).attr("alt") != "")
			{
				$(this).parent("a").attr("title", $(this).parent("a").attr("title") + "<div class=\"sbAlt\">" + $(this).attr("alt") + "</div>");
			}
		});
	});
});
