$(document).ready(function() {
	// Slider					   
	$("div.folder > div.folder_list").hide();
	$("div#plan > div.invis").hide();
	
	$("div.folder > div.folder_box").click(function() {
		if ($(this).next().css("display") == "none") {
			$(this).parent().parent().find("div.folder_list:visible").slideUp("normal");
			$(this).next().slideDown("normal");
			$(this).parent().parent().find("div.folder_box a > img").attr("src", "fileadmin/templates/images/icons/pfeil_r_w_g.gif");
			$(this).parent().parent().find("div.folder_box > a").removeAttr("id");
			// Schieber andere Listena uf gleicher Seite dann auch schliessen
			$(this).parent().parent().parent().find("div.folder div.folder_box a > img").attr("src", "fileadmin/templates/images/icons/pfeil_r_w_g.gif");
			$(this).parent().parent().parent().find("div.folder div.folder_box > a").removeAttr("id");
			$(this).find("a").attr("id","now");
			$(this).find("a > img").attr("src", "fileadmin/templates/images/icons/pfeil_u_w_g.gif");
			// Anker setzen für Zurück-Button
	//		location.search = $(this).parent().next().find('.folder_detail').attr("id");
	
			// Zählpixel einbauen
/* Zählpixel um genau bestimmen zu können, welches element angeklickt wurde
			url = window.location.href.replace(location.hash, "");
			url = url.replace(window.location.search, "");
			url = url.substring(0,(url.length-5));
			$("#maincolouter").append("<img class='counter' src='http://wdr.ivwbox.de/cgi-bin/ivw/CP/;"+url+"/"+location.hash.substring(2)+"/' width='1' height='1' alt='' />");
			$("#maincolouter").append("<img class='counter' src='http://stat.wdr.de/cgi-bin/wdr/CP/"+url+"/"+location.hash.substring(2)+"/' width='1' height='1' alt='' />");
*/
			$("#maincolouter").append("&nbsp;<img class='counter' src='http://wdr.ivwbox.de/cgi-bin/ivw/CP/;"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
			$("#maincolouter").append("&nbsp;<img class='counter' src='http://stat.wdr.de/cgi-bin/wdr/CP/"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
			return false;
		} else {
			$(this).next().slideUp("normal");
			$(this).find("a").removeAttr("id");
			$(this).find("a > img").attr("src", "fileadmin/templates/images/icons/pfeil_r_w_g.gif");
		}
		return;
	});
	
	
	// News aufklappen
	if(location.search.length != 0) {
		var qs = location.search.substring(1);
		$("div#"+qs).parent().show();
		$("div#"+qs).parent().parent().find("a > img").attr("src", "fileadmin/templates/images/icons/pfeil_u_w_g.gif");
		$("div#"+qs).parent().parent().find("a").attr("title", "Nachricht verbergen");
		$("div#"+qs).parent().parent().find("a").attr("id","now");
		$("div#"+qs).parent().parent().attr("title", "Nachricht verbergen");
		$("div#"+qs).parent().parent().find("div.titel").css("font-weight", "bold");
	} 
	
	
	// Slider automatsich ausfahren wenn Anker gesetzt
	if(location.hash != 0) {
		var qs = location.hash.substring(2);
		if($("#"+qs).css("display") == "none") {
			$("#"+qs).parent().parent().find("div.folder_list:visible").slideUp("normal");
			$("#"+qs).parent().parent().find("div.folder_box a > img").attr("src", "fileadmin/templates/images/icons/pfeil_r_w_g.gif");
			$("#"+qs).parent().parent().find("div.folder_box > a").removeAttr("id");
			$("#"+qs).slideDown("normal");
			$("#"+qs).parent().find("a > img").attr("src", "fileadmin/templates/images/icons/pfeil_u_w_g.gif");
			$("#"+qs).parent().find("div.folder_box > a").attr("id","now");
		}
	}	


   // Zoom Funktion für Beitragsbilder
   $("div.mod_bild").find("a.zoom").click(function() {
	if($(this).parents("div.mod_bild").parent("div").attr("class")!="one-col") {
		// alles zuklappen
		$(this).parents("div.mod_bild").parent("div").removeClass("two-cols");
		$(this).parents("div.mod_bild").parent("div").siblings("div").removeClass("two-cols");
		$(this).parents("div.mod_bild").parent("div").addClass("one-col");
		$(this).parents("div.mod_bild").parent("div").siblings("div").addClass("one-col");
		// Bilder tauschen
		teaser = $(this).parents("div.mod_bild").find("img:first").attr("src");
		$(this).parents("div.mod_bild").find("img:first").attr({ 
          src: $(this).attr("href")
        });
		// Link zurück auf Ausgangsgröße setzen
		$(this).parents("div.mod_bild").find("a").attr("href",teaser);
		$(this).parent("div.mod_bild").parent().parent().find("h2").css("margin-top","0.5em");
		// Icons und Bubbles neusetzen
		$(this).parents("div.mod_bild").find("a.lupe img").attr({ 
          src: "fileadmin/templates/images/icons/lupe_minus.gif"
        });
		$(this).parents("div.mod_bild").find("a.lupe").attr({ 
          title: "Bild verkleinern"
        });
		// Zählpixel einbauen
		$("#maincolouter").append("<img class='counter' src='http://wdr.ivwbox.de/cgi-bin/ivw/CP/;"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		$("#maincolouter").append("<img class='counter' src='http://stat.wdr.de/cgi-bin/wdr/CP/"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
	}
		else 
	{
		$(this).parents("div.mod_bild").parent("div").removeClass("one-col");
		$(this).parents("div.mod_bild").parent("div").siblings("div").removeClass("one-col");
		$(this).parents("div.mod_bild").parent("div").addClass("two-cols");
		$(this).parents("div.mod_bild").parent("div").siblings("div").addClass("two-cols");
		// Bilder tauschen
		teaser = $(this).parents("div.mod_bild").find("img:first").attr("src");
		$(this).parents("div.mod_bild").find("img:first").attr({ 
          src: $(this).attr("href")
        });
		// Link zurück auf Ausgangsgröße setzen
		$(this).parents("div.mod_bild").find("a").attr("href",teaser);
		$(this).parent("div.mod_bild").parent().parent().find("h2").css("margin-top","0");
		// Icons und Bubbles neusetzen
		$(this).parents("div.mod_bild").find("a.lupe img").attr({ 
          src: "fileadmin/templates/images/icons/lupe_plus.gif"
        });
		$(this).parents("div.mod_bild").find("a.lupe").attr({ 
		  title: "Bild vergrößern"
        });
		// Zählpixel entfernen
//		$(this).parents("div.mod_bild").parent().parent().find("h2 img.counter").remove();
	}
	return false;
 	});

/*
    // Zoom für normale Content Elemente
    $("div.csc-textpic").find("a.zoom").click(function() {

        // 

		// Bilder tauschen
		teaser = $(this).find("img:first").attr("src");
        //console.log($(this).attr("href"));
		$(this).find("img:first").attr({ 
          src: $(this).attr("href"),
          width: 458,
          height: 201
        });

		// Link zurück auf Ausgangsgröße setzen
		$(this).attr("href", teaser);

        console.log('TEST one zwo');
        return false;
    });
*/

	var pfeile = '<span class="pfeil_button"><a class="carousel-back" title="zur&uuml;ck"><img src="fileadmin/templates/images/icons/pfeil_rund_links.gif" width="19" height="19" alt="zur&uuml;ck" class="h_pfeil_l" /></a> <a class="carousel-forward" title="vor"><img src="fileadmin/templates/images/icons/pfeil_rund_rechts.gif" width="19" height="19" alt="vor" class="h_pfeil_r" /></a></span>'
	// 2er-Teaser
	$("div .carousel h2").append(pfeile);
//	$("div .carousel h1").remove();
	$("div .carousel .two-cols .content-block").addClass("nocss");
	$("div .carousel .two-cols .content-block:first").removeClass("nocss");
	$("div .carousel .two-cols .content-block:first").addClass("active");
	$("div .carousel .float-right .content-block").addClass("nocss");
	$("div .carousel .float-right .content-block:first").removeClass("nocss");
	$("div .carousel .float-right .content-block:first").addClass("active");
	
	
	// Karussell für Plugin
	// NÃ¤chstes Element anzeigen
	$("div .carousel .carousel-forward").click(function() {
		if($(this).parent().parent().parent().parent().find(".teaser-content-wrapper").length) {
			return;
		}
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://wdr.ivwbox.de/cgi-bin/ivw/CP/;"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://stat.wdr.de/cgi-bin/wdr/CP/"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		$(this).parent().parent().parent().removeClass("active");
		$(this).parent().parent().parent().addClass("nocss");
		if($(this).parent().parent().parent().next().next().next().length) {
			$(this).parent().parent().parent().next().next().next().addClass("active");
			$(this).parent().parent().parent().next().next().next().removeClass("nocss");
		}
		else {
			$(this).parent().parent().parent().parent().find(".content-block:first").addClass("active");
			$(this).parent().parent().parent().parent().find(".content-block:first").removeClass("nocss");
		}
	});
	// Vorheriges Element anzeigen
	$("div .carousel .carousel-back").click(function() {
		if($(this).parent().parent().parent().parent().find(".teaser-content-wrapper").length) {
			return;
		}
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://wdr.ivwbox.de/cgi-bin/ivw/CP/;"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://stat.wdr.de/cgi-bin/wdr/CP/"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		$(this).parent().parent().parent().removeClass("active");
		$(this).parent().parent().parent().addClass("nocss");
		if($(this).parent().parent().parent().prev().prev().prev().length) {
			$(this).parent().parent().parent().prev().prev().prev().addClass("active");
			$(this).parent().parent().parent().prev().prev().prev().removeClass("nocss");
		}
		else {
			$(this).parent().parent().parent().parent().find(".content-block:last").addClass("active");
			$(this).parent().parent().parent().parent().find(".content-block:last").removeClass("nocss");
		}
	});

	// Karussell für FCE
	// nächstes Element anzeigen
	$("div .carousel .teaser-content-wrapper .carousel-forward").click(function() {
		var carFceMother = $(this).parent().parent().parent().parent();
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://wdr.ivwbox.de/cgi-bin/ivw/CP/;"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://stat.wdr.de/cgi-bin/wdr/CP/"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		carFceMother.parent().find(".active").addClass("nocss");
		carFceMother.parent().find(".active").removeClass("active");
		if(carFceMother.next().next().next().length) {
			carFceMother.next().next().next().addClass("active");
			carFceMother.next().next().next().removeClass("nocss");
		}
		else {
			carFceMother.parent().find(".content-block:first").addClass("active");
			carFceMother.parent().find(".content-block:first").removeClass("nocss");
		}
	});
	// Vorheriges Element anzeigen
	$("div .carousel .teaser-content-wrapper .carousel-back").click(function() {
		var carFceMother = $(this).parent().parent().parent().parent();
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://wdr.ivwbox.de/cgi-bin/ivw/CP/;"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		$("#maincolouter").append("&nbsp;<img class='counter' src='http://stat.wdr.de/cgi-bin/wdr/CP/"+window.location.href.replace("http://", "")+"' width='1' height='1' alt='' />");
		carFceMother.removeClass("active");
		carFceMother.addClass("nocss");
		if(carFceMother.prev().prev().prev().length) {
			carFceMother.prev().prev().prev().addClass("active");
			carFceMother.prev().prev().prev().removeClass("nocss");
		}
		else {
			carFceMother.parent().find(".content-block:last").addClass("active");
			carFceMother.parent().find(".content-block:last").removeClass("nocss");
		}
	});
    
    $(".service_bereiche ul li").hover(
      function () {
            $(this).find('.rsslink').css('visibility', 'visible');
            $(this).css('background', '#A7CF81');
      }, 
      function () {
            $(this).find('.rsslink').css('visibility', 'hidden');
            $(this).css('background', 'none');
      }
    );

});

