(function( $ ){
  $.fn.superslideshow = function() {
    var current = 1;
    var interval = undefined;
    var delay = 3000;
    var size = this.find('.cont').length;
    var playing = false;
    
    return this.each(function() {
        var slider = $(this);
        
        var changeSlide = function(){
        
            $('#cont' + current).fadeOut(function(){
                $('.cont').css('display', 'none');
                current++;
                if(current > size) current = 1;
                $('#cont' + current).fadeIn(function(){
                    if(playing != true){
                        play();
                    }
                });    
            });
            
        }
        
        var changeSlideBack = function(){
        
            $('#cont' + current).fadeOut(function(){
                $('.cont').css('display', 'none');
                current--;
                if(current < 1) current = size;
                $('#cont' + current).fadeIn(function(){
                    
                    if(playing != true){
                        play();
                    }
                });    
            });
            
        }
        
        var play = function(){
            playing = true;
            interval = setInterval(changeSlide, delay);
           
        }
        
        //controlls
        if($('#arrows').length){
            //next
            $('#arrows img:last').click(function(){
                clearInterval(interval);
                playing = false;
                changeSlide();
            });
            
            //prev
            $('#arrows img:first').click(function(){
                clearInterval(interval);
                playing = false;
                changeSlideBack();
            });
        }
        
        play();    
        
    });
    
  };
})( jQuery );


