if(!doc) var doc = document; if(!win) var win = window;

/*-----------------------------------------------------------
    /// START FUNCTIONS ///
    ---------------------------------------------------------*/

		jQuery(doc).ready(function() {
/*--------- settings fancybox --------*/
			jQuery("a[rel^=lightbox],a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'none',
				'overlayOpacity'	:	0.4,
				'overlayColor': '#000000',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
		jQuery("a.iframe").fancybox({
				'easingIn, easingOut': true,
				'width':800,
				'height':490,
				'overlayOpacity':0.4,
				'overlayColor': '#000000'
			});
			noSpam();
			//jQuery('.goToTop').topLink();
	
		
			Cufon.replace('h2,h3,#nav,#open,#close',{ fontFamily: 'Museo 700' , hover:'true'});
		});

/*-----------------------------------------------------------
    to encrypt e-mail address
    ---------------------------------------------------------*/
	
function noSpam() {
   
 if (doc.getElementById) {
		var at = "@";
	  	var links = doc.getElementsByTagName('a');
	  
	  	for (var i = 0; i < links.length; i++) {
		  	var linkElem = links[i];
			
		  	if (linkElem.className == 'email') {
		  		var mail = linkElem.firstChild; var domain = linkElem.lastChild;
		  		mail.nextSibling.firstChild.innerHTML = at;
		  		linkElem.href = "mailto:" + mail.data + at + domain.data;
		  	}
			
	  	} 
	  
    } 		
}

 
 /*-----------------------------------------------------------
    slide panel
    ---------------------------------------------------------*/
 
 $(doc).ready(function() {
	
	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		
		
});
 
 /*-----------------------------------------------------------
    waypoints
    ---------------------------------------------------------*/
 

  $(win).load(function(){
      $('#back-top').addClass('hidden');
    
    $.waypoints.settings.scrollThrottle = 30;
    $('#container').waypoint(function(event, direction) {
        $('#back-top').toggleClass('hidden', direction === "up");
    }, {
        offset: '-10%'
    }).find('#nav').waypoint(function(event, direction) {
        $(this).parent().toggleClass('sticky', direction === "down");
        event.stopPropagation();
    });
    
    // Register each section as a waypoint.
    $('#main > .section').waypoint({ offset: '0'});
    
    // The same for all waypoints
    $('body').delegate('#main > .section', 'waypoint.reached', function(event, direction) {
        
        var $active = $(this);
        
        if (direction === "up") {
            $active = $active.prev();
        }
        if (!$active.length) $active.end();
        
        $('.section-active').removeClass('section-active');
        $active.addClass('section-active');
        
        $('.link-active').removeClass('link-active');
        $('a[href=#'+$active.attr('id')+']').addClass('link-active');
        
    });
    
    // Negates the flash of non-active nav.
    $('body > #header #nav a').click(function() {
        $(this).addClass('link-active');
    }).eq(0).addClass('link-active');
    
    // Wicked credit to
    // http://www.zachstronaut.com/posts/2009/01/18/jquery-smooth-scroll-bugs.html
    var scrollElement = 'html, body';
    $('html, body').each(function () {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }    
    });
    
    // Smooth scrolling for internal links
    $("a[href^='#']").click(function(event) {
        event.preventDefault();
        
        var $this = $(this),
        target = this.hash,
        $target = $(target);
        
        $(scrollElement).stop().animate({
            'scrollTop': $target.offset().top
        }, 500, 'swing', function() {
            window.location.hash = target;
        });
        
    });

  });
  //]]> 
  
  
  
  
  
 /*-----------------------------------------------------------
    slider
    ---------------------------------------------------------*/

  
  $(doc).ready(function() {
			$('body').removeClass('no-js');
		    $('#my-carousel-3').carousel({
				itemsPerPage: 3,
				itemsPerTransition: 3,
				easing: 'linear',
				noOfRows: 2
			});
		});

 
  /*-----------------------------------------------------------
    slider-mini
    ---------------------------------------------------------*/
 
/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

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

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

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


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

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

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

