(function() {

$WowheadPower.customDisplay=function(id,obj) {
	var el=document.getElementById('WH'+id);
	if (el) {
		var locale=el.locale;
		locale=((locale=='www')||(!locale))?'enus':locale+locale;
		el.innerHTML=obj['name_'+locale];
		if (obj.quality) el.className+=" q"+obj.quality;
		el.id=null; // only one execution
		return true;
	}
	return false;
}

var type=['Item','Quest','Spell','Achievement','Npc','Object'];
for(i=0;i<type.length;i++) {
	$WowheadPower['OldRegister'+type[i]]=$WowheadPower['register'+type[i]];
	$WowheadPower['register'+type[i]]=new Function('id,num,obj', 'if (!this.customDisplay(id+"-'+type[i].toLowerCase()+'",obj)) {this["OldRegister'+type[i]+'"](id,num,obj); }');
}

var aList=document.getElementsByTagName('a');
for(i=0;i<aList.length;i++) {
	var aMatch=aList[i].href.match(/^http:\/\/(.+?)?\.?wowhead\.com\/\??(item|quest|spell|achievement|npc|object)=([0-9]+)/);
	if(aMatch) {
		aList[i].locale=aMatch[1];
		aList[i].setAttribute('id','WH'+aMatch[3]+'-'+aMatch[2]);
		var aScript=document.createElement('script');
		aScript.type='text/javascript';
		aScript.src=aList[i].href+'&power';
		document.getElementsByTagName('head')[0].appendChild(aScript);
	}
}

})();
