/**
@author Crockford , bibby
A better typeof. Accurately returns null and array.and the objects Number, String, Boolean
Can also be used as an "is_a" or a simple test for truth.
examples:
	var foo = 'bar';
	is(foo); // true;
	is(foo,'string'); // true
	is(foo,'type'); // string
@param mixed variable
@param string (optional) data type
**/
var is = function (v,type)
{
	if(typeof type == 'undefined')
		return !!v;
	
	type=type.toLowerCase();
	if(type == 'nan')
	{
		return isNaN(v);
	}
	
	var vt = typeof v;
	if(vt === 'object')
	{
		if(v)
		{
			if (typeof v.length === 'number' && !(v.propertyIsEnumerable('length')) && typeof v.splice === 'function') 
			{              
				vt = 'array';
			}
			
			// last chance to return new Number() as a number :P
			if(v instanceof Number)
				vt = 'number';
			if(v instanceof String)
				vt = 'string';
			if(v instanceof Boolean)
				vt = 'boolean';
		}
		else
		{
			vt = 'null';
		}
	}
	
	if(type=="type")
		return vt;
	
	return vt == type ? true : false;
};
