(function($) {
    
$.widget("ui.seezam_slider",  $.extend({}, $.ui.slider.prototype, {
	options: {
		animate: true,
		step: 1,
		distance: 1,
        delay: 0,
		max: 3,
		min: 1,
		step: 1,
		value: 1,
		seezam: false,
		text: [messages.slider.public, messages.slider.contact, messages.slider.private]
	},
	
	_create: function(){
		$.ui.slider.prototype._create.call(this);
		
		this.element.after('<div id="seezam-slider-text-' + this.options.name + '" class="seezam-slider-text"></div>');
		
		if(this.options.disabled == true) {
          this.range.addClass('seezam-slider-tray-lock');
          this.handle.removeAttr('tabindex');
          this.handle.css('cursor', 'not-allowed');
        }
		
		if (this.options.max < 3) {
			this.range.addClass('seezam-slider-tray-last-lock');
        } 
        
        this.handle.addClass('seezam-slider-tracker');
    },
	
	enable: function() {
		this.options.disabled = false;
		this.range.removeClass('seezam-slider-tray-lock');
		this.handle.css('cursor', 'pointer').attr('tabindex', this.options.tabindex);
    },
    
	disable: function() {
		this.options.disabled = true;
		this.range.addClass('seezam-slider-tray-lock');
		this.handle.css('cursor', 'not-allowed').removeAttr('tabindex');
	},
	
	_change: function( event, index ) {
		$.ui.slider.prototype._change.call(this);
	},
	
	_refreshValue: function() {	
		$.ui.slider.prototype._refreshValue.call(this);
		
		var value = this.value();
		var text = '';
		this.handle.removeClass('seezam-slider-tracker-public seezam-slider-tracker-contacts seezam-slider-tracker-private');
		switch(value) {
			case 1:
				this.handle.addClass('seezam-slider-tracker-public');
				text = (typeof this.options.text[value-1] == 'function') ? this.options.text[value-1](this) : this.options.text[value-1];
				break;
			case 2:
				this.handle.addClass('seezam-slider-tracker-contacts');
				text = (typeof this.options.text[value-1] == 'function') ? this.options.text[value-1](this) : this.options.text[value-1];
				if(this.options.seezam == true)
					text+= ' &amp; SeeZam';
				break;
			case 3:
				this.handle.addClass('seezam-slider-tracker-private');
				text = (typeof this.options.text[value-1] == 'function') ? this.options.text[value-1](this) : this.options.text[value-1];
				if(this.options.seezam == true)
					text+= ' &amp; SeeZam';
				break;	
		};
		$('#seezam-slider-text-' + this.options.name).html(text);
	}
}));
		
      
})(jQuery);

