function OpenWin (Url,Nome,Parametri)
{
	NewWin = null
	NewWin = open(Url, Nome, Parametri)
	NewWin.focus()
}
function OpenWinAdmin (Url,Nome,Parametri)
{
	NewWin = null
	NewWin = open(Url,Nome,Parametri)
	NewWin.moveTo(screen.availWidth/100*30,0)
	NewWin.resizeTo(screen.availWidth/100*70,screen.availHeight)
	NewWin.focus()
}
function OpenWinAgeAttReg(Par)
{
	OpenWin('/Agenti/Attivita/AttivitaRegistra.asp?' + Par,'AttivitaRegistra','width=600,left=20,top=20,height=500,toolbar=no,directories=no,location=no,status=no,statusbar=no,resizable=0,menubar=no,scrollbars=yes')
}
function OpenWinAgeAtt()
{
	OpenWin('/Agenti/Attivita/Attivita.asp','AttivitaAgente','width=750,left=0,top=0,height=screen.availHeight,toolbar=no,directories=no,location=no,status=no,statusbar=no,resizable=1,menubar=no,scrollbars=yes')
}
function FinestraConferma(Testo)
{
	Risp = confirm(Testo)
	return Risp
}

function InviaForm(NomeForm, ParametriAgg)
{
	NomeForm.action = NomeForm.action + ParametriAgg
	NomeForm.submit()
}

function CtrlDivFromBox (BoxValue)
{
	if (BoxValue == 0)
		return ('none')
	else
		return ('')
}
function RidWinImg(NomeImg, LargAgg, AltAgg)
{
	var oImg = document.all[NomeImg];
	var w, h;
	if (oImg.width+30 > window.screen.width)
		w = window.screen.width;
	else
		w = oImg.width+LargAgg;
	if (oImg.height+40 > window.screen.height)
		h = window.screen.height;
	else
		h = oImg.height+AltAgg;
	window.resizeTo(w,h);
//			window.moveTo((window.screen.width-w)/2,(window.screen.height-h)/2);					
}
var ns6=document.getElementById&&!document.all
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1


function doOutline(e) {
	var targetId, srcElement, targetElement;
	srcElement=ns6? e.target : event.srcElement
//	srcElement = window.event.srcElement;
	if (srcElement.className == "Outline"||srcElement.className == "Outline2") {
		srcElement = srcElement.id
		srcElement = srcElement.substr(0, srcElement.length-1);
		targetId = srcElement + "s";
		srcElement = srcElement + "i";
		srcElement = document.getElementById(srcElement);
		targetElement = document.getElementById(targetId);
		if (srcElement != null) {
			var NuovaImmagine = srcElement.src
			if (targetElement.style.display == "none") {
				targetElement.style.display = "";
				srcElement.src = NuovaImmagine.replace("Chiuso", "Aperto");
			} else {
				targetElement.style.display = "none";
				srcElement.src = NuovaImmagine.replace("Aperto", "Chiuso");
			}
		}
	}
}

document.onclick = doOutline;

// google analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-6255149-57']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
// fine google analytics


$(document).ready(function() {		
	
	//Execute the slideShow
	slideShow();

});

function slideShow() {

	//Set the opacity of all images to 0
	$('#galleria a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#galleria a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#galleria .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#galleria .caption').css({width: $('#galleria a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#galleria .content').html($('#galleria a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the galleria function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('galleria()',6000);
	
}

function galleria() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#galleria a.show')?  $('#galleria a.show') : $('#galleria a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#galleria a:first') :current.next()) : $('#galleria a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#galleria .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#galleria .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#galleria .content').html(caption);
	
	
}


