
/**
 * @fileoverview Glowna klasa systemu posiadajaca
 * metody uzatwiajace wykonanie podstawowych operacji.
 *
 * @version 1.5 2006/03/08
 */

/*
myLib = {
	contents:	{},
	data:		{},
	effects:	{},
	events:		{},
	form:		{},
	html:		{},
	http:		{},
	layers:		{},
	native:		{},
	patterns:	{},
	sajax:		{},
	text:		{},
	util:		{}
};
*/

/**
 * @constructor
 */
function System(){
	/**
	 * @type	String
	 * @public
	 */
	this.classPath = ''; // set inherit file
};

//myLib.Lib = System;

/**
 * @type	String
 * @public
 */
System.resourcesPath = 'myLib/_resources/';

/**
 * @public
 * @param	Function	Cialo funkcji.
 * @return	Object
 */
System.subClass = function(func){
	var func = System.getValue(func, this.prototype.constructor);
	for(var i in this){
		func[i] = this[i];
	}
	func.prototype = new this();
	func.prototype.constructor = func;
	func.prototype.parent = new this();
	func.prototype.parent.constructor = func;
	return func;
};

/**
 * Pozwala skopiowac metody prototypowe do innej klasy.
 * System.inherit(new myWidget.Widget, this);
 * @public
 * @param	Object
 * @param	Object
 * @return	void
 */
System.inherit = function(src, desc){
	for(var i in src){
		desc[i] = src[i];
	}
};

/**
 * @public
 * @return	String
 */
System.prototype.getClassPath = function(file){
	var path = Import.path + this.classPath;
	if(typeof(file) == 'string'){
		path += file;
	}
	return path;
};

/**
 * @public
 * @return	String
 */
System.prototype.getResourcesPath = function(file){
	return System.getResourcesPath(file);
};

/**
 * @public
 * @return	String
 */
System.getResourcesPath = function(file){
	return Import.getFullPath(System.resourcesPath + file);
};

//-------------------------------------------------------------------

/**
 * @public
 * @return	Boolean
 */
System.isNull = function(value){
	return (typeof(value) == 'object' && value == null);
};

/**
 * @public
 * @return	Mixed
 * //return System.getVariable('undefined', null, x, value);
 */
System.getValue = function(x, value){
	if(typeof(value) == 'undefined'){
		var value = '';
	}
	if(typeof(x) == 'undefined' || x == null){
		var x = value;
	}
	return x;
};

/**
 * @public
 * @return	Object
 */
System.getObject = function(x, value){
	return System.getVariable('object', null, x, value);
};

/**
 * @public
 * @return	String
 */
System.getString = function(x, value){
	return System.getVariable('string', '', x, value);
};

/**
 * @public
 * @return	Number
 */
System.getNumber = function(x, value){
	return System.getVariable('number', 0, x, value);
};

/**
 * @private
 * @param	String
 * @param	Mixed
 * @param	Mixed
 * @param	Mixed
 * @return	Mixed
 */
System.getVariable = function(t, s, x, v){
	var v = System.getValue(v, s);
	if((typeof(x) != t) || (typeof(x) == t && x == s)){
		var x = v;
	}
	return x;
};

/**
 * Zwraca element ze struktury DOM.
 * @public
 * @param	Mixed	Element DOM lub jego id.
 * @return	Object	DOM object.
 */
System.getElement = function(element){
	if(typeof(element) == 'string'){
		element = document.getElementById(element);
	}
	return element;
};

System.show = function(obj){
	var result = '';
	if(typeof(obj) == 'object'){
		for(var i in obj){
			result += '\n' + i + ' = ' + obj[i];
		};
	}
	else{
		result = obj;
	}
	alert('type: ' + typeof(obj) + '\nvalue: ' + result);
};
