Peeq.ReconnectView.prototype = {
    
    updateReconnectTimer: function()
    {

	$('#reconnect_timer').text(this.timeout_time);
	if (this.timeout_time == 0)
	{
	    this.timeout_time = this.saved_timeout * 2;
	    this.saved_timeout = this.timeout_time;
	    this.reset();
	    app.reconnect();
	}
	else
	{
	    if(!this.display)
	    {
		setTimeout("app.reconnectView.updateReconnectTimer()",1000);
		this.timeout_time = this.timeout_time - 1;
	    }
	}
	
    },
    reset: function() {
	this.display = true;
	if(this.saved_timeout < 50)
	{
	    this.timeout_time = this.saved_timeout;
	}
	else
	{
	    this.timeout_time = 50;
	    this.saved_timeout = 50;
	}
    },
    reconnectWithTimer: function()
    {
	if(this.display)
	{
	    var timestamp = $("p#clock").text();

	    var error_html = $('#search_result').clone();
	    error_html.removeAttr('id');
	    error_html.attr('id','reconnect_message');
	    error_html.find('#content').html("You are no longer connected. You will be reconnected in <span id='reconnect_timer'>60</span> seconds. <a href='#' id='reconnect_app' >Reconnect</a> now.<br/><br/><br/>");
	    error_html.find('.time-stamp').text(timestamp);
	    error_html.show();
	    
	    $("#published_items").prepend(error_html.get(0));
	    $('#reconnect_app').click(function() {
		app.reconnect();
	    } );	
	    setTimeout("app.reconnectView.updateReconnectTimer()",1000);
	    this.display = false;
	}
    }
};
