Array.prototype.has=function(v){
	for (i=0;i<this.length;i++){
		if (this[i]==v) return true;
	}
	return false;
}


function initIMGTitles() {
	$(".dn-sf-frontend a").each(function() {
		var myTitle = $(this).attr("title");
		$(this).find("img").attr("title", myTitle);
	})

}

function setCheckedOpacity() {
	// Alles was nicht angehakt ist, wird unsichtbar
	$(".dn-sf-frontend input[name^='sf']").each(function(n) {
    	var cssClass = $(this).val();
		if (!$(this).attr("checked")) {
			$("." + cssClass).css({ "display" : "inline" });
		}
	});

	// Alle Klassen die nötig sind für den UND Filter werden gesammelt
	var andClass = [];
	$(".dn-sf-frontend input[name^='sf']").each(function(n) {
		if ($(this).attr("checked")) andClass.push($(this).val());
	});
	
	// Durchlaufe alle IDs der Linken Seite die mit ART beginnen und check auf vorhandene Klassen
	var n = 0;
	$(".dn-sf-frontend span[id^='art']").each(function() {

		// Wenn alle klassen aus andClass vorhanden sind - sichtbar
		// Welche Klassen hat diese ID
		var me = $(this).attr("class");
		// Alle Klassennamen dieser ID in ein Array
		me = me.split(" ");
		// Bool ob erfüllt oder nicht
		var tf = true;


		$.each(andClass, function(i,v) {
			if (!me.has(v)) tf = false; // Wenn ein Begriff aus andClass nicht vorkommt -> tf auf false und somit nicht sichtbar machen
		});

		// Sind alle Begriffe in andClass vorhanden -> sichtbar machen		
		if (tf) {
			$(this).addClass("active");
			$(this).removeClass("off");
			$(this).stop().animate({ "opacity" : "1" },2000);

			n++;
		} else {
			$(this).removeClass("active");
			$(this).addClass("off");
			$(this).stop().animate({ "opacity" : "0.2" },1000);

		}
	});
	//reset digibox
	resetDigibox();
}


// -> ALLE UNSICHTBAR

function setCheckedVisible() {
	// Alles was nicht angehakt ist, wird unsichtbar
	$(".dn-sf-frontend input[name^='sf']").each(function(n) {
    	var cssClass = $(this).val();
		if (!$(this).attr("checked")) {
			$("." + cssClass).stop().slideUp(100);
			$(this).removeClass("active");
		}
	});

	// Alle Klassen die nötig sind für den UND Filter werden gesammelt
	var andClass = [];
	$(".dn-sf-frontend input[name^='sf']").each(function(n) {
		if ($(this).attr("checked")) andClass.push($(this).val());
	});
	
	// Durchlaufe alle IDs der Linken Seite die mit ART beginnen und check auf vorhandene Klassen
	var n = 0;
	$(".dn-sf-frontend span[id^='art']").each(function() {

		// Wenn alle klassen aus andClass vorhanden sind - sichtbar
		// Welche Klassen hat diese ID
		var me = $(this).attr("class");
		// Alle Klassennamen dieser ID in ein Array
		me = me.split(" ");
		// Bool ob erfüllt oder nicht
		var tf = true;


		$.each(andClass, function(i,v) {
			if (!me.has(v)) tf = false; // Wenn ein Begriff aus andClass nicht vorkommt -> tf auf flase und somit nicht sichtbar machen
		});

		// Sind alle Begriffe in andClass vorhanden -> sichtbar machen		
		if (tf) {
			$(this).stop().delay(120).slideDown();
			$(this).addClass("active");
			n++;
		};
	});
	resetDigibox();
}

function doHider() {
	if ($(".dn-sf-frontend input[name='ausblenden']").attr("checked")) {
    	setCheckedVisible();
    } else {
    	setCheckedOpacity();
	}
}


function resetRadioButtons() {
	$('.dn-sf-frontend a[title="reset"]').click(function() {
		$('.dn-sf-frontend input[type="radio"]:checked').removeAttr("checked");
		doHider();
	});

}

function doFrontEndNormal() {
	initIMGTitles();
	resetRadioButtons();


	$(".dn-sf-frontend input[name^='sf'], .dn-sf-frontend input[name='ausblenden'], ").click(function(){
		doHider()
	});
//    $(".dn-sf-frontend .right label, .dn-sf-frontend .right input").wrap("<span style=\"clear\" />");

    
    
    
    /* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
	$("#art_1025, #art_1024, #art_1021").html("");
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
/* ACHTUNG DEVELOPMENTSTEINE  */ 
}

function resetDigibox() {
	//$("body").doDigitalNoisesBox(".uebersicht span.active a" , "href");// Umgebender Kasten / 
//$("body").doDigitalNoisesBox("body" , "href");// Umgebender Kasten / 

		//var select = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"]');
		
		$(".dn-sf-frontend a[rel='fancybox']").removeAttr("rel");

		$(".dn-sf-frontend a").each(function() {
			var myalt = $(this).find("img").attr("alt");
			$(this).attr("title", myalt);
		});
		
		var select = $('.dn-sf-frontend .active a[href$=".jpg"]');

		select.attr('rel', 'fancybox');

		select.fancybox();
	
}


jQuery(document).ready(function() {
	doFrontEndNormal();
	resetDigibox()
});

















// **************************** OLD DURATION EXPERIMENT
/*
function setCheckedVisible_verz() {
	var duration = 100;
	$(".dn-sf-frontend input[name^='sf']").each(function(n) {
			$("." + cssClass).stop().delay(n * duration).slideUp(100);
		rows = n;
	});

}
*/
