function QueueButton(bind_to, options) {
    this._dom_button = null;
    this._dom_image = null;
    this._dom_cb = null;
    this._dom_label = false;
    
    this._add_label = false;
    this._remove_label = false;
    
    this._id = null;
    this._queued = false;
    this._small = false;
    
    this._disabled = false;
    
    this._updateButtonFace = function() {
		if (this._dom_image != null) {
	        base_url = this._dom_image.src.split('/');
	        base_url.pop();
	        prefix = '';
	        if (this._small) {
	            prefix = 'small_';
	        }
        
	        remove_or_add = this._queued?'remove':'add';
	        new_name = prefix + remove_or_add + '.png';
	        base_url.push(new_name);
	        this._dom_image.src = base_url.join('/');
		} else {
			this._dom_cb.checked = this._queued;
		}
        
		Element.removeClassName(this._dom_button, 'in-queue');
		Element.removeClassName(this._dom_button, 'not-in-queue');
		Element.addClassName(this._dom_button, this._queued?'in-queue':'not-in-queue');

        if (this._dom_label) {
            this._dom_label.innerHTML = this._queued?this._remove_label:this._add_label;
        }
        
    }
    
    this.setQueued = function(f) {
        var old_value = this._queued;
        this._queued = f;
        if (this._queued != old_value) {
            this._updateButtonFace();
        }
    }
    
    this.getQueued = function() {
        return this._queued;
    }
    
    this._parseAndSetId = function(id) {
        parts = id.split('-');
        this._id = {preset_id: parts[0], post_id: parts[1], file_number: parts[2]};
    }
    
	this._setStateFromCB = function(cb) {
		this._queued = cb.checked;
	}

    this._setStateFromSrc = function(src) {
        bname = src.split('/').pop().split('.').shift();
        bname_parts = bname.split('_');
        if (bname_parts[0] == 'small') {
            this._small = true;
            bname_parts.shift();
            
        }
        this._queued = bname_parts[0] == 'add'?false:true;
    }
    
    this._onClicked = function(e) {
        Event.stop(e);
        if (this.getQueued()) {
            HTTPClient.POST('/frontend/user/queue_remove', this._id, function(response) {
               result = parse_json(response.body);
				try {
					$('qcount').innerHTML = result.count;
					new Effect.Highlight($('qcount').parentNode);
				} catch(e) {};
            });
        } else {
            HTTPClient.POST('/frontend/user/queue_add', this._id, function(response) {
                result = parse_json(response.body);
				try {
					$('qcount').innerHTML = result.count;
					new Effect.Highlight($('qcount').parentNode);
				} catch(e) {};              
            });
        }
        this.setQueued(!this.getQueued());
    }
    
    this._init = function(bind_to, options) {
        this._dom_button = document.getElementById(bind_to);

		imgs = this._dom_button.getElementsByTagName('img');
		if (imgs.length > 0) {
			this._dom_image = imgs[0];
		} else {
			this._dom_cb = this._dom_button.getElementsByTagName('input')[0];
		}
		
        spans = this._dom_button.getElementsByTagName('span');
        if (spans.length > 0) {
            this._dom_label = spans[0];
        }
        
        if (options.label_add) {
            this._add_label = options.label_add;
        }
        if (options.label_remove) {
            this._remove_label = options.label_remove;
        }        
        
        this._parseAndSetId(bind_to);
		if (this._dom_image != null) {
        	this._setStateFromSrc(this._dom_image.src);
		} else {
			this._setStateFromCB(this._dom_cb);
		}
        
        Event.observe(this._dom_button, 'click', this._onClicked.bind(this));
        
    }
    
    this._init(bind_to, options)
}
