/*
Author: Matt Mayers	http://mattmayers.com/
*/

function wowheadLinks(){
	
	$('<div id="ajax_loading_indicator" style="display:none;z-index:1;position:fixed;right:0px;top:0px;background-color:#F00;color:#FFF;padding:3px;"><p> Updating Itemlinks ... </p></div>').appendTo("body");

	$('#ajax_loading_indicator').ajaxStart(
		function() {
			$(this).show();
		}
	);
	$('#ajax_loading_indicator').ajaxStop(
	        function() {
	                $(this).hide();
	        }
	);


	$('.wowhead').each(function(){
		var el = $(this)
		$.ajax({
			type: "GET",
			url: el.attr('href'),
			dataType: "xml",
			timeout: 10000,
			success: function(data){
				el.attr('href',$('link',data).text())
				el.addClass('q'+$('quality',data).attr('id'))
			}
		})
	})
}


$(document).ready(function(){
	$("head").append('<script src="http://www.wowhead.com/widgets/power.js"></script>');
	wowheadLinks();
});
