//onload

var speed = 1000;
var height = 450;
	
$(window).load(function() {

	var switchoff =  $('.startseite').children();	
    if(switchoff.length>1) var animate = setInterval( "slideSwitch()", 4000 );
	
	var start = true; //startseite an/aus
	var bigview = false;	
	var lastImg = "";
	
	$(".stage").css( { display : "block" } );
    $("#accordion").accordion({ active: false, autoHeight: false, animated: 'easeslide' });
	$('#accordion').children("h3").click(function(){ 
		if(start) { 
			$('#startseite').hide(); 
			clearInterval(animate);
			start = false;
		}
			$(".bigsize").css({ height: "0px" });
			if(lastImg != "") lastImg.removeClass("activeImg");
			lastImg = "";
			bigview = false;								
		
	});
	
	$('#blog').click(function(){
		window.open($(this).attr("href"),"blog");
	});
							 
	var pElem = "";
	var countThumbs = 0
	
	$('.big').click(function(){
		if(lastImg != "") lastImg.removeClass("activeImg");
		lastImg = $(this);
		countThumbs = $(this).nextAll().size();
		$(this).addClass("activeImg");
		var url = $(this).attr("href");
		pElem = $(this).parent().parent().children("div.bigsize");
		
		$(pElem).addClass('loading');
		
		var img = new Image();
  			$(img)			
			.load(function () {
				$(this).css({opacity: 0});
				$(pElem)
				.removeClass('loading')
				.html(this);
				$(this).animate({opacity: 1.0}, speed, function() {				
				});			
    		})
			.attr('src', url);
			
		if(!bigview) {
			pElem.animate({height: height+"px"}, speed, function() {
			bigview = true;								
			});		
		} 
		
		return false;
	});
	
	$(".bigsize").click(function(){
			var nextElem = $('.activeImg').next();
			if(countThumbs==0) {
				nextElem = $(this).parent().children("p").children('a:first');
				countThumbs = nextElem.nextAll().size()+1;
			}
			var nexturl = nextElem.attr("href");
			lastImg.removeClass("activeImg");
			lastImg = nextElem;
			nextElem.addClass("activeImg");
			
			$(pElem).addClass('loading');
			
			var img2 = new Image();
  			$(img2).load(function () {
				$(this).css({opacity: 0});
				$(pElem)
				.removeClass('loading')
				.html(this);
				$(this).animate({opacity: 1.0}, speed, function() {				
				});			
    		})
			.attr('src', nexturl);
			
			countThumbs--;
		});
	
	var imp = false;
	
	$(".impressum").click(function(){
		if(!imp) {
			$("#impressum").animate({height: "300px"}, speed, function() {
				$(".impclose").show();							
			});	
		} else {
			$(".impclose").hide();	
			$("#impressum").animate({height: "0px"}, speed, function() {						
			});	
		} 
		imp = !imp;
		return false;
	});
	
	
	$('.logo').click(function(){
		if(start) { 
			$('#startseite').hide(); 
			clearInterval(animate);
			start = false;
		}
		$("#accordion").accordion( "option", "active", 6 );		  
	});
		
});



function slideSwitch() {
    var $active = $('.startseite IMG.active');

    if ( $active.length == 0 ) $active = $('.startseite IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('.startseite IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, speed, function() {
            $active.removeClass('active last-active');
        });
}


