

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// CORE LIBRARY / NEGORA © 2007
	//
	// Description: General purpose functions.
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// STRING
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function CoreStr () {
	}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT TURNS ANY LOWER CASE AT THE BEGINNING OF A STRING OR AFTER A WHITE SPACE INTO AN UPPER CASE
		//
		// _str				String											S
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreStr.capitalize = function (_str) {
			return _str.replace (new RegExp ("^[a-z]| [a-z]", "gm"),
					function (_match) {
						return _match.toUpperCase ();
					}
				);
		}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT REMOVES WHITE SPACES AT THE BEGINNING AND THE END OF A STRING
		//
		// _str				String											S
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreStr.trim = function (_str) {
			return _str.replace (new RegExp ("^ +| +$", "gm"), "");
		}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT REMOVES EVERY WHITE SPACE, TABULATION, LINE FEED, FORM FEED AND RETURN CARRIAGE OF A STRING 
		//
		// _str				String											S
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreStr.normalize = function (_str) {
			return _str.replace (new RegExp ("[\\s\\r]", "gm"), "");
		}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT UPSIDES A STRING DOWN
		//
		// _str				String											S
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreStr.reverse = function (_str) {
			var mtx_rev = _str.split ("");
			mtx_rev.reverse ();
			return mtx_rev.join ("");
		}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT REPLACES A SEPARATOR AND THE NEXT CHAR BY THE UPPER CASE FORM OF THAT CHAR (OR VICEVERSA)
		//
		// _str			String						S		Syntax: word1[char]word2[char]word3		I.e.: this-is-my-text = thisIsMyText
		// _sep		Separation string		S
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreStr.sepToUpCase = function (_str, _sep) {
			_str = _str.replace (new RegExp (_sep + "[A-Za-z]", "gm"),
				function (_match) {
					return _match.charAt (1).toUpperCase ();
				}
			);
			return _str;
		}
		
		CoreStr. upCaseToSep = function (_str, _sep) {
			_str = _str.replace (new RegExp ("[a-z][A-Z]", "gm"),
				function (_match) {
					return _match.charAt (0) + _sep + _match.charAt (1).toLowerCase ();
				}
			);
			return _str;		
		}
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// LIST
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function CoreList () {
	}


		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT COPIES ONE LIST TO ANOTHER
		//
		// _list				List which will work as font						O
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreList.clone = function (_list) {
			
			var list_clone = new Object ();
			for (var key in _list) {
				list_clone [key] = _list [key];
			}
			return list_clone;
			
		}
	
	
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT JOINS THE VALUES OF A LIST, INCLUDING THE KEYS
		//
		// _list				List which will work as font											O
		// _sep1				Separation string among keys and values						S
		// _sep2				Separation string among pairs of keys and values				S
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		CoreList.join = function (_list, _sep1, _sep2) {
			
			var _str = "";
			for (var key in _list) {
				_str += key + _sep1 + _list [key] + _sep2;
			}
			return _str.substring (0, _str.length - 1);
			
		}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT PROCESSES EVERY ELEMENT OF A LIST USING A PRE-DEFINED OR CUSTOMIZED FUNCTION
		//
		// _list				List															O
		// _type				Type of function which will process the list			S				int | float | custom
		// ? _func_proc		Processor function											O				Only for type "custom"
		//
		// Note 1: "_func_proc" receives the key and the value of the element and must return any value.
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreList.forEach = function (_list, _type, _func_proc) {
			
			var list_out = new Object ();
			
			if (_type == "int") {
				for (var key in _list) {
					list_out [key] = parseInt (_list [key]);
				}
			} else if (_type == "float") {
				for (var key in _list) {
					list_out [key] = parseFloat (_list [key]);
				}
			} else {
				for (var key in _list) {
					list_out [key] = _func_proc (key, _list [key]);
				}
			}
			
			return list_out;
			
		}
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// MATH
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function CoreMath () {
	}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT TURNS A DECIMAL NUMBER INTO A HEXADECIMAL ONE
		//
		// _num				Decimal number										i
		// _length			Length of the hexadecimal number					i
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreMath.decToHex = function (_num, _length) {
		
			var arr_hex = new Array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
			var num_hex = "";
		
			while (_num != 0) {
				num_hex += arr_hex [_num % 16];
				_num = Math.floor (_num / 16);
			}
			
			num_hex = strInverter (num_hex);
			
			while (num_hex.length < _length) {
				num_hex = "0" + num_hex;
			}
			
			return num_hex;
			
		}
	
	
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT TURNS A HEXADECIMAL NUMBER INTO A DECIMAL ONE
		//
		// _num				Hexadecimal number						S
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreMath.hexToDec = function (_num) {
		
			var list_dec = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15};
			
			var num_dec = 0;
			for (var i = 0; i < _num.length; i++) {
				num_dec += list_dec [_num.charAt (i).toLowerCase ()] * Math.pow (16, _num.length - i - 1);
			}
			
			return num_dec;
			
		}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT FORMATS A NUMBER TO THE DESIRED DECIMAL PRECISION
		//
		// _num			Number										d
		// _dec			Decimal precision							i
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreMath.toPrecision = function (_num, _dec) {
			var _num = Math.round (_num * Math.pow (10, _dec)) / Math.pow (10, _dec);
			return (new Number (_num)).toFixed (_dec);
		}
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// GEOMETRY
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function CoreGeom () {
	}
	
	
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT CALCULATES THE COORDINATES OF ONE ENTITY ALIGNED TO ANOTHER ENTITY
		//
		// _list_t					X, Y, W and H of the target element			O
		// _list_r					X, Y, W and H of the reference element		O
		// _align					Horizontal alignment								S				right | center | left | null
		// _valign					Vertical alignment									S				top | middle | bottom | null
		// _type					Type of alignment									S				inner | outter
		//
		// Note 1: It returns the list of coordinates, x and y, of the second  entity.
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreGeom.alignTwo = function (_list_t, _list_r, _align, _valign, _type) {
			
			var x = _list_t ["x"];
			var y = _list_t ["y"];
			
			if (_align == "left") {
				if (_type == "inner") {
					x = _list_r ["x"];
				} else {
					x = _list_r ["x"] - _list_t ["w"];
				}
			} else if (_align == "center") {
				x = _list_r ["x"] + (_list_r ["w"] / 2) - (_list_t ["w"] / 2);
			} else if (_align == "right") {
				if (_type == "inner") {
					x = _list_r ["x"] + _list_r ["w"] - _list_t ["w"];
				} else {
					x = _list_r ["x"] + _list_r ["w"];
				}
			}
			
			if (_valign == "top") {
				if (_type == "inner") {
					y = _list_r ["y"];
				} else {
					y = _list_r ["y"] - _list_t ["h"];
				}
			} else if (_valign == "middle") {
				y = _list_r ["y"] + (_list_r ["h"] / 2) - (_list_t ["h"] / 2);
			} else if (_valign == "bottom") {
				if (_type == "inner") {
					y = _list_r ["y"] + _list_r ["h"] - _list_t ["h"];
				} else {
					y = _list_r ["y"] + _list_r ["h"];
				}
			}
	
			var list_coor = new Object ();
			list_coor = {"x": x, "y": y};
			
			return list_coor;
			
		}
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// VARIABLES
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function CoreVar () {
	}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT GETS THE TYPE OF A VARIABLE
		//
		// _var				Variable							any
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreVar.type = function (_var) {
			
			// If the variable isn't either a function or an object, it prints its type.
			// If not...
			if (typeof (_var).toLowerCase () == "string") {
				return "String";
			} else if (typeof (_var).toLowerCase () != "function" && typeof (_var).toLowerCase () != "object") {
				return typeof (_var);
			} else {
				
				// If the function or object has a constructor, it prints the name of it.
				// If not, it prints the string representation of it.
				if (_var.constructor != null) {
					var list_search = strSearch (_var.constructor.toString ().toLowerCase (), "function[^(]*\\(");
					if (list_search != null) {
						list_search ["text"] = list_search ["text"].replace (" ", "");
						return list_search ["text"].substring (8, list_search ["text"].length - 1);
					} else {
						return "Object";
					}
				} else  {
					
					return "Object";
				}
				
			}
	
		}
	
	

	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// DATE AND TIME
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function CoreDate () {
	}
		
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// IT GETS THE PRESENT TIME EPOCH
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		CoreDate.time = function () {
			return (new Date ()).getTime ();
		}
		
