$(document).ready(function() {
	// Vorbereitung für Projektwechsel
	klick = false;
	$("#vorschaubildlinks").append("<ul class=\"keineliste projektliste clearfix\"></ul>");
	$("#vorschaubild a[class*='vorschau']").each(function(i) {
		var j = i+1;
		var html = "<li><a rel=\""+j+"\" class=\"projektwechsel\">"+j+"</a></li>";
		$("#vorschaubildlinks ul.projektliste").append(html);
	});
	var titel = $("#vorschaubild a.vorschau-1").attr("title");
	var href = $("#vorschaubild a.vorschau-1").attr("href");
	$("#vorschaubild #vorschaubildInformation").html("<p class=\"kleiner keinrahmen\">"+ titel +" (<a href=\""+ href +"\">"+ href +"</a>)</p>");
	$("a.projektwechsel[rel*='1']").addClass("aktiv");
	
	// Ausführung des Projektwechsel
	$("a.projektwechsel").click(function() {
		var rel = $(this).attr("rel");
		klick = true;
		projektwechsel(rel);
	});
	
	
	$("#vorschaubild a[class*='vorschau']").each(function(i) {
		var j = i+1;
		var k = i+2;
		var vorschaubildWechsel = setTimeout(function() {
			var anzahlProjekte = parseInt($("#vorschaubild a[class*='vorschau']").size());
			if(j != anzahlProjekte && klick !== true) {
				projektwechsel(k);
			}
		}, 5000*j);
	});
	
	function projektwechsel(rel) {
		$("a.projektwechsel").removeClass("aktiv");
		$("#vorschaubildlinks a.projektwechsel[rel*='"+rel+"']").addClass("aktiv");
		var anzahlProjekte = parseInt($("#vorschaubild a[class*='vorschau']").size());
		var naechstesRel = parseInt(rel)+1;
		var vorherigesRel = parseInt(rel)-1;
		if(rel == anzahlProjekte) {
			naechstesRel = 1;
		}
		if(vorherigesRel == 0) {
			vorherigesRel = anzahlProjekte;	
		}
		var titel = $("#vorschaubild a.vorschau-"+rel).attr("title");
		var href = $("#vorschaubild a.vorschau-"+rel).attr("href");
		$("#vorschaubild a").fadeOut(1200);
		$("#vorschaubild #vorschaubildInformation").fadeOut(600);
		$("#vorschaubild a.vorschau-"+rel).fadeIn(1200);
		var vorschaubildInformation = setTimeout(function() {
			$("#vorschaubild #vorschaubildInformation").html("<p class=\"kleiner keinrahmen\">"+ titel +" (<a href=\""+ href +"\">"+ href +"</a>)</p>");
			$("#vorschaubild #vorschaubildInformation").fadeIn(600);
		}, 600);
		$("a.vorheriges-projekt").attr("rel",vorherigesRel);
		$("a.naechstes-projekt").attr("rel",naechstesRel);	
	}
	
	// png Fix
	$(document).pngFix();
});


