
var wowhead_loader_image = function(aobj, json) {
    if (json.icon)
        Element.insert(aobj, {before: '<img src="http://static.wowhead.com/images/wow/icons/large/'+json.icon.toLowerCase()+'.jpg" alt="[icon '+json.name+']" width="16" height="16" style="vertical-align: bottom;" title="'+json.name+'" />'});
}

Event.observe(window, 'load', function() {

var items = new Array();
var spells = new Array();
var nonee = $$('a').each(function(atag) { 
    var item = atag.href.match(/item=([0-9]+)/); 
    if (item) {
        items.push(item[1]);
        atag.addClassName('item'+item[1]);
    }
    var spell = atag.href.match(/spell=([0-9]+)/); 
    if (spell) {
        spells.push(spell[1]);
        atag.addClassName('spell'+spell[1]);
    }
});

var url = '/wp-content/plugins/wowhead_qualifier/wowhead_proxy.php';

var ar = new Ajax.Request(url, {
    parameters: {items: items.join(','), spells: spells.join(',')},
    
    onSuccess: function(transport, json) {
        for (var i in json) {
            var aobjs = $$('.item'+i);
            aobjs.each(function(aobj) {
                if (json[i].quality) aobj.addClassName('q'+json[i].quality)
                wowhead_loader_image(aobj, json[i]);
            });
            var aobjs = $$('.spell'+i);
            aobjs.each(function(aobj) {
                wowhead_loader_image(aobj, json[i]);
            });
        }
    }
});

});
