function ListAlert(params) {
    if(params) {
	for(var i in params) this[i] = params[i];
    } else { throw('Error in ListAlert!!!') }
    this.title = document.title;
    this.alertDelete.observe('click', this.deleteAlert.bindAsEventListener(this));
    window.onfocus = window.onFocus = this.ifFocus.bindAsEventListener(this);
    $(document).observe('focus', this.ifFocus.bindAsEventListener(this));
    this.chTitle = 0;
    this.interval = setInterval(this.listen.bind(this, null), this.listenInterval);
}

ListAlert.prototype.ifFocus = function(){
    if(this.chtitleInterval) clearInterval(this.chtitleInterval);
    document.title = this.title;
}

ListAlert.prototype.listen = function(data){
    if(data) {
	if(data.Alert_1_AlertID == this.alertID) return;
	if(data.Alert_1_Type){
		
		var _this = this;
		req_stat(this.templatepath, 'AlertsKeeper', function(){ 
			(function(){
			    this.data = this.prepareData(data);
			    var Alert = new Template(unescape($('AlertType' + data['Alert_1_Type']).innerHTML));
			    this.alertContainer.innerHTML = Alert.evaluate(this.data);
			    this.alertContainer.select('a').each(function(el) {
			    	if(el.readAttribute('phref')) el.href = el.readAttribute('phref');	
			    });
			    this.massObserve('[name="DeleteThis"]','click', this.deleteAlert.bindAsEventListener(this) );
			    this.boosterObserve();
			    this.alertContainer.parentNode.style.display = '';
			    if(this.chtitleInterval) clearInterval(this.chtitleInterval);
			    this.chtitleInterval = setInterval(this.setTitle.bindAsEventListener(this), this.titleInterval);
			}).call(_this);
	    });
	    
	} else {
	    this.alertContainer.parentNode.style.display = 'none';
	    this.ifFocus();
	}
    } else {
	if(this.script) document.body.removeChild(this.script);
	this.script = new Element('script', {'src':this.statusRequestURL + '&var=' + this.objName + '&' + (new Date()).getTime()});
	document.body.appendChild(this.script);
    }
}

ListAlert.prototype.prepareData = function(data){
    for(i in this.myvars) data[i] = this.myvars[i];
    data.photohost = this.photohost;
    data.AvatarChangeTime = (new Date()).getTime();
    data.sex = (data.Alert_1_Sex == 2 ? 'à' : '');
    data.classmatesSex = (data.Alert_1_Sex == 2 ? 'àñü' : 'ñÿ');
    data.back_value = escape(location.href);
    if(data.Alert_1_Event && (/^\-?\d+$/).test(data.Alert_1_Event)) data.Alert_1_JournalID = data.Alert_1_Event;
    this.alertID = data.Alert_1_AlertID;
    if(data['Alert_1_Type'] == 11 || data['Alert_1_Type'] == 20 || data['Alert_1_Type'] == 21) 
		data['Alert_1_Event'] = this.eventUnescape(data['Alert_1_Event']);
	if(data['Alert_1_Type'] == 13 || data['Alert_1_Type'] == 14 || data['Alert_1_Type'] == 15 || data['Alert_1_Type'] == 18 || data['Alert_1_Type'] == 21) {
		if(data.Alert_1_UserAvatarDir && data.Alert_1_UserAvatarID) {
			var small = (data['Alert_1_Type'] == 18 || data['Alert_1_Type'] == 21) ? 'small' : '';
			data.comm_avatar_url = this.photohost + data.Alert_1_UserAvatarDir + '_cavatar' + small + '/' +
									data.Alert_1_UserAvatarID + '?' + data.AvatarChangeTime;
		}
		else {
			data.comm_avatar_url = "http://img0.imgsmail.ru/mail/ru/images/community.jpg";
		}
	}
    return data;
}

ListAlert.prototype.setTitle = function(){
    this.chTitle = !this.chTitle;
    if(this.chTitle) document.title = this.alertContainer.getElementsByTagName('h5')[0].lastChild.nodeValue;
    else document.title = this.title;
}

ListAlert.prototype.deleteAlert = function(t){
    $(this.alertContainer.parentNode).hide();
    if(t && t.responseText) {
	this.ifFocus();
	if(this.hideAlert) this.hideAlert = 0;
	this.listen();
    } else {
    // data from JSON is splitted by ':' or '='
    // DO NOT USE '=' for inside of JSON or foto will blow up! There is used some other Ajax.Request...
	new Ajax.Request(this.requestURL + '?ajax_call=1&func_name=perl_delete_alert', {
	    method: 'post',
	    postBody: 'data=' + [(this.alertID ? 'id:' + this.alertID : this.mSpec ? this.mSpec + ':1' : 'mid:' + this.mSubmited)].toJSON(),
	    onSuccess: this.deleteAlert.bindAsEventListener(this)
	});
    }
}
ListAlert.prototype.eventUnescape = function(text) {
    text = text.replace(new RegExp("&lt;", "gi"), '<');
    text = text.replace(new RegExp("&gt;", "gi"), '>');
    text = text.replace(new RegExp("&quot;", "gi"), '"');
    text = text.replace(new RegExp("&amp;nbsp;", "gi"), ' ');
    text = text.replace(new RegExp("&amp;laquo;", "gi"), '«');
    text = text.replace(new RegExp("&amp;raquo;", "gi"), '»');
    return text;
}
ListAlert.prototype.massObserve = function(tags, event, observer){
    var elements = this.alertContainer.select(tags);
    for(var i = 0;i < elements.length; i++) elements[i].observe(event, observer);
    return elements;
}
ListAlert.prototype.boosterObserve = function(){
    if(window.Booster.inited) {
    	Booster.fetchAnchors(this.alertContainer);
    }
}
