function slideShow(){
    var active_img = $('#SLIDE img.active');
    if ( active_img.length == 0 ) active_img = $('#SLIDE img:last');
    var next_img =  active_img.next().length ? active_img.next() : $('#SLIDE img:first');
    active_img.addClass('last-active');
    next_img.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function(){ active_img.removeClass('active last-active'); });
}

function imgGal(){
$("#IMGNAV").hide();

$("#PREVIEW").ready(function(){
	$("#PREVIEW li img").show();
});

$('#PREVIEW li').addClass("inactive_img");
$('.inactive_img').click(function(){
	$(this).removeClass("inactive_img").addClass("active_img");
	$("#IMGNAV").show();
	$("#PAGENAV").hide();
});

// Blättern
$("#PAGENAV a").eq(0).addClass("active");
$("#PAGENAV a").click(function(){ 
					$("#PAGENAV a.active").removeClass("active");
			  		$(this).addClass("active"); 
});

// weiter
$("#NEXT_btn").click(function(){
	 $(".active_img img").fadeOut("300",function(){
                    $(".active_img img").show();
                    $(".active_img").removeClass("active_img").addClass("inactive_img").next("li").removeClass("inactive_img").addClass("active_img");
                    $("#PREVIEW li div").hide();
                    $("#INFO_btn").data("clicked", false);
	 })
});
//zurück
$("#BACK_btn").click(function(){
	 $(".active_img img").fadeOut("300",function(){
                    $(".active_img img").show();
                    $(".active_img").removeClass("active_img").addClass("inactive_img").prev("li").removeClass("inactive_img").addClass("active_img");
                    $("#PREVIEW li div").hide();
                    $("#INFO_btn").data("clicked", false);
	 })
});
 //INFO
 $("#INFO_btn").data("clicked", false);
 $("#INFO_btn").click(
 	  function(){ 
			  if(	$(this).data("clicked")==false)
			  { 	$(".active_img div").show(300);
			  		$(this).data("clicked",true); 
					return false; }
			  else
			  { 	$(".active_img div").hide(300);
					$(this).data("clicked", false); 
					return false; }
	});
//schlißen	
$("#CLOSE_btn").click(function(){
 	$(".active_img").removeClass("active_img").addClass("inactive_img");
 	$("#PREVIEW li div").hide();
 	$("#INFO_btn").data("clicked", false);
 	$("#IMGNAV").hide();
 	$("#PAGENAV").show();
	});
}
// Bilder POPUP
function imgPopup(){
$("a.popup").click(function(){
	var url = $(this).attr("href");
	var modulPlace = '<div id="POPUP"><img src="" /><a href="#" class="close">&times;</a></div>';
	$(modulPlace).insertAfter("#FOOTER");
	$("#POPUP").children("img").attr("src", url);
	$("#POPUP").fadeIn(500);

	$("#POPUP a").click(function(){
		$(this).parent("div").remove();
	});
	
	$("#POPUP img").height("90%").data("clicked",true);
	$("#POPUP img").click(function(){
				if(	$(this).data("clicked")==true)
				{ $(this).height("").data("clicked",false); }
				else
				{ $(this).height("90%").data("clicked", true); }
				});	
	
	return false;
});
}

$(document).ready(function() {
   	$.ajaxSetup({ cache: false });
	$("#CONTENT").hide(); 
	$("#PREVIEW li img").hide();
	imgPopup();
});
 
$("#CONTENT").ready(function(){ 
	$("#CONTENT").fadeIn(500);
	imgGal();
});
