
/****************************** FMD COLLECTION OBJECT ******************************/
/* Version: 1.0                                                                    */
/* Copyright (c) 2003 Flying Machine Development, All Rights Reserved              */
/* Contact: info@flyingmachinedevelopment.com                                      */
/***********************************************************************************/

  function collection()
  {
    this.add = add;
    this.clear = clear;
    this.length = 0;
    this.keys = new Array();
    this.isMember = isMember;
    this.sort=sort;
    return this;
  }
  
  function clear()
  {
    for(var n=0;n<this.length;n++)
    {
      delete this[n];
      delete this.keys[n];
    }
    this.length=0;
  }

  function isMember(key)
  {
    var n=0;
    for (n=0;n<this.length;n++)
    {
      if(this.keys[n] == key)
      {
        return true;
      }
    }
    return false;
  }

  function add(key, value)
  {
     this[key] = value;
     for (var n=0;n<this.length;n++)
     {
       if(this.keys[n] == key) break;
     }
     this[n]=this[key];
     this.keys[n] = key;
     if(n>=this.length)this.length++;
     return this[key];
  }

  function sort(fx)
  {

    var cSort=new collection();
    var aSort=new Array()
    if(!fx)
    {
      for(var n=0;n<this.length;n++)
      {
        aSort[n]=this.keys[n];
      }
      aSort.sort();
      for(var n=0;n<aSort.length;n++)
      {
        cSort.add(aSort[n], this[aSort[n]])
      }
    }
    else
    {
      for(var n=0;n<this.length;n++)
      {
        aSort[n]=new Array(this.keys[n], this[n])
      }
      aSort.sort(fx);
      for(var n=0;n<aSort.length;n++)
      {
        cSort.add(aSort[n][0], this[aSort[n][0]])
      }
    }
    
    return cSort;
  }


  