//
// BrowserSession
//

$(function()
{
	BrowserSession.init();
});

var BrowserSession =
{
	intervals: [1000, 3000, 5000, 10000, 30000],
	intervalindex: 0,
	intervalmax: 5,
	
	defaultlink: "/session/ping",
	
	init: function()
	{
		this.wait();
	},
	
	wait: function()
	{
		setTimeout($.proxy(this.update, this), 
			this.intervals[this.intervalindex]);
		
		if(this.intervalindex < this.intervalmax-1)
			this.intervalindex++;
	},
	
	update: function()
	{
		$.get(this.defaultlink, "", $.proxy(this.receive, this))
			.error($.proxy(this.wait, this));
	},
	
	receive: function(data)
	{
		var s = "<a href=\'/user/online\'>Who\'s Online (" + $("online", data).text() + ")</a>";
		$("#whos_online").html(s);
		
		var needrefresh = $("refresh", data).text();
		if(needrefresh == 1) refreshContentPage();
		
		this.wait();
	},
	
	
	dum: 0
};




///
//var s = "<a href=\'index.php?r=user/online\'>Who\'s Online (" + $("online", data).text() + ")</a>";
//$("#whos_online").html(s);
//
//if($("inbox", data).text() != '0')
//{
//	var s = "<a href=\'index.php?r=pm/inbox\'>My Inbox (" + $("inbox", data).text() + ")</a>";
//	$("#inbox").html(s);
//}
//
//if($("call", data).text() != '0')
//{
//	var s = "<a href=\'index.php?r=call/list\'><font color=red>New Call (" + $("call", data).text() + ")</font></a>";
//	$("#incoming_cell").html(s);
//
//	count = 2;
//	setTimeout("gotcall1()", 500);
//	
//	//PlaySound("sound1");
//}
//function PlaySound(soundObj)
//{
//	var sound = document.getElementById(soundObj); 
//	sound.Play(); 
//}

//function gotcall1()
//{
//	if(!count) return;
//	count--;
//	
//	$("#incoming_cell").hide();
//	setTimeout("gotcall2()", 200);
//}
//
//function gotcall2()
//{
//	$("#incoming_cell").show();
//	setTimeout("gotcall1()", 500);
//}

