/*** 
    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( slideTo) {
    var $active = $('#slideshow .slide.active');

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

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

	// Allow navigation by buttons
	var slideTo = ( slideTo ) ? slideTo : null;
	if ( slideTo != null ) $next = $('#slideshow .slide-' + slideTo);
	
    $active.addClass('last-active');

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

$(function() {
	$('.products .hentry h2').hide();
	$('.products .hentry p').hide();
	
	// Initiate customized lightbox for enlarging thumbnails
	$('#content a.lightbox').lightBox();
	
    var playSlideshow = setInterval( "slideSwitch()", 5000 );
	var isPlaying = true;
	
	// Count number of slides and insert number in the menu:
    var n = $("#slideshow .slide").length;
	var slidemenu = "";
	if( n!=0 )
		slidemenu = '<div id="slidemenu">';
	for( var i=n; i>0; i-- ) {
		slidemenu += '<a href="#1" rel="' + i + '" class="slidemenunumber slideknapp-' + (i % 3) + '">' + i + '</a>';
	}
	if( n!=0 )
		slidemenu += '</div>';
	$('#slideshow').append(slidemenu);
	
	// Controller for slide navigation:
	var $slideButtons = $("#slidemenu .slidemenunumber");
	$slideButtons.click(function(){
		// stop the slideshow, to keep it from trying to overlap our transition
		clearInterval(playSlideshow);
		// Call the function using the rel attribute of the clicked button
		slideSwitch( $(this).attr('rel') ); 
		// restart the slideshow
		playSlideshow = setInterval( "slideSwitch()", 5000 );
	});
	
	// Fadein or fadeout contact info
	$('#kontaktknapp').click( function() {
		$('#kontaktwrap').fadeIn('slow');
	});
	$('#kontaktwrap').click( function() {
		$('#kontaktwrap').fadeOut('slow');
	});
	$('.close').click( function() {
		$('#kontaktwrap').fadeOut('slow');
	});
});

