I use underscore.js methods to detect the type of the variable. Try to use:
isEmpty, isElement, isArray, isArguments, isFunction, isString, isNumber, isBoolean, isDate, isRegExp isNaN, isNull, isUndefined
Described here:
http://documentcloud.github.com/underscore/