// JavaScript Document

var tempoTransizione = 500;
var tempoPermanenza = 15;

$(document).ready(function()
{
	$(".terna").hide();
	$(".active").show();
	$("#notizia_prev").click(function() {
		var prev = $(".active").prev();
		
		if (prev.hasClass("terna"))
		{
			$(".active").hide("slide", {direction: "right"}, tempoTransizione, function() {});
			$(".active").removeClass("active");
			prev.addClass("active");
			$(".active").show("slide", {direction: "left"}, tempoTransizione, function() {});
		}
	});
	
	$("#notizia_next").click(function() {
		var next = $(".active").next();
		
		if (next.hasClass("terna"))
		{
			$(".active").hide("slide", {direction: "left"}, tempoTransizione, function() {});
			$(".active").removeClass("active");
			next.addClass("active");
			$(".active").show("slide", {direction: "right"}, tempoTransizione, function() {});
		}
		else
		{
			inizio();
		}
	});
	
	mostraPopup();
});

function chiudiPromo()
{
	$("#notizia_popup_1").fadeOut();
	$("#notizia_overlay_1").fadeOut();
}

function mostraPopup()
{
	$("#notizia_overlay_1").hide();
	$("#notizia_overlay_1").css("opacity", 0);
	$("#notizia_overlay_1").width($(document).width());
	$("#notizia_overlay_1").height($(document).height());
	$("#notizia_overlay_1").css("left", 0);
	$("#notizia_overlay_1").css("top", 0);
	$("#notizia_overlay_1").css("z-index", 5000);
	$("#notizia_overlay_1").show();
	
	$("#notizia_popup_1").hide();
	$("#notizia_popup_1").css("left", (($("#notizia_overlay_1").width()/2) - ($("#notizia_popup_1").width()/2)));
	$("#notizia_popup_1").css("z-index", 6000);
	$("#notizia_popup_1").show();
	
	setTimeout("chiudiPromo()", 60000);
}

function inizio()
{
	var prev = $(".active").prev();
	if (prev.hasClass("terna"))
	{
		$(".active").hide("slide", {direction: "right"}, tempoTransizione/2, function() {});
		$(".active").removeClass("active");
		prev.addClass("active");
		$(".active").show("slide", {direction: "left"}, tempoTransizione/2, function() {
			inizio();
		});
	}
}

