var OptionsModel = new Class({

	//costruttore, assegno le variabili necessarie
    /**
     * container == elemnto in cui andrà il blocco descrizione
     * */
	initialize: function() {
		this.data = new Array();
        this.sons = new Array();
        this.fathers = new Array();
        this.edges = new Array();
        
	},
	//ricevo oggetto con le opzioni disponibili
    clean:function(){
		this.data = new Array();
        this.sons = new Array();
        this.fathers = new Array();
        this.edges = new Array();
    },
	//ricevo oggetto con le opzioni disponibili
    setData:function(data){
        this.data = data;
    },
	//ricevo oggetto per un'opzione
    addSon:function(candidate){
        var present = false;
        this.sons.each(function(item,index){
            if (!present) {
                if (item.father == candidate.father) {
                    if (candidate.son != -1) {
                        this.sons[index] = candidate;
                    }
                    else {
                        this.sons[index] = null;
                        this.sons = this.sons.clean();
                    }
                    present = true;
                }
            }
        }.bind(this));
        if (!present) {
            this.sons.push(candidate);
        }
    },
	//ricevo oggetto per opzione solo padre
    addFather:function(candidate){
       var present = false;
       this.fathers.each(function(item,index){
            if (item.father == candidate.father) {
                this.fathers[index] = null;
                this.fathers = this.fathers.clean();
                present = true;
            }
        }.bind(this));
        if (!present) {
            this.fathers.push(candidate);
        }
    },
	//ricevo oggetto per set lati di un'opzione
    addEdge:function(candidate){
        var present = false;
        this.edges.each(function(item,index){
            if (!present) {
                if (item.father == candidate.father) {
                    if (candidate.edge != 0) {
                        this.edges[index] = candidate;
                    }
                    else {
                        this.edges[index] = null;
                        this.edges = this.edges.clean();
                    }
                    present = true;
                }
            }
        }.bind(this));
        if (!present && candidate.edge != 0) {
            this.edges.push(candidate);
        }
    },
	//ripulisco il container
    clean:function(data){
        this.sons = new Array();
        this.fathers = new Array();
        this.edges = new Array();
        this.data = new Array();
    },
	//ritorna i dati delle opzioni selezionate
    getEstimateData:function(){
        var options = new Array();
        options.push(this.sons);
        options.push(this.fathers);
        options.push(this.edges);
        return options;
    },
    //restituisce i dati
    getSelectData:function(){
        return this.data;
    }
});
