var currentBlockHeaderImage = 0;
var speed = 3500;
var maxloops = 50;
var loops = 0;
var countAll = 1;
var slideIntervalId;

$( function() {
	var imagesBlocks = $("#phone-images-slideshow img");
	loops = 1;
	
	$( '.category' ).click( function() {
		$( this ).toggleClass( 'active' )
		$( this ).siblings( '.dropdown' ).toggle();
		$( this ).find( '.indicator' ).toggleClass( 'indicator-active' );
		return false;
	} );

	if (imagesBlocks.length > 0) {
		$(function() {
			slideIntervalId = setInterval( "slideSwitch()", speed );
		});
	}		
} );


function slideSwitch() {
	var $active = $('#phone-images-slideshow img.active');
	if (loops >= maxloops) {
		clearInterval(slideIntervalId);
	}
	loops++;
    if ( $active.length == 0 ) $active = $('#phone-images-slideshow img:last');
    var $next =  $active.next().length ? $active.next()
        : $('#phone-images-slideshow img:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });

}

