
var timer;
var count;

function check() {
    count += 1;
    var myAjax = new Ajax.Request(
	'http://easystreaming.lootil.eu/login.php?check=true&count=' + count,
	{
	    method: 'post',
	    parameters: '',
	    asynchronous: true,
	    onSuccess: function(o) {
		var r = o.responseText;
		var v = eval('(' + r + ')');

		clearInterval(timer);
		if (v.logged) {
		    window.location = v.location;
		}

		// timeout ?
		Lightview.hide();
	    },
	}
    );
}

function login() {
    count = 0;
    // tries every 2s
    timer = setInterval('check()', 2000); 
}

document.observe('lightview:hidden', function() {
    clearInterval(timer);
});

