/*
  Copyright (c) 2003 Jan-Klaas Kollhof
 
  This is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
 
  This software is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 
  You should have received a copy of the GNU General Public License
  along with this software; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
*/

function newClass (superClass, className){
    //setting defaults
    superClass = (superClass==null) ? Object : superClass; 
    //creating an anonymous function which serves as a generic constructor.
    //The constructor will call the init method of the new object if and only 
    //if the constructor was not used for inheritence(called from within newClass)
    //this makes sure that init is not called while subclassing.
    var GenericConstructor = function(caller){
        if(caller !== newClass){
            if(this.init){
                this.init.apply(this, arguments);
            }
        }
    };
    GenericConstructor.generatedByNewClass = true;
    //only subclassed classes generated by newClass can be called with newClass as parameter
    if(superClass.generatedByNewClass){
        GenericConstructor.prototype = new superClass(newClass);
    }else{
        GenericConstructor.prototype = new superClass();
    }
    //resetting the true constructor for the new class
    GenericConstructor.prototype.constructor = GenericConstructor;
    //convenience properties
    GenericConstructor.superClass = superClass;
    //setting the className
    GenericConstructor.className=className; 
    //convenience functions
    GenericConstructor.toString = function(){return "[class " + GenericConstructor.className +"]";};
    GenericConstructor.prototype.toString = function(){return "[object " + GenericConstructor.className +"]";};
    return GenericConstructor;
}

