/* jshint sub: true */
window['makeEmoji'] = function(name) {
    var emoji,
        emojiName;

    if (typeof(name) === "string") {
        for (var i =0, nbEmojis = emojis.length; i < nbEmojis && !emoji; i++) {
            var emojiNames = emojis[i].names;

            for (var j=0, nbEmojiName = emojiNames.length ;j < nbEmojiName && !emoji; j++)
                if (emojiNames[j] === name)
                    emoji = emojis[i];
            emojiName = name;
        }
    } else {
        emoji = name;
        emojiName = emoji["names"][0];
    }
    if(emoji) {
        var dom = document.createElement("span");
        dom.className="emoji emojione emojione-64 emojione-64-" +emoji["sprite"] +" _" +emoji["unicode"];
        dom.textContent = ':' +emojiName +':';
        dom.title = emojiName;
        return dom;
    }
    return null;
};

window['emojiProviderHeader']="emojione.logo.svg";

window['searchEmojis'] = function(queryString, nameOnly) {
    var result = {},
        queryLength = queryString.length;

    lp: for (var emojiIndex =0, nbEmojis = emojis.length; emojiIndex < nbEmojis; emojiIndex++) {
        var currentEmoji = emojis[emojiIndex];

        for (var nameIndex =0, nbNames = currentEmoji.names.length; nameIndex < nbNames; nameIndex++) {
            if(currentEmoji["names"][nameIndex].substr(0, queryLength) === queryString) {
                result[currentEmoji["names"][0]] = currentEmoji;
                continue lp;
            }
        }
        if (!nameOnly)
            for (var keywordIndex =0, nbKeywords = currentEmoji["keywords"].length; keywordIndex < nbKeywords; keywordIndex++) {
                if(currentEmoji["keywords"][keywordIndex].substr(0, queryLength) === queryString) {
                    result[currentEmoji["names"][0]] = currentEmoji;
                    break;
                }
            }
    }
    return result;
};

