/* ON LOAD */
$(document).ready(function(){
	if ($("#profile-table").hasClass("rating-form")) {
		$("input[name^='rating']:radio").hide();
		// Container-Zellen-Klasse ändern
		$('table.rating-form').addClass('eyeimg');
		$('table.rating-form td.label').addClass('eyeimg');
	}
	setTimeout("replaceEyes()", 100);

// === TICKER
	if(jQuery.browser.safari){
		 divScroller("ticker", "h", 30, 3000);
	}
	else if(jQuery.browser.mozilla){
		if (navigator.appVersion.indexOf("Mac")!=-1) {
			divScroller("ticker", "h", 1, 3000);
		}
		else {
			divScroller("ticker", "h", 30, 3000);
		}
	}
	else{
		 divScroller("ticker", "h", 16, 3000);
	}

	// Set external links
	setExternalLinks();
	
	// Random Flash-Headers
	if ($('#header1').length > 0) {
		
		var headers = randomHeaders.split(",");

		var headersLeft = new Array(
			new Array("1"),
			new Array("2"),
			new Array("3"),
			new Array("4"),
			new Array("5"),
			new Array("6"),
			new Array("7"),
			new Array("8")
		);

		$(document).everyTime(2000, function(i) {
			// Zufallszahl ermitteln
			var thisRandomHeader = $.random((headersLeft.length-1));
			var outputHeader = headersLeft[thisRandomHeader];
			headersLeft.splice(thisRandomHeader,1);

			$('#header-movie-container'+outputHeader+' img').remove();
			playPlayFlash(outputHeader);
		}, 8);
	}
	
	// Init fading in header
	$('#header-klartext-info2').addClass("js");
	var activeInfo = 1;
	$(document).everyTime(8000, function(i) {
		if (activeInfo == 1) {
			$("#header-klartext-info1").fadeOut({
			duration: 1700,
			queue: "global"
			});
			
			$("#header-klartext-info2").fadeIn({
			duration: 1700,
			queue: "global"
			});
			activeInfo = 2;
		}
		else if (activeInfo == 2) {
			$("#header-klartext-info2").fadeOut({
			duration: 1700,
			queue: "global"
			});
			
			$("#header-klartext-info1").fadeIn({
			duration: 1700,
			queue: "global"
			});
			activeInfo = 1;
		}
	}, 0);
	
	// Init slideshow in klartext header
	if ($('#header-klartext').length > 0) {
		$('#header-klartext').removeClass("noscript");
		$('#header-klartext').addClass("jcarousel-skin-tango");
		$('#header-klartext').jcarousel({
			scroll: 1,
			easing: 'easeInOutExpo'
		});
	}
	
	// Hide & show quicklinks
	$("#quicklinks").hide();
	$("#button-quicklinks").click(function () {
		$(this).toggleClass("active");
		$("#quicklinks").slideToggle("slow",function() {
				$.scrollTo('max');
    });
		return false;
  });
	
	// Panels
	if ($('#box-panel-udm').length > 0) {
		// Accordions
		$('#box-panel-udm').accordion({
			header: 'h2',
			active: 1,
			autoheight: false
		});
	}
	
	// Profile
	// Ausgangspunkt: alles zugeklappt, erstes offen
	$('#profile-table tbody tr:not(.profile-panel, .maincomment)').toggle();
	$('#profile-table tbody tr.profile-panel:first').siblings().toggle();
		
	// Bei Klick auf ein Element: togglen
	var oldPanel = $('#profile-table tbody tr.profile-panel:first');
	$(function(){
		$('#profile-table tbody tr.profile-panel').click(function() {
			$(this).siblings().toggle();
			$(oldPanel).siblings().toggle();
			oldPanel = this;
		})
	});
	
	// Search & Autocomplete
	$("#searchword").click(function () {
		if ($("#searchword").val() == 'Firma') {
			this.value = '';
		}
  });
	$("#searchwhere").click(function () {
		if ($("#searchwhere").val() == 'Chef') {
			this.value = '';
		}
  });
	$("#searchword").keydown(function () {
		selectItemWord(true);
  });
	$("#searchwhere").keydown(function () {
		selectItemWhere(true);
  });
	$("#searchword").autocomplete("lib/lib.ajax.php", {
		minChars:1,
		matchSubset:0,
		matchContains:1,
		maxItemsToShow:10,
		cacheLength:10,
		onItemSelect:selectItemWord,
		formatItem:formatItem,
		selectOnly:false,
		width:385,
		delay:100,
		extraParams: {
			func:'autocomplete',
			mode:'searchword'
		}
	});
	
	if (loginStatus == true) {
		$("#searchwhere").autocomplete("lib/lib.ajax.php", {
			minChars:1,
			matchSubset:0,
			matchContains:1,
			maxItemsToShow:10,
			cacheLength:10,
			onItemSelect:selectItemWhere,
			formatItem:formatItem,
			selectOnly:false,
			width:385,
			delay:100,
			extraParams: {
				func:'autocomplete',
				mode:'searchwhere'
			}
		});
	}
													 
	// Bewertungsformulare Autofill/Autocomplete
	if ($('#ratingStreet').length > 0 && !$('fieldset.noauto').length) {
		$("#ratingCompany").autocomplete("lib/lib.ajax.php", {
			minChars:1,
			matchSubset:0,
			matchContains:1,
			maxItemsToShow:10,
			cacheLength:10,
			onItemSelect:autofillComp,
			formatItem:formatItem,
			selectOnly:false,
			width:275,
			delay:100,
			extraParams: {
				func:'autocomplete',
				mode:'company'
			}
		});
	}
	
	$("#ratingLastname").autocomplete("lib/lib.ajax.php", {
		minChars:1,
		matchSubset:0,
		matchContains:1,
		maxItemsToShow:10,
		cacheLength:10,
		onItemSelect:autofillBoss,
		formatItem:formatItem,
		selectOnly:false,
		width:275,
		delay:100,
		extraParams: {
			func:'autocomplete',
			mode:'lastname'
		}
	});
	
	if ($('#ratingStreet').length > 0) {
		var autoFieldsComp = new Array("Sector", "Street", "Postcode", "City", "Website");
		$.each(autoFieldsComp, function() {
			var paramMode = this.toLowerCase();
			$("#rating"+this).autocomplete("lib/lib.ajax.php", {
				minChars:1,
				matchSubset:0,
				matchContains:1,
				maxItemsToShow:10,
				cacheLength:10,
				onItemSelect:selectItemAuto,
				formatItem:formatItem,
				selectOnly:1,
				width:275,
				delay:100,
				extraParams: {
					func:'autocomplete',
					mode:paramMode
				}
			});
		});
	}
	
	if ($('#ratingLastname').length > 0) {
		var autoFieldsBoss = new Array("Firstname", "Company", "Sector", "Department", "Postcode", "City", "Email");
		$.each(autoFieldsBoss, function() {
			var paramMode = this.toLowerCase();
			$("#rating"+this).autocomplete("lib/lib.ajax.php", {
				minChars:1,
				matchSubset:0,
				matchContains:1,
				maxItemsToShow:10,
				cacheLength:10,
				onItemSelect:selectItemAuto,
				formatItem:formatItem,
				selectOnly:1,
				width:275,
				delay:100,
				extraParams: {
					func:'autocomplete',
					mode:paramMode
				}
			});
		});
	}
	
	// Lightbox
	/*$('a[rel*=lightbox]').lightBox({
		overlayOpacity: 0.6,
		imageLoading: 'scripts/jquery-lightbox/images/loading.gif',
		imageBtnClose: 'scripts/jquery-lightbox/images/close.gif',
		imageBtnPrev: 'scripts/jquery-lightbox/images/prev.gif',
		imageBtnNext: 'scripts/jquery-lightbox/images/next.gif',
		txtImage: 'Imagem',
		txtOf: 'de'
  });*/
	
	// Lightbox
	if ($("a[rel*=lightbox]").length > 0) {
		$("a[rel*=lightbox]").fancybox({
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'titlePosition' 	: 'inside',
			'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-inside">Bild ' +  (currentIndex + 1) + ' / ' + currentArray.length + '<br>' + title + '</span>';
			}
		});
	}
	
	if ($("a.videolink").length > 0) {
		var msrc = '';
		var mdata = '';
		$("a.videolink").click(function () {
			msrc = $(this).parent().attr("title");
			mdata = $(this).parent().attr("rel").split("#");
		});
		
		$("a.videolink span.video-play").each(function(){
			$(this).width($(this).prev("img").width()+6);
		});
		
		$("a.videolink").fancybox({
		 autoScale: false,
		 autoDimensions: false,
		 overlayShow: true,
		 overlayOpacity: 0.7,
		 onStart: function() {
				var flashvars = {
					file: "../videos/ag/"+msrc,
					//image: "images/ag-stills/600/"+mdata[3],
					showdigits: "false",
					autostart: "true",
					showfsbutton: "false",
					fullscreen: "false",
					repeat: "false",
					backcolor: "0x243D53",
					frontcolor: "0xffffff",
					lightcolor: "0xB8DC27"
				};
				var params = {
					allowfullscreen: "false",
					allowscriptaccess: "always",
					wmode: "transparent"
				};
				var attributes = {
					id: "ag-video-"+mdata[0]
				};
				swfobject.embedSWF("flash/flvplayer.swf?t="+new Date().getTime(), "ag-video-"+mdata[0], mdata[1], mdata[2], "9.0.0", "flash/expressInstall.swf", flashvars, params, attributes);
		 },
		 onCleanup: function() {
				$("#ag-video-"+mdata[0]).replaceWith('<div id="ag-video-'+mdata[0]+'"></div>'); 
		 },
		 onComplete: function() {
				$("#fancybox-inner, #fancybox-wrap").animate({
					height: (parseInt(mdata[2])+20),
					width: (parseInt(mdata[1])+20)
				},
				{duration: 300,
				queue: true});

				$("#fancybox-wrap").animate({
					left: (($(window).width() - (parseInt(mdata[1])))/2)-30
				},
				{duration: 300,
				queue: true});
		 }
		});
	}
	
	// Störer
	$("#button").mouseover(function () {
		$("#button").attr({ 
     	src: "images/header-button-over.png"
    });
  });
	$("#button").mouseout(function () {
		$("#button").attr({ 
     	src: "images/header-button.png"
    });
  });
	
	// Carousel im AG
	if ($(".profile-carousel.jcarousel-skin-profile").length > 0) {	
		$(".profile-carousel.jcarousel-skin-profile").jcarousel({
			itemFallbackDimension: 100																			
		});
	}
	
	if ($(".profile-carousel.jcarousel-skin-profile-col1").length > 0) {
		$(".profile-carousel.jcarousel-skin-profile-col1").jcarousel({
				scroll: 1,
				easing: 'easeInOutExpo'
		});
	}
	
	if ($(".jcarousel-skin-profile").length > 0) {
		//alert();
		$(".jcarousel-skin-profile ul li p").each(function(){
			$(this).width($(this).prev("a").width());
		});
	}

	// Accordion im AG
	if ($('#box-panel-ag').length > 0) {
		var activepanel = $(document).getUrlParam("activepanel");
		// Accordion
		$('#box-panel-ag h2').click(function() {
			$(this).next().slideToggle('slow');
			$(this).toggleClass("open");
			return false;
		}).next(":not(.profile, ."+activepanel+")").hide();
		
		$("#box-panel-ag h2.profile, #box-panel-ag h2."+activepanel).toggleClass("open");
		$.scrollTo("h2."+activepanel);
	}
	
	if ($('table.tabelle-ratingcomments').length > 0) {
		// Accordion
		$('table.tabelle-ratingcomments tr.rating-panel-head th, table.tabelle-ratingcomments tr.rating-panel-head-comment th').not("th.button-left").click(function() {
			$(this).parent().nextUntil("tr.rating-panel-head").not("tr.rating-panel-head-comment").filter('tr.maincat, tr.maincat-comment').toggle();
			$(this).parent().nextUntil("tr.rating-panel-head").not("tr.rating-panel-head-comment").filter('tr.subcat').hide();
			//$(this).parent().toggleClass("open");
			return false;
		}).parent().nextAll(":not(.rating-panel-head, .rating-panel-head-comment)").hide();
		
		$('table.tabelle-ratingcomments tr.maincat td, table.tabelle-ratingcomments tr.maincat-comment td').not("td.button-left").click(function() {
			$(this).parent().nextUntil("tr.maincat").not("tr.maincat-comment").toggle();
			//$(this).parent().nextAll("tr.maincat:first").toggleClass("maincat-active");
			return false;
		});
	}
	
	// Funktion LÖSCHEN im AG
	$('a.delete').click(function() {
		var conf = confirm('Möchten Sie diesen Datensatz wirklich löschen?');
		return conf;
	});
	
	/*// Funktion BEARBEITEN im AG
	$('a.edit').after('<img src="images/icon-edit.gif" class="editimg">');
	$('img.editimg').click(function() {
		
	});*/
	
});

/* PASSWORD STRENGTH */
var updateStrength = function(pw) {
	var strength = getStrength(pw);
	var barWidth = (100/32)*strength;
	var xyz = 100;

	$("#psStrength").animate({ width: Math.ceil(barWidth)+"px" }, 600 );

}

var getStrength = function(passwd) {
	intScore = 0;
	
	// [verified] at least one lower case letter
	if (passwd.match(/[a-z]/)) {
		intScore = (intScore+1)
	}
	// [verified] at least one upper case letter
	if (passwd.match(/[A-Z]/)) {
		intScore = (intScore+1)
	}
	
	// NUMBERS
	// [verified] at least one number
	if (passwd.match(/\d+/)) {
		intScore = (intScore+1)
	}
	// [verified] at least two numbers
	if (passwd.match(/(\d.*\d)/)) {
		intScore = (intScore+3)
	}
	
	// SPECIAL CHAR
	// [verified] at least one special character
	if (passwd.match(/[!,@#$%^&*?_~]/)) {
		intScore = (intScore+1)
	}
	// [verified] at least two special characters
	if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) {
		intScore = (intScore+3)
	}
	
	// COMBOS
	// [verified] both upper and lower case
	if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) {
		intScore = (intScore+5)
	}
	// [verified] both letters and numbers
	if (passwd.match(/\d/) && passwd.match(/\D/)) {
		intScore = (intScore+5)
	}
	
	// [Verified] Upper Letters, Lower Letters, numbers and special characters
	if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/)){
		intScore = (intScore+5)
	}
	
	// Add the length of the password to the score, if it is a long password.
	if (passwd.length >= 10) {
		intScore = (intScore+passwd.length) 
	}
	else {
		// Remove some points if it is a very short password
		if(passwd.length <= 6) {
			intScore = (intScore-(intScore/2)) 
		}
		// Add factor 0.33 for each letter
		else {
			intScore = (intScore+(passwd.length*0.33)) 
		}
	}
	
/*	
	// Only characters from one set of characters used, having less than 10 characters
	if ((passwd.match(/[a-z]/) || passwd.match(/[A-Z]/) || passwd.match(/[0-9]/) || passwd.match(/[!,@#$%^&*?_~]/)) && passwd.length <= 10) {
		intScore = (intScore+1)
	}
*/
	
	if (intScore > 32) {
		intScore = 32
	}
	if (intScore < 0) {
		intScore = 0
	}

	return intScore;
}

/* EXTERNAL LINKS */
function setExternalLinks() {
	if (!document.getElementsByTagName) {
		return null;
	}
	var anchors = document.getElementsByTagName("a");
	for (var i=0;i < anchors.length;i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.className.search(/external-link-new-window/) != -1)) {
			anchor.setAttribute("target", "blank");
		}
	}
	var maps = document.getElementsByTagName("area");
	for (var i=0;i < maps.length;i++) {
		var map = maps[i];
		if (map.getAttribute("href") && (map.getAttribute("rel") == "external" || map.className.search(/external-link-new-window/) != -1)) {
			map.setAttribute("target", "blank");
		}
	}
}

/* HELPER FUNCTIONS */
function formatItem(row, i, num, field) {
	var termOriginal = $(field).val();
	var term = termOriginal.replace(/["']/gi, "");
	var value = row[0];
	var qq=eval('/('+term+')/gi');
	//alert( term + '-' + qq);
	return value.replace(qq, "<strong>$1</strong>");
}

function selectItemWord(keypressed, input, v) {
	var curTerm = $("#searchword").val();
	$("#searchword").val(curTerm.replace(/&#44;/gi, ","));
	$("#searchwhere").val('Chef');
	if (keypressed != true) {
		//$("#searchsubmit").focus();
		$("#quicksearch").submit();
	}
}

function selectItemWhere(keypressed, input, v) {
	var curTerm = $("#searchwhere").val();
	$("#searchwhere").val(curTerm.replace(/&#44;/gi, ","));
	$("#searchword").val('Firma');
	if (keypressed != true) {
		//$("#searchsubmit").focus();
		$("#quicksearch").submit();
	}
}

function selectItemAuto(li, input, v) {
	var curTerm = input.value;
	input.value = curTerm.replace(/&#44;/gi, ",");
}

function autofillComp(li, input, v) {
	var q = v.replace(/&#44;/gi, ",");
	$("#ratingCompany").val(q);
	$.ajax({
   type: "GET",
	 cache: false,
	 dataType: "xml",
   url: "lib/lib.ajax.php",
   data: "func=autofill&mode=comp&q="+escape(q)+"&id="+escape(li.extra[1])+"&db="+escape(li.extra[2]),
   success: function(xmlDocument) {
		 var fields2fill = new Array("fakefirst", "Sector", "Street", "Postcode", "City", "Country", "Website", "CompanySize");
     autofillRatingForm(xmlDocument, fields2fill);
   }
 });
}

function autofillBoss(li, input, v) {
	var q = v.replace(/&#44;/gi, ",");
	$("#ratingLastname").val(q);
	$.ajax({
   type: "GET",
	 cache: false,
	 dataType: "xml",
   url: "lib/lib.ajax.php",
   data: "func=autofill&mode=boss&q="+escape(q)+"&id="+escape(li.extra[1]),
   success: function(xmlDocument) {
		 var fields2fill = new Array("fakefirst", "Firstname", "Gender", "Company", "Sector", "Department", "Postcode", "City", "Country", "Email");
     autofillRatingForm(xmlDocument, fields2fill);
   }
 });
}

function autofillRatingForm(xmlDocument, fields2fill) {
	//alert(xmlDocument);
	// Alle, die ausgefüllt werden müssen, leeren
	$.each(fields2fill, function() {
		$("#rating"+this ).val('');
	});
	$("#ratingImage").replaceWith('<input id="ratingImage" type="file" tabindex="90" name="ratingImage"/>');
	if ($('img#agimg').length > 0) {
		$('img#agimg').remove();
		$('input#ratingImageName').remove();
	}
	
	for(var i=0; i< xmlDocument.getElementsByTagName("el").length; i++) {
		var base = xmlDocument.getElementsByTagName("el")[i];
		var autovalue = base.getElementsByTagName("autovalue")[0].firstChild.nodeValue;
		var keyUCFirst = base.getElementsByTagName("keyUCFirst")[0].firstChild.nodeValue;
		var mode = base.getElementsByTagName("mode")[0].firstChild.nodeValue;
		if (mode == 'comp') {
			var imgFolder = 'companies';
		}
		else if (mode == 'boss') {
			var imgFolder = 'bosses';
		}
		//alert(key+" - "+autovalue);
		// Werte in die Felder einsetzen
		if ($.inArray(keyUCFirst, fields2fill) != -1 && autovalue != '-') {
			$("#rating"+keyUCFirst).val(autovalue);
		}
		else if (keyUCFirst == 'Image' && (autovalue.substr(0,3) != 'no_' && autovalue != '-') && $('label#ag').length == 0) {
			$("#ratingImage").replaceWith('<p id="ratingImage">Bild bereits vorhanden</p>');
		}
		else if (keyUCFirst == 'Image' && (autovalue.substr(0,3) != 'no_' && autovalue != '-') && $('label#ag').length > 0) {
			$("#ratingImage").after('<img src="images/'+imgFolder+'/100/'+autovalue+'" id="agimg" /><input type="hidden" name="ratingImageName" id="ratingImageName" value="'+autovalue+'" />');
			$("img#agimg").error(function(){ 
				$(this).hide();
			}); 
		}
	} // for
}

function ratingEyesMouseOver(ID, newImage) {
	$('img#'+ID).attr({ 
		src: newImage
	});
}

function recalcAvgMainPoints(mainCatName) {
	// Alle Werte für diese Hauptkategorie holen
	var addMainPoints = 0;
	
	jQuery.each($("td[class^='prof-info sub "+mainCatName+"']"), function(n, el) {
		if ($(el).text()) {
			addMainPoints += parseInt($(el).text());
		}
	});
	
	var avgMainPoints = (addMainPoints/$("td[class^='prof-info sub "+mainCatName+"']").length).toFixed(1);

	if (avgMainPoints > 0) {
		return avgMainPoints;
	}
	else {
		return "";
	}
}

function replaceEyes() {

	// === REPLACEMENT of radios in rating forms
	if ($("#profile-table").hasClass("rating-form")) {
		// Container-Zellen-Klasse ändern
		$('table.rating-form').addClass('eyeimg');
		$('table.rating-form td.label').addClass('eyeimg');
		
		// Durch die Radios bewegen (SUBCATS)
		jQuery.each($("input:radio"), function(i, e) {
      
			// Daten abspeichern
			var thisImgID = $(e).attr("id")+"_img";
			var thisRadioPoints = $(e).val();
				
			// Input ausblenden
			//$(e).hide();
			
			// Die Bezeichnung des übergeordneten Punktes feststellen
			var nameParts = $(e).attr("name").split("_");
			var mainCatName = nameParts[0]+'_'+nameParts[1]+'_';
			
			// Die "kA"-Buttons haben ein anderes Bild
			if ($(e).val() == 0) {
				
				$(e).after("<img src=\"images/eye-na-disabled.png\" id=\""+thisImgID+"\" class=\"first\" alt=\"\">");
				
				// Initial highlighten
				// Auslesen, welches Feld gerade angecheckt ist
				checkedRightNow = $("input[name='"+$(e).attr("name")+"']:checked").val();
				if (checkedRightNow < 1 || !checkedRightNow) {
					$('img#'+thisImgID).attr({ 
						src: "images/eye-na-enabled.png"
					});
					$('#'+$(e).attr("id")).attr("checked","checked");
					
					// Wert ausgeben
					$("td.prof-info."+$(e).attr("name")).text("");
				}
				
				// Mouseover
				$('img#'+thisImgID).mouseover(function () {
					$('img#'+thisImgID).attr({ 
						src: "images/eye-na-enabled.png"
					});
				});
				
				// Mouseout
				$('img#'+thisImgID).mouseout(function () {
					checkedRightNow = $("input[name='"+$(e).attr("name")+"']:checked").val();
					// Nur zurücksetzen, wenn diese Option nicht ausgewählt ist
					if (checkedRightNow > 0 && checkedRightNow != 'undefined') {
						$('img#'+thisImgID).attr({ 
							src: "images/eye-na-disabled.png"
						});
					}
				});
				
				// Click
				$('img#'+thisImgID).click(function () {
					// Das entsprechende Radio-Feld checken
					$('#'+$(e).attr("id")).attr("checked","checked");
					checkedRightNow = $(e).val();
					
					// Alle ausgrauen
					for (var y=5; y>0; y--) {
						$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
					}
					
					// Wert ausgeben
					$("td.prof-info."+$(e).attr("name")).text("");
					
					// Wert in der Hauptcat. ausgeben
					var mainPoints = recalcAvgMainPoints(mainCatName);
					$("td.prof-info."+mainCatName).text(mainPoints);
					
					// In der Hauptkategorie alles ausgrauen
					for (var y=5; y>=1; y--) {
						$('img#'+mainCatName+"_"+y+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
					}
					// Und die Relevanten wieder einblenden
					for (var y=1; y<=Math.round(mainPoints); y++) {
						$('img#'+mainCatName+"_"+y+"_img").attr({ 
							src: "images/eye-rating-enabled.png"
						});
					}
					
					if (mainPoints <= 0) {
						$('img#'+mainCatName+"_0_img").attr({ 
							src: "images/eye-na-enabled.png"
						});
					}
				});
			}
			
			// Normale Buttons
			else {
				// Alle mit Bild ersetzen
				$(e).after("<img src=\"images/eye-rating-disabled.png\" id=\""+thisImgID+"\" alt=\"\">");
				
				// Mouseover
				$('img#'+thisImgID).mouseover(function () {
					// Alle, die kleiner sind, mit highlighten!
					for (var y=1; y<=thisRadioPoints; y++) {
						$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
							src: "images/eye-rating-enabled.png"
						});
					}
				});
				
				// Mouseout
				$('img#'+thisImgID).mouseout(function () {
					
					// Auslesen, welches Feld gerade angecheckt ist
					checkedRightNow = $("input[name='"+$(e).attr("name")+"']:checked").val();
					
					// Wenn gerade ein Feld angecheckt ist, darf der Mouseout nur maximal bis zu diesem Feld gehen
					if (checkedRightNow) {
						maxY = checkedRightNow;
					}
					else {
						maxY = 0;
					}

					// Ansonsten muss alles ausgegraut werden
					for (var y=5; y>maxY; y--) {
						$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
					}
				});
				
				// Click
				$('img#'+thisImgID).click(function () {
					// Das entsprechende Radio-Feld checken
					$('#'+$(e).attr("id")).attr("checked","checked");
					checkedRightNow = $(e).val();
					
					// Alle ausgrauen, die größer sind
					for (var y=5; y>$(e).val(); y--) {
						$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
					}
					
					// Auch den Nuller ausgrauen
					$('img#'+$(e).attr("name")+"_0_img").attr({ 
						src: "images/eye-na-disabled.png"
					});
					
					// Wert ausgeben
					$("td.prof-info."+$(e).attr("name")).text(checkedRightNow);
					
					// Wert in der Hauptcat. ausgeben
					var mainPoints = recalcAvgMainPoints(mainCatName);
					$("td.prof-info."+mainCatName).text(mainPoints);
					
					// In der Hauptkategorie alle ausgrauen
					for (var y=5; y>=1; y--) {
						$('img#'+mainCatName+"_"+y+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
					}
					$('img#'+mainCatName+"_0_img").attr({ 
						src: "images/eye-na-disabled.png"
					});
					// Und die Relevanten wieder einblenden
					for (var y=1; y<=Math.round(mainPoints); y++) {
						$('img#'+mainCatName+"_"+y+"_img").attr({ 
							src: "images/eye-rating-enabled.png"
						});
					}
				});
			}
		});
		
		// Augen generieren (MAINCATS)
		jQuery.each($("input.rating-main-hidden"), function(i, e) {
			
			// "kA"-Bild anlegen
			var thisImgID = $(e).attr("id")+"_0_img";
			$(e).before("<img src=\"images/eye-na-disabled.png\" id=\""+thisImgID+"\" class=\"first\" alt=\"0\">");
			
			// SUBCATS: Initial highlighten
			// Alle zugehörigen SUB-Felder auslesen
			var subFields = $("input[name^='"+$(e).attr("name")+"']:checked");
			// SUB-Felder durchlaufen
			jQuery.each(subFields, function(m, subfield) {
				// Auslesen, welches Feld gerade angecheckt ist
				checkedRightNow = $(subfield).val();
				
				if (checkedRightNow && checkedRightNow > 0) {
					for (var y=1; y<=checkedRightNow; y++) {
						$('img#'+$(subfield).attr("name")+"_"+y+"_img").attr({ 
							src: "images/eye-rating-enabled.png"
						});
					}
					
					// Wert ausgeben
					$("td.prof-info."+$(subfield).attr("name")).text(checkedRightNow);
				}
				else {
					// Wert ausgeben
					$("td.prof-info."+$(subfield).attr("name")).text("");
				}
			});
			
			// Wert in der Hauptcat. ausgeben
			$("td.prof-info."+$(e).attr("name")).text(recalcAvgMainPoints($(e).attr("name")));
			
			// Initial highlighten
			// Auslesen, welcher Wert im Durchschnitt gesetzt ist
			checkedRightNow = recalcAvgMainPoints($(e).attr("name"));

			//checkedRightNow = checkedRightNow.toFixed(1);
			if (checkedRightNow == 0 || !checkedRightNow) {
				$('img#'+thisImgID).attr({ 
					src: "images/eye-na-enabled.png"
				});
				$("input[name='"+$(e).attr("name")+"']").val(0);
				checkedRightNow = 0;
			}
			
			// Mouseover
			$('img#'+$(e).attr("id")+"_0_img").mouseover(function () {
				ratingEyesMouseOver($(e).attr("id")+"_0_img", "images/eye-na-enabled.png");
			});
			
			// Mouseout
			$('img#'+$(e).attr("id")+"_0_img").mouseout(function () {
				checkedRightNow = $("#"+$(e).attr("name")).val();
				// Nur zurücksetzen, wenn diese Option nicht ausgewählt ist
				if (checkedRightNow > 0 && checkedRightNow != 'undefined') {
					$('img#'+$(e).attr("id")+"_0_img").attr({ 
						src: "images/eye-na-disabled.png"
					});
				}
			});
			
			// Click
			$('img#'+$(e).attr("id")+"_0_img").click(function () {
				// Wert abspeichern
				$("input[name='"+$(e).attr("name")+"']").val("0");
				checkedRightNow = "0";
				
				// Alle ausgrauen, die größer sind
				for (var y=5; y>0; y--) {
					$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
						src: "images/eye-rating-disabled.png"
					});
				}
				
				// Wert ausgeben
				$("td.prof-info."+$(e).attr("name")).text("");
				
				// SPEZIAL: Alle Unterkategorien vorauswählen
				jQuery.each($("input[name^='"+$(e).attr("name")+"']"), function(ii, ee) {
					// Die aktuelle Hauptkategorie ist dann aber mitausgewählt, das darf nicht sein
					if ($(ee).attr("name").length > $(e).attr("name").length) {

						// Das entsprechende Radio-Feld checken
						$('#'+$(ee).attr("name")+"_0").attr("checked","checked");
						
						// Alle ausgrauen
						$('img#'+$(ee).attr("id")+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
						
						// Alle Nuller-Felder highlighten
						$('img#'+$(ee).attr("name")+"_0_img").attr({ 
							src: "images/eye-na-enabled.png"
						});
						
						// Wert ausgeben
						$("td.prof-info."+$(ee).attr("name")).text("");
					}
				});
				
			});
		
			// Normale durchlaufen
			for (var z=1; z<=5; z++) {
				var thisImgID = $(e).attr("id")+"_"+z+"_img";
				
				$(e).before("<img src=\"images/eye-rating-disabled.png\" id=\""+thisImgID+"\" alt=\""+z+"\">");
				
				// Mouseover
				$('img#'+thisImgID).mouseover(function () {
					// Alle, die kleiner sind, mit highlighten!
					for (var y=1; y<=$(this).attr("alt"); y++) {
						ratingEyesMouseOver($(e).attr("id")+"_"+y+"_img", "images/eye-rating-enabled.png");
					}
				});
				
				// Mouseout
				$('img#'+thisImgID).mouseout(function () {
					
					// Auslesen, welches Feld gerade angecheckt ist
					checkedRightNow = $("input[name='"+$(e).attr("name")+"']").val();

					// Wenn gerade ein Feld angecheckt ist, darf der Mouseout nur maximal bis zu diesem Feld gehen
					if (checkedRightNow) {
						maxY = checkedRightNow;
					}
					else {
						maxY = 0;
					}

					// Ansonsten muss alles ausgegraut werden
					for (var y=5; y>maxY; y--) {
						$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
					}
				});
				
				// Click
				$('img#'+thisImgID).click(function () {
					// Wert abspeichern
					$("input[name='"+$(e).attr("name")+"']").val($(this).attr("alt"));
					checkedRightNow = $(this).attr("alt");
					// Alle ausgrauen, die größer sind
					for (var y=5; y>checkedRightNow; y--) {
						$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
							src: "images/eye-rating-disabled.png"
						});
					}
					
					// Auch den Nuller ausgrauen
					$('img#'+$(e).attr("name")+"_0_img").attr({ 
						src: "images/eye-na-disabled.png"
					});
					
					// SPEZIAL: Alle Unterkategorien vorauswählen
					var countEE = 0;
					jQuery.each($("input[name^='"+$(e).attr("name")+"']"), function(ii, ee) {
						// Die aktuelle Hauptkategorie ist dann aber mitausgewählt, das darf nicht sein
						if ($(ee).attr("name").length > $(e).attr("name").length) {
							countEE++;
							
							// Das entsprechende Radio-Feld checken
							$('#'+$(ee).attr("name")+"_"+checkedRightNow).attr("checked","checked");
							
							// Alle ausgrauen
							$('img#'+$(ee).attr("id")+"_img").attr({ 
								src: "images/eye-rating-disabled.png"
							});
							
							// Alle bis zum gewählten Feld wieder highlighten
							if ($(ee).val() <= checkedRightNow) {
								$('img#'+$(ee).attr("id")+"_img").attr({ 
									src: "images/eye-rating-enabled.png"
								});
							}
							
							// Auch den Nuller ausgrauen
							$('img#'+$(ee).attr("name")+"_0_img").attr({ 
								src: "images/eye-na-disabled.png"
							});
							
							// Wert ausgeben
							$("td.prof-info."+$(ee).attr("name")).text(checkedRightNow);
						}
					});
					
					// Wert berechnen & ausgeben
					$("td.prof-info."+$(e).attr("name")).text(checkedRightNow);
					
				});
			}
			
			// MAINCATS: Initial highlighten
			// Auslesen, welcher Wert im Durchschnitt gesetzt ist
			checkedRightNow = recalcAvgMainPoints($(e).attr("name"));
			if (checkedRightNow) {
				//alert(Math.round(checkedRightNow));
				for (var y=1; y<=Math.round(checkedRightNow); y++) {
					$('img#'+$(e).attr("name")+"_"+y+"_img").attr({ 
						src: "images/eye-rating-enabled.png"
					});
				}
			}
		});
	}
}
