var null_element = 0;
function spsGetElementById(id) {
	if (document.getElementById(id)) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers && document.layers[id]) {
		return (document.layers[id]);
	} else {
		return null_element;
	}
}

function openCentered(url,name,width,height){
	var WW = width;
	var HH = height;
	var TT = screen.height / 2 - HH / 2;
	var LL = screen.width / 2 - WW / 2;
	var opts = 'width='+WW+',height='+HH+',top='+TT+',left='+LL+',innerWidth='+WW+',innerHeight='+HH+',status=no,scrollbars=yes,resizable=no,menubar=no,copyhistory=no,toolbar=no,location=no,directories=no';
	var new_window = window.open(url,name,opts);
	new_window.focus();
	
	if( typeof( new_window.innerWidth ) == 'number' ) {
		//Non-IE
		new_window.innerWidth = WW;
		new_window.innerHeight = HH;
	} else if( new_window.document.documentElement && ( new_window.document.documentElement.clientWidth || new_window.document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		new_window.document.documentElement.clientWidth = WW;
		new_window.document.documentElement.clientHeight = HH;
	} else if( new_window.document.body && ( new_window.document.body.clientWidth || new_window.document.body.clientHeight ) ) {
		//IE 4 compatible
		new_window.document.body.clientWidth = WW;
		new_window.document.body.clientHeight = HH;
	}
}

function DoBlink() {
	$.getJSON("hasnotify.php", function(j){
		if( j.length > 0 ) {
			if( j[0].hasNotify ) {
				if( $("#notifica").css('display') == 'none' ) {
					$("#notifica").attr('style', 'display: block');
				}
				$("#notifica").fadeOut(150).fadeIn(150).fadeOut(150).fadeIn(150).fadeOut(150).fadeIn(150).fadeOut(150).fadeIn(150);
			} else {
				$("#notifica").attr('style', 'display: none');
			}
		} else {
			$("#notifica").attr('style', 'display: none');
		}
	})	
}

$(document).ready(function(){
	var hi = spsGetElementById('homeimg');
	if( hi != null_element ) {
		$("#homeimg").hide();
		$("#homeimg").fadeIn(4000);
	}
	if ( $("#notifica").length > 0 ) {
		DoBlink();
		setInterval( 'DoBlink()', 5000 );
	}
	$('#mostranotifica').click(function() {
		openCentered( 'mostranotifica.php', 'NOTIFICA', 600, 400 );
	});
});