var Slider = function(opt) { this.initialize(opt); };
jQuery.noConflict();
(function($) { 
  $(function() {
    // more code using $ as alias to jQuery
    
    Slider.prototype = {
        initialize: function(options) {
            
            this.is_moving = false;
            this.in_p = 1;
            var $this = this;
            $(options.leftbtn).click(function(e) { e.preventDefault(); $this.moveSlider(1); });
            $(options.rightbtn).click(function(e) { e.preventDefault(); $this.moveSlider(-1); });
            
            if(options.afterFinish != null)
                this.afterFinish = options.afterFinish;
            else
                this.afterFinish = function() { };
            
            this.container = options.container;
            this.window    = options.window;
            
            this.offset = parseInt($(this.window).css('width')); 
            
            $(this.container).css('left', '0px');
        },
                                     
        moveSlider: function(dir) {
            
            var $this = this;
            
            if(!this.is_moving) {
                
                if(dir == 1) {
                    //$(options.rightbtn).show();
                    
                    if(parseInt($(this.container).css('left')) < 0) {
                        
                        this.in_p      = this.in_p-1;
                        this.is_moving = true;
                        $(this.container).animate({ left: '+='+this.offset+'px' }, 500, 'linear', function() { $this.is_moving = false; setTimeout($this.afterFinish, 0); });
                        
                        if($('.spc-galeria')){
                            $('#photo-current').html(this.in_p);
                        }
                        //var listItem = jQuery('.spc_on').index()+1;
                    }
                }
                else {
                     //$(options.leftbtn).show();
                    if(parseInt($(this.container).css('width')) + parseInt($(this.container).css('left')) > parseInt($(this.window).css('width'))) {  
                        
                        this.in_p      = this.in_p+1;
                        this.is_moving = true;
                        $(this.container).animate({ left: '-='+this.offset+'px' }, 500, 'linear', function(e) { $this.is_moving = false; setTimeout($this.afterFinish, 0); });
                        
                        if($('.spc-galeria')){
                           $('#photo-current').html(this.in_p);
                        }
                    }
                }
            }
            
            
        }
    };

});
})(jQuery);

