var BackgroundData= function(){
	this.requestStart= 0;
	this.requestEnd= 0;
};
BackgroundData.prototype.get= function()
{
	this.requestStart= new Date().toLocaleString();
	document.getElementById('onlinerTree').style.backgroundColor= '#FF0000';
	$.ajax({
		url: uri_root+'/include/ajax.php'
		, data: 'json'
		, async: true
		, success: function(json)
		{
			document.getElementById('onlinerTree').style.backgroundColor= 'transparent';
			backgroundData.requestEnd= new Date().toLocaleString();
			eval('var data = (' + json + ')');
			backgroundData.setOnliner(data);
			backgroundData.setPM(data);
			backgroundData.setTrade(data);
			backgroundData.setInfo(data);
			backgroundData.community(data);
			backgroundData.initGet();
		}
		, error: function()
		{
			backgroundData.initGet();
		}
	});
};
BackgroundData.prototype.setOnliner= function(data)
{
	var onlinerTree= document.getElementById('onlinerTree');
	while(onlinerTree.hasChildNodes())
	{
		onlinerTree.removeChild(onlinerTree.firstChild);
	}
	//data.onliner['requestStart ' + this.requestStart]= 0;
	//data.onliner['requestEnd ' + this.requestEnd]= 0;
	for(var i in data.onliner)
	{
		var onlinerTreeNode= document.createElement('li');
		var onlinerTreeNodeLink= document.createElement('a');
		var onlinerTreeNodeLinkText= document.createTextNode('');
		if(user_id){
		onlinerTreeNodeLink.setAttribute('href', uri_root+'/usrctrl/user.php?user=' + data.onliner[i]);
		onlinerTreeNodeLink.setAttribute('onmousedown', 'if(event.button==2){this.oncontextmenu = function(){return false;}; chatWith("'+i+'")}');
		onlinerTreeNodeLink.setAttribute('title', 'Zum Profil von '+i+' (Oder mit Rechtsclick Chat Starten)');
		}
		onlinerTreeNodeLinkText.nodeValue= i; //+ ' (id: ' + data.onliner[i] + ')';
		onlinerTreeNodeLink.appendChild(onlinerTreeNodeLinkText);
		onlinerTreeNode.appendChild(onlinerTreeNodeLink);
		onlinerTree.appendChild(onlinerTreeNode);
		
	}
};
BackgroundData.prototype.setPM= function(data)
{
	if(data.pm.unread > 0)
	{
		document.getElementById('pmindicator_text').innerHTML = '('+data.pm.unread+')';
	}
};
BackgroundData.prototype.setTrade= function(data)
{
	if(data.trade.questing > 0)
	{
		document.getElementById('tradeindicator_text').innerHTML = '('+data.trade.questing+')';
	}
};
BackgroundData.prototype.setInfo= function(data)
{
	if(data.trade.questing > 0 || data.pm.unread > 0)
	{
		var info_value = (data.trade.questing*1) + (data.pm.unread*1);
		document.getElementById('info_indicator').innerHTML = '('+info_value+')';
	}
};
BackgroundData.prototype.community= function(data)
{
	if(data.sets.newsets > 0)
	{
		var community_value = (data.sets.newsets*1);
		document.getElementById('community_indicator').innerHTML = '('+community_value+')';
	}
	if(data.sets.newsets > 0)
	{
		var cards_value = (data.sets.newsets*1);
		document.getElementById('cards_indicator').innerHTML = '('+cards_value+')';
	}
	if(data.sets.newsets > 0)
	{
		document.getElementById('newsets_indicator').innerHTML = '('+data.sets.newsets+')';
	}
};
BackgroundData.prototype.initGet= function()
{
	window.setTimeout('backgroundData.get()', 60000);
};
var backgroundData= new BackgroundData();

