var old_height = 0;

jQuery(document).ready(function($){

	
projektVor = function(){
	if($($('a.ajax.active')[0]).next("a.ajax").length>0){
		$($('a.ajax.active')[0]).next("a.ajax").click();	
	} else{
		$($('a.ajax')[0]).click();	

	}	
}
projektZur = function(){
	if($($('a.ajax.active')[0]).prev("a.ajax").length>0){
		$($('a.ajax.active')[0]).prev("a.ajax").click();	
	} else{
		$($('a.ajax')[$('a.ajax').length-1]).click();	

	}

}



fadeAllOutExceptActive = function(){
$('.projekt_klein').each(function(){


	if(!$(this).parent().hasClass("active")){
		$(this).fadeTo(1, 0.5);
	}

});

}

fadeAllOutExceptActive();


old_height = $('#single_projekt').height();

		$('.projekt_klein').live("mouseenter", function(e){

			//$('.projekt_klein').clearQueue();
			
			//console.log($(this));
			
			/*$(this).stop().fadeTo(100,1, function(){
				//$(this).stop().animate({backgroundColor:'#FFAC3A'}, 1000);
				//$(this).find('h3').stop().animate({color:'#fff'}, 800);

			});*/
			
			//$('.projekt_klein.overActive').stop().animate({backgroundColor:'#fff'}, 1000);
			//$('.projekt_klein.overActive').find('h3').stop().animate({color:'#9E9E9E'},800);



			/*$('.projekt_klein').each(function(){
				if($(this).css('backgroundColor')!="rgb(255, 255, 255)"){
					$(this).stop().animate({backgroundColor:'#fff'}, 1000);
					$(this).find('h3').stop().animate({color:'#9E9E9E'},800);				}
			});*/
		

			$(this).stop().animate({backgroundColor:'#FFAC3A','opacity':1}, 750);
			$(this).find('h3').stop().animate({color:'#fff'}, 500);

			$('a.active .projekt_klein').fadeTo(1,1);

			

			return;
			 

			$(this).addClass("overActive");

			$('.projekt_klein').not('.overActive').animate({backgroundColor:'#fff'},1500).fadeTo(1500, 0.1);
			//$('.projekt_klein').not('.overActive').stop().delay(1).css({backgroundColor:'red'}); //stop().fadeTo(1800, 0.1);
			//$('.projekt_klein').not('.overActive').stop().fadeTo(1,0.1);
			
			
			return;
			/*$('.projekt_klein').stop().fadeTo(1500, 1);
			

			$(this).addClass("overActive");

			$('.projekt_klein').not('.overActive').stop().fadeTo('slow', 0.2);*/

			
		});

		$('.projekt_klein').live("mouseleave", function(e){

			$(this).stop().animate({backgroundColor:'#fff','opacity':0.5}, 750);
			$(this).find('h3').stop().animate({color:'#9E9E9E'}, 500);

			$('a.active .projekt_klein').fadeTo(1,1);

			//$('.projekt_klein').not('.overActive').stop().fadeTo(1800, 1);
			return;
			
			$('.projekt_klein').not('.overActive').stop().fadeTo(1500, 1); //stop().fadeTo(1800, 0.1);
			
			$(this).removeClass("overActive");
			
			//$('.projekt_klein').not('.overActive').stop().fadeTo(1,1);
			


			/*$('.projekt_klein').not('.overActive').stop().fadeTo(1500, 1);

			$(this).removeClass("overActive");
			*/

			




		});

    
                /* Ajaxloader für Seiteinhalte, fliegt aus dem Bild und wieder hinein */
		$("a.ajax").live("click", function(e){

			e.preventDefault();
			
                        href = $(this).attr("href");
			selector = $(this).attr("rel");

			  $('a.ajax').removeClass("active");

			$('a[href='+href+']').addClass("active");
			
			if($(this).find(".projekt_klein").length>0){
				$.scrollTo('body', 900, {axis:'y'});
				fadeAllOutExceptActive();
			}


                      



			old_height = $(selector).height();
			$(selector).css({'height': old_height+'px'});

			
			
                    // $(selector).fadeTo('slow', 1);
 			$(selector).fadeTo('slow', 0.01);
			

			$('#projekte_loading').fadeIn('slow');


			//$(single_selector).animate({marginLeft:"-=1000"},500,function() {
			$.get(href, function(data){				

					ajax = "<div>"+data.split("<body").join("<div bodyattr='true' ").split("</body>").join("</div>")+"</div>";
					
					$(selector).each(function(){
						$(this).html($(ajax).find("#"+$(this).attr("id")).html());

					});
					$(selector).css({height:old_height+'px'});
					$('#projekte_loading').fadeOut('slow');


					
					$(selector).each(function(){

						$(this).stop().hide().show().css("opacity","0").fadeTo('slow', 1,function(){
							$(this).removeAttr("style");
						});

						$('#projekt_loading_dummy').html($('#single_projekt').html());
						new_height = $('#projekt_loading_dummy').height();
									
						$('#projekt_loading_dummy').html('');

						$(selector).animate({height: new_height+'px'});
					});
					
					(function($) { 
						$(function() {$(".lightbox").lightbox( {navbarOnTop: 0 , resizeSpeed: 300 , overlayOpacity: 0.4, strings : { prevLinkTitle: "previous image", nextLinkTitle: "next image", prevLinkText:  "&laquo;&nbsp;&nbsp;", nextLinkText:  "&nbsp;&nbsp;&raquo;",closeTitle: "close", image: "Image", of: "of"}});});
					})(jQuery);



					

				});

			//}); //animation
		});



});