function pcSlider(opts) {



	this.current = 0;

	this.direction = 0;

	this.id = opts.id;

	this.picMas = opts.picMas;

	this.fadeOut = opts.fadeOut;

	this.fadeIn = opts.fadeIn;

	this.timeout = opts.timeout;

	this.event_onStart = opts.onStart;

	this.event_onStop = opts.onStop;

	this.loader_class = opts.loader_class;

	

	this.waiting = false;

	this.waiting_period = 500;

	

    this.setImage = function() {

    	//
		
    	if ($('#' + this.id + ' ~ div img.pcsltemps_' + this.current).attr('loaded') == 1) {

    		// Loaded

			$("#" + this.id).animate({opacity:0}, this.fadeOut, 

				(function(obj) { 

					return function() {

						$("#" + obj.id).attr('src', obj.picMas[obj.current]);
						//
						$("#" + obj.id).css('display', 'inline');

						$("#" + obj.id).animate({opacity:1}, obj.fadeIn);

					};

				})(this)

			);

			this.waiting = false;

			$('.' + this.loader_class).css('display', 'none');

    	} else {

    	//
			setTimeout(

				(function(obj){ 

					return function() {

						obj.setImage();

						};

				})(this), 

				this.waiting_period

            );

			this.waiting = true;

			$('.' + this.loader_class).css('display', 'inline');

    	}

    	

    }

    

    this.onStop = function() {

    	this.direction = 0;

    	this.event_onStop();

    }

    

    this.onStart = function() {

   		this.direction = 1;

   		this.timeStepper();

   		this.event_onStart();

    }

    

    this.onNext = function() {

    	this.onStop();

    	if (!this.waiting) {

	    	this.current ++;

    		if (this.current >= this.picMas.length) {

	    		this.current = 0;

    		}

	    	this.setImage();

    	}

    }

    

    this.onBack = function() {

    	this.onStop();

    	if (!this.waiting) {

	    	this.current --;

	    	if (this.current < 0) {

    			this.current = this.picMas.length - 1;

    		}

	    	this.setImage();

    	}

    }

    

    this.timeStepper = function() {



    	if (!this.waiting) {

	    	if (this.direction >= 1) {

    			this.current ++;

	    		if (this.current >= this.picMas.length) {

    				this.current = 0;

    			}

    		}

	    	if (this.direction <= -1) {

    			this.current --;

	    		if (this.current < 0) {

    				this.current = this.picMas.length - 1;

    			}

    		}

    		if (this.direction != 0) {

    			this.setImage();

    		}

    	}

    	

        if (this.direction != 0) {

			setTimeout(

				(function(obj){ 

					return function() {

						obj.timeStepper();

						};

				})(this), 

				this.timeout

            );

        }

    };

    

    this.makeNodes = function() {

    	

    	//$('#' + this.id).after($('<div style="display:none;position:relative;top:-20px;" class="pcsltempswi">Loading image...</div>'));

    	

    	s = '';

    	for (i = 0; i < this.picMas.length; i++) {

    		s += '<img src="' + this.picMas[i] + '" class="pcsltemps_' + i + '">';

    	}

    	$('#' + this.id).after($('<div style="display:none;">' + s + '</div>'));

    	$('#' + this.id + ' + div img').load(function(){

    		$(this).attr('loaded', 1);

    	});

    }

    

    $('*[rel="' + this.id + '_next"]').click(

    	(function(obj){return function(){return obj.onNext();};})(this)

    );

    

    $('*[rel="' + this.id + '_back"]').click(

    	(function(obj){return function(){return obj.onBack();};})(this)

    );

    

    $('*[rel="' + this.id + '_start"]').click(

    	(function(obj){return function(){return obj.onStart();};})(this)

    );

    

    $('*[rel="' + this.id + '_stop"]').click(

    	(function(obj){return function(){return obj.onStop();};})(this)

    );

    

    $('.' + this.loader_class).css('display', 'none');

    

    this.makeNodes();

    //this.timeStepper();
this.setImage();
}	
