$(document).ready(function() {

    $("h1").css("margin-bottom", "20px");
    $("li").css("list-style-type","none");


    // TT News ? 
    tt_news_elements = $("#content").find(".tt_news");
    tt_news2_elements = $("#content").find(".tt_news_start"); 
    tt_news = 0;
    
    
    // Gallerie? 
    gallerie = $("#content").find(".csc-textpic-imagerow");
    tt_gallerie = 0;
    
    // FAQ
    faq_set = 0;
	faq = $("#content").find(".countbox");
    
    // Shop? 
    shop = $("#content").find(".col");
    
    if(tt_news_elements.length > 0) {
        elemente = tt_news_elements;
        tt_news = 1;
    } else if(tt_news2_elements.length > 0) {
        elemente = tt_news2_elements;
        tt_news = 1;        
    } else if(gallerie.length > 0) {
        elemente = gallerie;
        tt_news = 0;
        tt_gallerie = 1;
    } else  if(shop.length > 0) {
        elemente = shop;
        tt_news = 0;
        shop = 1;
	} else if(faq.length > 0) {
		elemente = faq;
		faq_set = 1;
    } else {    
        elemente = $("#content").find("p");
        tt_news = 0;
    }
    
    anzahl = elemente.length;
    
    if(tt_news2_elements.length > 0) {
        widthread = anzahl * 370;
        //alert("News!");
    } else if(shop == 1) {
        widthread = anzahl * 200;
    } else {
        widthread = anzahl * 320;    
    }
    
    widthtoset = widthread + "px";
    
    if(anzahl > 1) {
    
        if(tt_news < 1 && shop < 1) {
        	// alert("Kein TT_News, Kein Shop");
            $.each(elemente,function(index,value) { 
                $(this).css({
                    "float" : "left",
                    "width" : "280px",
                    "display" : "block",
                    "padding": "10px",
                    "margin-right" : "20px",
                    "background-image" : "url('/cms/fileadmin/template/raumland/images/bg_weiss_85.png')"
                });             
                
            });
        } else if(shop == 1) {
        	// alert("Kein TT_News, aber Shop!");        	
			$.each(elemente,function(index,value) { 
			    $(this).css({
			        "float" : "left",
			        "width" : "140px",
			        "display" : "block",
			        "padding": "10px",
			        "margin-right" : "20px"
			    });             
			    
			});        	
         } else if(tt_news != 1) {
            //alert("Was anderes");
            $.each(elemente,function(index,value) { 
                $(this).css({
                    "float" : "left",
                    "width" : "280px",
                    "display" : "block",
                    "padding": "10px",
                    "margin-right" : "20px",
                    "background-image" : "url('/cms/fileadmin/template/raumland/images/bg_weiss_85.png')"
                });             
                
            });
        }
             
        if(tt_gallerie > 0) {
        	$(".csc-textpic-imagewrap").css("width",widthtoset);
        	$(".csc-textpic-image").css("float","left");
        }
                
        $("#content").css("width", widthtoset);
        $("#main").css("width", widthtoset);        
        $(".csc-textpic").css("width", widthtoset);        
        $(".csc-default").css("width", widthtoset);        
        $("#mainInner").css("width", widthtoset);
        $("#content").append("<div class='clearBoth'></div>");
    }

});
