/**
 * @fileoverview Importuje podany plik.
 *
 * @Used IE, FF, Opera
 *
 * @example
 *		Import('myLib/data/Vector.js');
 *		lub
 * 		Import('myLib.data.Vector');
 *		lub
 *		Import.script('http://wap.samozycie.pl/_lib_js/myLib/util/Service.js');
 *
 * @version: 1.01 2005/06/07
 */

function Import(file){
	file = Import.getScriptPath(file);
	Import.script(Import.path + file);
};

Import.getScriptPath = function(file){
	if(file.indexOf('/') >= 0)
		return file;
	else
		return file.split('.').join('/') + '.js';
};

Import.HOST_MAIN = 'http://www.uml.lodz.pl/';

Import.path = Import.HOST_MAIN + 'js/';

Import.pathWebSerwices = '';

Import.scripts = new Array();

Import.script = function(file){
	if(!Import.isImport(file)){
		document.write('<script src="' + file + '"></script>');
		Import.scripts[Import.scripts.length] = file;
	}
};

Import.isImport = function(file){
	for(var i = 0; i < Import.scripts.length; i++){
		if(Import.scripts[i] == file){
			return true;
		}
	}
	return false
};

Import.namespace = function(name){
    if(typeof(name) == 'undefined'){
        alert('Lack of package\'s name.');
        return false;
    }
    name = name.replace('.', '/');
    if(name.substr(name.length - 1, 1) != '/'){
        name += '/';
    }
    //alert(name);
    var result = false;
    var scripts = document.getElementsByTagName('script');
    for(var i = 0; i < scripts.length; i++){
        if(scripts[i].src != ''){
            var tmp = scripts[i].src.replace(Import.path, '');
            if(tmp.substr(0, name.length) == name){
                tmp = tmp.replace('.js', '');
                var className = tmp.replace(name, '');
                var classFullName = tmp.replace('/', '.');
                //alert(className + ' = ' + classFullName)
                eval(className + ' = ' + classFullName);
                //window[className] = window[classFullName];
                result = true;
                //document.write('<li>' + tmp + '</li>');
            }
        }
    }
    return result;
};

Import.style = function(file){
	document.write('<link href="' + Import.path + file
	+ '" rel="stylesheet" type="text/css" />');
};

Import.getFullPath = function(file){
	var path = Import.path;
	if(typeof(file) != 'undefined'){
		path += file;
	}
	return path;
};

Import.scriptList = function(){
	var content = '<ul>';
	for(var i = 0; i < Import.scripts.length; i++){
		content += '<li>' + Import.scripts[i] + '</li>';
	}
	content += '</ul>';
	document.write(content);
};

Import.load = function(){
    var obj, tmp;
    for(var j = 0; j < Import.scripts.length; j++){
        //var t = j.split(/[.\/]/);
        var script = Import.scripts[j];
        var m = script.substring(0, script.lastIndexOf('.'));
        var t = m.split('/');
        //alert(m);
        for(var i = 0; i < t.length; i++){
            obj = t[i];
            if(i == 0){
                if(!window[obj]){
                    window[obj] = new Object();
                }
                tmp = window[obj];
                //tmp = window[obj] = new Object();
            }
            else if(i < t.length-1){
                if(!tmp[obj]){
                    tmp[obj] = new Object;
                }
                tmp = tmp[obj];
                //tmp = tmp[obj] = new Object;
            }
            else{
                tmp[obj] = window[obj];
            }
        }
    }
};

var neo = {
	/*
	parser:	{},
	lib:	{},
	page:	{},
	widget: {}
	*/
};

Import('myLib/System.js');
Import('neo/lib/Lib.js');
