
function dom_init() {

	setTimeout(function() {
		k = 1;
		while(k<=backgrounds) {
			$("#backstretch"+k).addClass("back");
			k++;
		};
		
	}, 10);
	
	if (!iosdetect) {
	var i = 0;
	setInterval(function() {
		refresh(i);
		i++;
	}, 4500);
  }
  
  
  
  $('#boxtoggle').click(function(){
    $('#content').slideToggle(220);
    $(this).toggleClass('closed');
  });
  
  $("a.fancybox").fancybox({
		'speedIn' : 600,
		'speedOut' : 300,
		'titleShow': true,
		'title': '<a href="#" class="printpic">Foto drucken</a>',
		'overlayShow': true,
		'cyclic': true,
		'showNavArrows': true,
		'onStart': function(){
			changeBackground = false;
		},
		'onClosed': function(){
		  if (!iosdetect) {
			  changeBackground = true;
		  }
		}
	});
	
  
  $('.printpic').live('click', function(){
    $('body').addClass('gallerymode');
    window.print();
    $('body').removeClass('gallerymode');
  });
  
	
}
var animateSpeed = 300;

function refresh(i) {
	if(changeBackground) {
		cur = i % backgrounds; 
		$("#backstretch"+cur).stop().animate({ opacity: 0 }, 3*animateSpeed);
		next = (i+1) % backgrounds;
		$("#backstretch"+next).stop().animate({ opacity: 1.0 }, 3*animateSpeed);
	}
	
}
