//****************************************//
//              toggleButton              //
//****************************************//
function toggleButton(task,state1,class1,turnedOn,state2,class2,turnedOff) {
    this.spanner = document.createElement("div");
    this.spanner.structure = this;
    this.ontext = state1;
    this.onclass = class1;
    this.offtext = state2;
    this.offclass = class2;

    this.state = 0; //off
    this.spanner.className = this.offclass;
    this.spanner.appendChild(document.createTextNode(this.ontext));
    this.OnFunction = turnedOn;

    this.OffFunction = turnedOff;
    this.task = task;
    addEvent(this.spanner,"click",function() {
        var b = this.structure;
        if (b.state == 0 ) {
            b.on();
            b.OnFunction();
        } else {
            b.off();        
            b.OffFunction();
        }
    });
}

toggleButton.prototype.setState = function(s) {
    if (this.spanner.firstChild !== undefined) {    
        this.spanner.removeChild(this.spanner.firstChild);
    }
    if (s == 0) {
        this.state = 0; //off
        this.spanner.className = this.offclass;
        this.spanner.appendChild(document.createTextNode(this.ontext));
    } else {
        this.state = 1; //on
        this.spanner.className = this.onclass;
        this.spanner.appendChild(document.createTextNode(this.offtext));
    }
}

toggleButton.prototype.on = function() {
    this.setState(1);
}

toggleButton.prototype.off = function() {
    this.setState(0);
}
