/* Author: Beda*/
function rotatePics(currentPhoto) {
    var numberOfPhotos = $('#photostack img').length;
    currentPhoto = currentPhoto % numberOfPhotos;
    nextPhoto = (currentPhoto + 1) % numberOfPhotos;
    $('#photostack img').eq(currentPhoto).fadeOut(function() {
        // re-order the z-index
        $('#photostack img').each(function(i) {
            $(this).css('zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos);
            $(this).show();
        });

    });
    $('#photostack img').eq(nextPhoto).addClass('show').show();
    $('#photostack img').eq(currentPhoto).removeClass('show');
    
	$('#circles_nav a').eq(currentPhoto).removeClass('active');
    $('#circles_nav a').eq(nextPhoto).addClass('active');    
	
	$('#photostack a').eq(nextPhoto).show();
    $('#photostack a').eq(currentPhoto).hide();
	
	$('aside div').eq(nextPhoto).show();
    $('aside div').eq(currentPhoto).hide();
	
};

// rotate counterclockwise
function rotatePicsCC(currentPhoto) {
    var numberOfPhotos = $('#photostack img').length;
    currentPhoto = currentPhoto % numberOfPhotos;
    nextPhoto = (currentPhoto - 1) % numberOfPhotos;
    $('#photostack img').eq(nextPhoto).fadeIn(function() {
        // re-order the z-index
        $('#photostack img').each(function(i) {
            var zindex = ((numberOfPhotos - i) + nextPhoto - 1) % numberOfPhotos;
            if (zindex == -1) {
                zindex = numberOfPhotos;
            }
            $(this).css('zIndex', zindex);
        });
        $(this).addClass('show').show();
       
    });
	$('#photostack img').eq(nextPhoto).addClass('show').show();
	$('#photostack img').eq(currentPhoto).removeClass('show');
    
	$('#circles_nav a').eq(currentPhoto).removeClass('active');
 	$('#circles_nav a').eq(nextPhoto).addClass('active');
    
	$('#photostack a').eq(nextPhoto).show();
    $('#photostack a').eq(currentPhoto).hide();
   
	$('aside div').eq(nextPhoto).show();
    $('aside div').eq(currentPhoto).hide();
};

function rotatePicsCircle(currentPhoto) {
    var numberOfPhotos = $('#photostack img').length;
    currentPhoto = currentPhoto % numberOfPhotos;
    nextPhoto = (currentPhoto + 1) % numberOfPhotos;
    $('#photostack img').eq(currentPhoto).fadeOut(function() {
        // re-order the z-index
        $('#photostack img').each(function(i) {
            $(this).css('zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos);
            $(this).show();
        });

    });
    $('#photostack img').removeClass('show').eq(nextPhoto).addClass('show').show();
    $('#circles_nav a').removeClass('active').eq(nextPhoto).addClass('active');    
	$('#photostack a').hide().eq(nextPhoto).show();
    $('aside div').hide().eq(nextPhoto).show();
};

$(document).ready(function() {
		//var test=$("#content h1").text();
		//$(".slide-out-div textarea").val('Mein Kommentar zu der Anleitung '+test);
    $('#photostack a').hide().first().show();
    $('aside div').hide().first().show();
	$('#circles_nav a.circles').each(function(i) {
        $(this).data('index',i);
    });

    $('#weiter').bind('click',
    function(event) {
        var current = 0;
        $('#photostack img').each(function(i) {
            if ($(this).hasClass('show')) {
                current = i;
            };
        });
        rotatePics(current);
    });

    $('#zurueck').bind('click',
    function(event) {
        var current = 0;
        $('#photostack img').each(function(i) {
            if ($(this).hasClass('show')) {
                current = i;
            };
        });
        rotatePicsCC(current);
    });

	$('#circles_nav a.circles').bind('click',
    function(event) {
 		rotatePicsCircle($(this).data('index')-1);
    });

});



