/**
 * Nephilim Toolbox v1.0: A collection of useful functions - http://www.thenephilim.com.ar/toolbox
 *
 * Nephilim Toolbox is (c) 2007 Luciano Longo and is released under the GNU GPL License:
 * http://www.gnu.org/licenses/gpl.html
 *
 */

if(typeof nephilim == "undefined") var nephilim = new Object();

nephilim.toolbox = function() {
	this.hexes = [0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"];
}

nephilim.toolbox.prototype = {
	about:function() {
		lines = "Nephilim Toolbox v1.0\n";
		lines += "A collection of useful functions.\n";
		lines += "http://www.thenephilim.com.ar/toolbox\n";
		lines += "**************************************************\n";
		lines += "* Nephilim Toolbox (c) 2007 Luciano Longo AKA The_Nephilim\n";
		lines += "* Released under GNU GPL\n";
		lines += "* http://www.gnu.org/licenses/gpl.html\n";
		lines += "**************************************************";
		alert(lines);
	},
	d2h: function(dec) {
		h2 = '';
		f = Math.floor(dec/16);
		mod = dec%16;
		h2 = this.hexes[mod] + h2;
		
		while(f >= 16) {
			ftmp = Math.floor(f/16);
			mod = f%16;
			h2 = this.hexes[mod] + h2;
			f = ftmp;
		}
		h1 = this.hexes[f];
		return h1 + h2;
	},
	h2d: function(hex) {
		//You should know that there's no need to use this function anyway, you can add a 0x at the beginning of the hex number and that will return it's value in a decimal form
		return parseInt(hex,16);
	},
	roundXDec: function(n,x) {
		var xpow = Math.pow(10,x);
		return Math.round(n*xpow) / xpow;
	},
	randColor:function() {
		r = Math.round(Math.random()*255);
		g = Math.round(Math.random()*255);
		b = Math.round(Math.random()*255);
		return "#" + this.d2h(r) + this.d2h(g) + this.d2h(b);
	},
	randHexColor:function() {
		r = Math.round(Math.random()*255);
		g = Math.round(Math.random()*255);
		b = Math.round(Math.random()*255);
		return "0x"+ this.d2h(r) + this.d2h(g) + this.d2h(b);
	},
	random2:function(i,f) {
		return Math.random() * (f-i) + i;
	}
}

var Toolbox = nephilim.toolbox;
