//client-side management of acetate layer objects
//for instance, adding a label to an address for the location finder
//these items are not true acetate layer objects as they reside on the client only.
//this allows for better control and fewer server requests.

function IMS2_AcetateList(acetateDivID){
    var self = this;
    
    this.acetates = new Array();
    this.acetateDivID = acetateDivID;
    
    function Add(x,y){
        var acetate = new IMS2_Acetate(x,y);
        self.acetates[self.acetates.length] = acetate;
        acetate.AddDiv(document.getElementById(self.acetateDivID));
        return(acetate);
    }
    this.Add = Add;
    
    function Remove(val){
        for(var i = 0; i < self.acetates.length; i++){
            if(self.acetates[i] == val){
                self.RemoveAt(i);
                return(val);
            }
        }
        return(null);
    }
    this.Remove = Remove;
    
    function RemoveAt(i){
        if(i >= 0 && i < self.acetates.length){
            var val = self.acetates[i];
            if(val){
                val.Destroy();
            }
            self.acetates.splice(i,1);
            return(true);
        }
        return(false);
    }
    this.RemoveAt = RemoveAt;
    
    function Clear(){
        while(RemoveAt(0)){;};
    }
    this.Clear = Clear;
}

function IMS2_Acetate(x,y){
    var self = this;
    
    this.position = [x,y];
    this.positionType = ["center","center"];
    this.div = null;
    
    function AddDiv(parent){
        if(null == self.div && parent){
            self.div = document.createElement('div');
            self.div.style["position"] = "absolute";
            self.div.style["left"] = "0px";
            self.div.style["top"] = "0px";
            parent.appendChild(self.div);
        }
    }
    this.AddDiv = AddDiv;
    
    function Destroy(){
        if(self.div){
            self.div.parentNode.removeChild(self.div);
        }
    }
    this.Destroy = Destroy;
}