// Alert
var idIdent = 0;
var int = new Array;

function setAlert(text, type, obj) {
	if (obj == undefined) obj = "#alerts";
	idIdent++;
	var ret = '<p class="alert-text">'+text+'</p>';
	ret = '<div class="alert-textarea">'+ret+'</div>';
	ret = '<div class="alert-bg"></div>'+ret;
	ret = '<div id="alert_id_'+idIdent+'" class="alert alert-'+type+'">'+ret+'</div>';
	
	$(obj).append(ret);
	alertActions(idIdent);
	if (idIdent>15) idIdent = 0;
}

function alertActions(id) {
	// Hide Flash
	$("object").css("visibility", "hidden");
	$("embed").css("visibility", "hidden");
	// Open Alers
	$("#alert_id_"+id).slideDown("normal");
	// Close Alert Send Form
	$("form").submit(function(){$(".alert").click()});	
	// Close Alerts
	$(".alert").click(function(){removeAlert(this.id);});
	// Auto hide
	int[id] = setTimeout(function(){
		clearInterval(int[id]);
		removeAlert("alert_id_"+id);
	}, 6000);
}

function removeAlert(id) {
	$("#"+id).slideUp("fast", function(){
		$("#"+id).remove();
		// Show Flash
		$("object").css("visibility", "visible");
		$("embed").css("visibility", "visible");
	});
	id = id.split('_');
	id = id.pop();
	clearInterval(int[id]);
}

function alertParse (value) {
	var ret = new Array(3);
	if ($(value).find('alert').length > 0) {
		value = $(value).find('alert');	
		ret['message'] = value.text();
		ret['type'] = value.attr('type');
		ret['extra'] = value.attr('extra');
	} else if ($(value).attr('id') == "ajaxAlert") {
		value = $(value).html().split('{|}');	
		ret['message'] = value[0];
		ret['type'] = value[1];
		ret['extra'] = value[2];
	} else {
		return false;	
	}
	
	return ret;
}

/* deprecated */
function alertXML (value) {
	value = $(value).find('alert');	
	var ret = new Array(3);
	ret['message'] = value.text();
	ret['type'] = value.attr('type');
	ret['extra'] = value.attr('extra');
	return ret;
}