


	//=============================================================================================== projektbox hover & p position
	
	$(".projekthoverbox, .headline, p").hover(function(){
		$(this).parent().children(".projekthoverbox").css({'background':'white'});
	}, function(){
		$(this).parent().children(".projekthoverbox").css({'background':'none'});
	});
	
	$("p").each(function(){
		var headlineheight = $(this).siblings(".headline").height() + 10 + "px";
		$(this).css({'top': headlineheight})
	});

	$(".view").each(function(){
		var paragraphheight = $(this).siblings("p").height() + $(this).siblings(".headline").not(".view").height() + 20 + "px";
		$(this).css({'top': paragraphheight})
	});

	//=============================================================================================== leere projektbox & home, impressum, links

	
	$(".projektbox:first").after("<div class='projektbox leer'></div>").children("b").remove();
	$(".projektbox:first").find(".headline").addClass("homebutton");
	
	$(".projektbox:last").children("b").remove();
	$(".projektbox:last").prev().children("b").remove();

	//=============================================================================================== Bilder an Position 0,0 setzen


	$("img").offset({ top: 0, left: 0 });
	
	
	//=============================================================================================== Startseitenbild anzeigen andere ausblenden & Random

	var zufall = Math.floor(Math.random()*5);
	
	var pfad = $("#projektboxencontainer>.projektbox:first-child").find(".projektbild").eq(zufall);
	

	
	$("#projektboxencontainer>.projektbox:first-child").find(".projektbild").eq(zufall).attr('src', pfad.attr("original")).removeAttr("original");
	
	
	$("img").not(pfad).hide();
	
	
	//=============================================================================================== click, cycle & load
	
	
	$(".headline").not("strong").append("<span class='positionsichtbar'></span><span class='gesamtanzahl'></span><span class='loader'></span>");	
	$("strong").append("<span class='loader'></span>");	

	$(".homebutton").click(function(){
		window.location = "http://www.stephangoeschl.com/"
		$(".homebutton").siblings("img").fadeIn(100);	
	});



	

		
	$(".headline").not(".homebutton").click(function(){
		
		
		$(this).parent().siblings().children(".sichtbar").removeClass("sichtbar");	
		
		$(this).not("strong").children(":first-child").html("NEXT &rarr;");
		$(".view").not(this).children(":first-child").html("VIEW &rarr;");
		
		
		if(!$(this).siblings("img:first").hasClass("geladen")){
			$(this).siblings("img:first").addClass("sichtbar");
			var loaderint = window.setInterval("$('.sichtbar').siblings('.headline').children('.loader').append('.')", 250);
			$(this).parent().siblings().children(".headline").children(".positionsichtbar, .gesamtanzahl").text("");
			
			$(".sichtbar").attr('src', $(".sichtbar").attr('original')).load(function(){
				$(".sichtbar").fadeIn(100);
				$(".sichtbar").addClass("geladen");
				$(this).parent().siblings().children("img").fadeOut(250);
				$(".homebutton").siblings("img").hide();
				window.clearInterval(loaderint);
				$(".loader").text("");
				
				positionsichtbar = $(this).index()-1;
				gesamtanzahl = $(this).siblings("img").length+1;
				
				$(this).siblings(".headline").children(".positionsichtbar").text(" " + positionsichtbar);
				$(this).siblings(".headline").children(".gesamtanzahl").text("/" + gesamtanzahl);
				
			});
		} 
		
		else if(($(this).siblings("img:first").hasClass("geladen")) && ($(this).siblings(".sichtbar").length == 0)){

				$(this).parent().siblings().children(".headline").children(".positionsichtbar, .gesamtanzahl").text("");
				
				$(this).siblings("img:first").addClass("sichtbar");
				$(".sichtbar").fadeIn(100);
				$(this).parent().siblings().children("img").fadeOut(250);
				$(".homebutton").siblings("img").hide();
				
				positionsichtbar = $(this).siblings(".sichtbar").index()-1;
				gesamtanzahl = $(this).siblings("img").length;
				
				$(this).children(".positionsichtbar").text(" " + positionsichtbar);
				$(this).children(".gesamtanzahl").text("/" + gesamtanzahl);
		}

		
		else {
		
			if($(this).siblings("img:last").hasClass("sichtbar")){

				$(this).parent().siblings().children(".headline").children(".positionsichtbar, .gesamtanzahl").text("");
				
				$(this).siblings("img:first").fadeIn(100);
				$(this).siblings("img:first").addClass("sichtbar");
				$(this).siblings("img:last").fadeOut(250);
				$(this).siblings("img:last").removeClass("sichtbar");
				$(this).parent().siblings().children("img").fadeOut(250);
				$(".homebutton").siblings("img").hide();
				
				positionsichtbar = $(this).siblings(".sichtbar").index()-1;
				gesamtanzahl = $(this).siblings("img").length;
				
				$(this).children(".positionsichtbar").text(" " + positionsichtbar);
				$(this).children(".gesamtanzahl").text("/" + gesamtanzahl);
				
			} else {
				
				if (!$(".sichtbar").next().hasClass("geladen")) {
						var loaderint = window.setInterval("$('.sichtbar').siblings('.headline').children('.loader').append('.')", 250);
						$(this).parent().siblings().children(".headline").children(".positionsichtbar, .gesamtanzahl").text("");
				
						$(".sichtbar").next().attr('src', $(".sichtbar").next().attr('original')).load(function(){
							$(".sichtbar").next().fadeIn(100);
							$(".sichtbar").next().addClass("geladen");
							$(".sichtbar").next().addClass("sichtbar");
							$(".sichtbar").prev().removeClass("sichtbar");
							$(".sichtbar").prev().fadeOut(250);
							$(this).parent().siblings().children("img").fadeOut(250);
							$(".homebutton").siblings("img").hide();
							window.clearInterval(loaderint);
							$(".loader").text("");
							
							positionsichtbar = $(this).index()-1;
							gesamtanzahl = $(this).siblings("img").length+1;
				
							$(this).siblings(".headline").children(".positionsichtbar").text(" " + positionsichtbar);
							$(this).siblings(".headline").children(".gesamtanzahl").text("/" + gesamtanzahl);
				
						});
				} else	{

						$(this).parent().siblings().children(".headline").children(".positionsichtbar, .gesamtanzahl").text("");
						
						$(".sichtbar").next().fadeIn(100);
						$(".sichtbar").next().addClass("geladen");
						$(".sichtbar").next().addClass("sichtbar");
						$(".sichtbar").prev().removeClass("sichtbar");
						$(".sichtbar").prev().fadeOut(250);
						$(this).parent().siblings().children("img").fadeOut(250);
						$(".homebutton").siblings("img").hide();
						
						positionsichtbar = $(this).siblings(".sichtbar").index()-1;
						gesamtanzahl = $(this).siblings("img").length;
				
						$(this).children(".positionsichtbar").text(" " + positionsichtbar);
						$(this).children(".gesamtanzahl").text("/" + gesamtanzahl);
					
					}
			}
		};
	});	
			
			
	//=============================================================================================== sichtbare Projektbox einblenden & andere ausblenden, visited
		
	
	$(".headline").not(".homebutton").click(function(){
		$(this).parent().addClass("visited");
		$(this).parent().siblings(".visited").css({"background":"url('')"});
		$(this).parent().siblings(".projektbox").children(".headline, p").not(".homebutton, .homebutton+p").fadeOut(100);
		
		$(this).parent().siblings().children(".visited").parent().css({"background":"url('http://stephangoeschl.com/ndxz-studio/site/js/visited.png')"});
	});
	
	$(".headline").not(".homebutton").mouseover(function(){
	
		$(this).parents(".visited").css({"background":"url('')"});
		
	}).mouseout(function(){
	
		$(".projektbox").children(".headline, p").not(".homebutton, .homebutton+p").fadeIn(100);
		$(this).parent().siblings(".visited").css({"background":"url('http://stephangoeschl.com/ndxz-studio/site/js/visited.png')"});

	});
	

	//=============================================================================================== fullscreen stuff

	$(".titel").each(function(){
		var titel = $(this).text();
		
		if(titel == "Movies"){
			$(this).parent().siblings("b").remove();
		}
		
	});




	function fullscreen() {

    	var imageAR = $(".projektbild").width()/$(".projektbild").height();

    	var documentwidth = $(window).width();
    	var documentheight = $(window).height();

    	var documentAR = documentwidth/documentheight;
    	if(documentAR > imageAR){
        	$(".projektbild").width(documentwidth);
        	$(".projektbild").height($(".projektbild").width()/imageAR);
   	 	} else {
       	 	$(".projektbild").height(documentheight);
        	$(".projektbild").width($(".projektbild").height()*imageAR);
    	}
	}
	
	fullscreen();
	
	
	$(window).resize(function(){
      fullscreen();     
    });
	
	
	
	

