function Steam() {
	var ran;
	var basePath;
	var objs = new Array();
	var ids = new Object();
	var cache = new Object();
	var ROOT;
	
	this.run = function() {
		if (!ran) {
			var scr = $('script[src$=\'steam.js\']');
			ROOT = scr.attr('src').replace('static/js/steam.js','');
			ran = true;
			this.refresh();
		} else {
			return;
		}
	}
	this.refresh = function() {
		objs = $('.steamInfo[id]');
		objs.each(function() {
			profileid = $(this).attr("id").substr(5);
			$(this).css("padding","3px").html("");
			if (cache[profileid] == null) {
				$("<div />").addClass("st-loading").prependTo(this);
				ids[profileid] = true;
			} else {
				$(this).html(cache[profileid]);
			}
		});
		for (key in ids) {
			if (cache[key] == null) {
				profileData(key);
			}
		}
	}
	
	
	function xmlURL(id) {
		return ROOT+'steam/profilexml/'+id;
	}
	function profileData(id) {
		jQuery.ajax({
			type: 'GET',
			url: xmlURL(id),
			dataType: 'xml',
			complete: function(request,status) {
				setProfileHTML(id,$(request.responseXML));
			}
		});
	}
	function setProfileHTML(id,data) {
		var statusimg;
		var status;
		var name;
		var avatar;
		
		if (data.find('profile').length != 0) {
			if (data.find('profile > steamID').text() == '') {
				name = "(Unknown)";
			} else {
				name = data.find('profile > steamID').text();
				status = data.find('profile > onlineState').text();
				avatar = data.find('profile > avatarIcon').text();
				id64 = data.find('profile > steamID64').text();
			}
		} else if (data.find('response').length != 0) {
			name = "("+(data.find('response > error').text())+")";
		} else {
			name = "(Invalid Data)";
		}

		cache[id] = '<div class="steam '+status+'"><a href="http://steamcommunity.com/profiles/'+id64+'" target="_blank"><div class="avatar" style="background-image: url(\''+avatar+'\');"></div></a><div class="name"><a href="'+ROOT+'user/profiles/'+id64+'">'+name+'</a></div></div>';
		
		$(".steamInfo#steam"+id).html(cache[id]);
	}
}
