/**
 * Class for parsing css class's which contain bootstrap
 * information
 */
VZT.Parser = {
    /**
     * Parses a class for information
     * @param str - class to parse
     * @param namespace - namespace
     * @param defaults - default values
     * @return arguments
     */
    parse:function(str,namespace,defaults) {
        var reGroup = /(?:\w|\d)*\:\:(\w|\d|\:)[^ ]*/g,
   		    reValues = /((?:\w|\d)[^:]*):((?:\w|\d)[^:]*)/g,
   		    reGetNamespace = /((?:\w|\d)*)\:\:/,
   		    reIsInteger = /^\d*$/,
   		    tempRe = null,
   		    match = null,
   		    namespace = namespace || null,
   		    tests = [],
   		    results = {};

        if (namespace !== null) {
            tempRe = new RegExp(namespace+"\:\:.[^ ]*");
            tests[0] = tempRe.exec(str);
        } else {
            while (match = reGroup.exec(str)) {
                tests.push(match[0]);
            }
        }

        if (tests.length == 1) {
            var test = tests[0],
                ns = reGetNamespace.exec(test),
                res = results;

            while(match = reValues.exec(test))
            {
                //convert to integer if all digits
                if (reIsInteger.test(match[2])) {
                    match[2] = match[2].toInt();
                    //convert to boolean if true or false
                }
                else if (match[2] === 'true' || match[2] === 'false')
                {
                    match[2] = (match[2]==='true')?true:false;
                }

                res[match[1]] = match[2];
            }
        } else {
            tests.each(function(test) {
                var ns = reGetNamespace.exec(test),
                    res = results[ns[1]] = {};

                while(match = reValues.exec(test)) {
                    //convert to integer if all digits
                    if (reIsInteger.test(match[2])) {
                        match[2] = match[2].toInt();

                    //convert to boolean if true or false
                    }
                    else if (match[2] === 'true' || match[2] === 'false')
                    {
                        match[2] = (match[2]==='true')?true:false;
                    }
                    res[match[1]] = match[2];
                }
            });
        }
        for (var d in defaults) {
            if (defaults.hasOwnProperty(d)) {
                if (typeof results[d] === 'undefined') {
                    results[d] = defaults[d];
                }
            }
        }
        return results;
      }
};
