/**
 * Create namespace
 */
window.nl = {} ;
window.nl.xd = {} ;

/**
 * XD Class
 * @abstract
 */
nl.xd.XD = {

	/**
	 * The browser User Agent
	 * 
	 * @var string
	 */
	ua: navigator.userAgent.toLowerCase() ,
	
	/**
	 * If the browser is the Opera browser
	 * 
	 * @var boolean
	 */
	isOpera: null ,
	
	/**
	 * If the browser is the Opera browser
	 * 
	 * @var boolean
	 */
	isIE: null ,
	
	/**
	 * If the browser has a Geko engine
	 * 
	 * @var boolean
	 */
	isGecko: null ,
	
	/**
	 * If the browser is the Safari browser
	 * 
	 * @var boolean
	 */
	isSafari: null ,
	
	/**
	 * If the browser is the Konqueror browser
	 * 
	 * @var boolean
	 */
	isKonqueror: null ,
	
	/**
	 * Set the static attributes referencing the browser attributes
	 */
	browser: function() {
		this.isOpera     = ( this.ua.indexOf( 'opera' ) != -1 ) ;
		this.isIE        = ( this.ua.indexOf( 'msie' ) != -1 && ! this.isOpera ) ;
		this.isGecko     = ( this.ua.indexOf( 'gecko' ) != -1 ) ;
		this.isSafari    = ( this.ua.indexOf( 'safari' ) != -1 ) ;
		this.isKonqueror = ( this.ua.indexOf( 'konqueror' ) != -1 ) ;
	} ,
	
	/**
	 * Create a namespace
	 * 
	 * @param string
	 * @return void
	 */
	namespace: function( namespace ) {
		if ( namespace.indexOf( 'nl.xd.' ) != -1 ) {
			namespace = namespace.replace( 'nl.xd.' , '' ) ;
			var packages = namespace.split( '.' ) ;
			var base     = nl.xd ;
			
			for ( var i = 0; i < packages.length; i++ ) {
				if ( ! base[ packages[ i ] ] ) {
					base[ packages[ i ] ] = {} ;
				} ;
				
				base = base[ packages[ i ] ] ;
			} ;
		} else {
			alert( 'Illegal namespace : "' + namespace + '"' ) ;
		} ;
	} ,
	
	/**
	 * Extend a class
	 * 
	 * @param string the name of the subclass
	 * @param string the name of the superclass
	 */
	extend: function( subclass , superclass ) {
		var parentConstructor = superclass.toString() ;
		var isClass           = parentConstructor.match( /\s*function (.*)\(/ ) ;
		
		if ( isClass != null ) {
			subclass.prototype[ isClass[ 1 ] ] = superclass ;
		} ;
		
		for ( var m in superclass.prototype ) {
			subclass.prototype[ m ] = superclass.prototype[ m ] ;
		} ;
	}
} ;

nl.xd.XD.browser() ;