﻿function PopZoom(img)  {
	var nFoto='Foto_'+Math.round(50000*Math.random());
	var MyLayer =(MyLayer)? MyLayer : 'Div'+nFoto;
	var Img=['ZoomPiu.gif','ZoomMeno.gif','ZoomNormale.gif'];
	Img=ImageLoadArray(Img,Tema);	
	var titolo=(img.title)? img.title : (img.alt)? img.alt :  "Senza Nome";
	var foto='<img src="'+ img.src +'" border="0" id="'+ nFoto +'" alt="'+ titolo +'">';
	var footer='<table onmouseout="ColorePulsante(\''+ MyLayer+'ZoomPiu\');ColorePulsante(\''+ MyLayer +'ZoomMeno\');ColorePulsante(\''+ MyLayer +'ZoomImg\');KillTimer();">'+
				'<tr>'+
					'<td><a href="#" '+
						'onmousedown="ZoomScroll(\''+ nFoto +'\',40);ColorePulsante(\''+ MyLayer +'ZoomPiu\',\'#00FF50\');" '+
						'onmouseup="ColorePulsante(\''+ MyLayer+'ZoomPiu\');KillTimer();" '+
						'title=" + Zoom">'+
						'<img id="'+MyLayer+'ZoomPiu" src="'+Img[0].src+'" alt="+ Zoom" border="0"></a></td>'+
					'<td><a href="#" '+
						'onmousedown="ColorePulsante(\''+ MyLayer +'ZoomImg\',\'#00FF50\');" '+
						'onclick="ResizeFoto(\''+nFoto+'\','+ MyLayer +'Object.Contenitore.Width,'+ MyLayer +'Object.Contenitore.Height);" '+
						'onmouseup="ColorePulsante(\''+ MyLayer+'ZoomImg\');KillTimer();" '+
						'title="Rendi visibile nella finestra">'+
						'<img id="'+MyLayer+'ZoomImg" src="'+Img[2].src+'" border="0" alt="Rendi visibile nella finestra"></a></td>'+
					'<td><a href="#" '+
						'onmousedown="ColorePulsante(\''+ MyLayer +'ZoomMeno\',\'#00FF50\');ZoomScroll(\''+ nFoto +'\',-40);" '+
						'onmouseup="ColorePulsante(\''+ MyLayer +'ZoomMeno\');KillTimer();" '+
						'title=" - Zoom"><img id="'+MyLayer+'ZoomMeno" src="'+Img[1].src+'" alt=" - Zoom" border="0"></a></td>'+
				'</tr>'+
			'</table';
			
	var obj = PopUP(titolo, '',"../themes/foto.gif", MyLayer);
	obj.WriteFooter(footer);
	obj.Write(foto);
	ResizeFoto(nFoto, obj.Width,obj.Height);
	return obj
};
function ZoomScroll(foto, move){
	this.fotoimg=document.images[foto];
	this.fotoimg.width+=move;
	if (this.fotoimg.width>100) timer = setTimeout("ZoomScroll(this.fotoimg.id,"+move+");", speed);
	else this.fotoimg.width=100;
};
function ResizeFoto(foto, w,h){
	if (document.images[foto]){
		h=parseInt(h-70);
		w=parseInt(w);
		document.images[foto].width=0;
		do{	document.images[foto].width++;
		} while(document.images[foto].height<h && document.images[foto].width<=w);
	}
};
function TimedFoto(foto, tempo) {
	var indice = eval('indice_'+foto);	
	var mylista=eval('Lista'+foto+'['+(1+indice++)+']');
	tempo=(tempo>0)? tempo : 5000;
	GalleryFoto(foto);
	ColorePulsante('Start'+foto,'#50FF50');
	ColorePulsante('Alt'+foto,'#FF3030');
	eval('indice_'+foto+'='+(!mylista? 0 : indice));
	eval('Timer'+foto+'=setTimeout("TimedFoto(\''+foto+'\', '+tempo+')",'+tempo+')')
};
function StepAFoto(foto) {
	eval('indice_'+ foto +'=(indice_'+ foto +'++<(Lista'+ foto +'.length-1))? indice_'+ foto +' : 0;');
	DoGallery(foto);
};
function StepBFoto(foto) {
	eval('indice_'+ foto +'=(indice_'+ foto +'-->0)? indice_'+ foto +' : (Lista'+ foto +'.length-1);');
	DoGallery(foto);
};
function StopTimedFoto(foto){
	var tempo=eval('Timer'+foto);
	if (tempo) { 
		ColorePulsante('Alt'+foto,'transparent');
		ColorePulsante('Start'+foto,'transparent'); 
		KillTimer(tempo);
	}
};
function GalleryFoto(foto) {
	var mylista=eval('Lista'+ foto +'[indice_'+ foto +']');
	Oggetto('Didascalia'+foto).innerHTML='<span class="PopGalleryDidascalia">'+mylista[1]+'</span>';
	document.images[foto].src="../images/"+mylista[0];
	
//	while (!document.images[foto].complete);
	
	var obj=eval('Div'+ foto +'Object');
	ResizeFoto(foto, obj.Width-160, obj.Height);
};
function ColorePulsante(foto, colore){
	if (document.images[foto]) document.images[foto].style.background=(colore? colore : 'transparent');
};
function DoGallery(foto){	
	StopTimedFoto(foto);
	GalleryFoto(foto);
};
function PopGallery(titolo, mylayer){
	var obj;
	if (!Oggetto("Div"+mylayer)){
		obj=PopUP (titolo, '', "../themes/foto.gif", "Div"+mylayer, "PopGallery");	
		obj.WriteFooter(FooterGallery(mylayer));
		obj.Write(BodyGallery(mylayer));
		
		Oggetto(obj.nlay+"Miniature").style.clip='rect(0px 140px '+ (obj.Height-60) +'px 0px)';
		Oggetto(obj.nlay+"Miniature").style.height=obj.Height-60;
		Oggetto(obj.nlay+"ZoomImage").style.width = obj.Width-150;
		Oggetto(obj.nlay+"ZoomImage").style.height = obj.Height-60;
		Oggetto(obj.nlay+"ZoomImage").style.clip='rect(0px '+ (obj.Width-150) +'px '+ (obj.Height-60) +'px 0px)';
	
	} else {
		obj=eval('Div'+mylayer+'Object');
		obj.Show();
	}
	GalleryFoto(mylayer);
	return obj;
};
function BodyGallery(foto){
    var mylista = eval("Lista"+foto);
    var fotografia, text;

	var	text = '<div id="Div'+ foto +'Miniature" style="position: absolute; top: 0px; left: 0px; width: 140px; height: 100px; visibility: inherit; clip: rect(0px 140px 400px 0px); overflow: auto;">';	
		text += '<table border="0" cellspacing="0" cellpadding="2">';

	for (var k=0; k<mylista.length; k++) 
			text += '<tr><td><a href="#" title="'+ mylista[k][1] +'" onclick="indice_'+foto+'='+k+';DoGallery(\''+foto+'\');"><img src="../images/piccole/'+ mylista[k][0] +'" border="0" alt="'+ mylista[k][1] +'"></a></td></tr>';
			
		text += '</table></div>';	
		text += '<div id="Div'+ foto +'ZoomImage" style="position: absolute; top: 0px; left: 140px; width: 100px; height: 100px; clip: rect(0px 100px 100px 0px); visibility: inherit; overflow: auto;">'+		
					'<img src="../images/'+ mylista[0][0] +'" alt="'+ mylista[0][1] +'" id="'+ foto +'" border="0"></div>';				
	
	eval("indice_"+foto+"=0");
	return text;
};
function FooterGallery(mylayer){
	var img=['ZoomPiu.gif','ZoomMeno.gif','ZoomNormale.gif','piuSinistra.gif','piudestra.gif','piuStop.gif','piuStart.gif'];
	img=ImageLoadArray(img,Tema);	
	var HTMLtext=''+
'<table>'+
	'<tr>'+
		'<td><a href="#" onmousedown="StopTimedFoto(\''+mylayer+'\');ColorePulsante(\'ZoomPiu'+mylayer+'\',\'#00FF50\');ZoomScroll(\''+mylayer+'\',40);" '+
			'onmouseup="ColorePulsante(\'ZoomPiu'+mylayer+'\');KillTimer()"  title="+Zoom">'+
			'<img id="ZoomPiu'+mylayer+'" src="'+img[0].src+'" alt="+ zoom" align="bottom" border="0"></a></td>'+
		'<td><a href="#" onmousedown="StopTimedFoto(\''+mylayer+'\');ColorePulsante(\'Riduci'+mylayer+'\',\'#00FF50\');" '+
			'onclick="ResizeFoto(\''+mylayer+'\', Div'+mylayer+'Object.Contenitore.Width-160, Div'+mylayer+'Object.Contenitore.Height);ColorePulsante(\'Riduci'+mylayer+'\');" title="Rendi visibile nella finestra">'+
			'<img id="Riduci'+mylayer+'" src="'+img[2].src+'" alt="Rendi visibile nella finestra" border="0"></a></td>'+
		'<td><a href="#" onmousedown="StopTimedFoto(\''+mylayer+'\');ColorePulsante(\'ZoomMeno'+mylayer+'\',\'#00FF50\');ZoomScroll(\''+mylayer+'\',-40)" '+
			'onmouseup="ColorePulsante(\'ZoomMeno'+mylayer+'\');KillTimer()" title="-Zoom">'+
			'<img  id="ZoomMeno'+mylayer+'" src="'+img[1].src+'" alt=" - zoom" border="0"></a></td>'+
		'<td><a href="#" onclick="StepBFoto(\''+mylayer+'\');ColorePulsante(\'StepB'+mylayer+'\');"'+
			'onmousedown="ColorePulsante(\'StepB'+mylayer+'\',\'#00FF50\');" title="Immagine precedente">'+
			'<img id="StepB'+mylayer+'" src="'+img[3].src+'" alt="Immagine precedente" border="0"></a></td>'+
		'<td><a href="#" onclick="StepAFoto(\''+mylayer+'\');ColorePulsante(\'StepA'+mylayer+'\');"'+
			'onmousedown="ColorePulsante(\'StepA'+mylayer+'\',\'#00FF50\');" title="Immagine successiva">'+
			'<img id="StepA'+mylayer+'" src="'+img[4].src+'" alt="Immagine successiva" border="0"></a></td>'+
		'<td><a href="#" onclick="StopTimedFoto(\''+mylayer+'\')" title="Ferma Proiezione">'+
			'<img id="Alt'+mylayer+'" src="'+img[5].src+'" alt="Ferma Proiezione" border="0"></a></td>'+
		'<td><a href="#" onclick="TimedFoto(\''+mylayer+'\',15000);" title="Inizia Proiezione">'+
			'<img id="Start'+mylayer+'" src="'+img[6].src+'" alt="Inizia Proiezione" border="0"></a></td>'+
		'<td nowrap><div id="Didascalia'+mylayer+'"></div></td>'+
	'</tr>'+
'</table>';
	return HTMLtext
};
function ScriviFlash(link, w,h, name, bgcolor){

	var txt;
	if (navigator.appName.indexOf ("Microsoft") != -1){
		txt='<object name="'+name+'" height="'+h+'" width="'+w+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">'+
				'<param name="bgcolor" value="'+bgcolor+'" />'+
				'<param name="quality" value="high" />'+
				'<param name="movie" value="video/'+link+((link.indexOf("?")>-1)? '&showdigits=true&autostart=false"' : '"')+' />'+
				'<param name="scale" value="exactfit" />'+
				'<param name="swLiveConnect" value="true" />'+
				'<param nam="allowScriptAccess" value="always">'+
			'</object>';
	}else txt='<embed name="'+name+'" src="video/'+link+((link.indexOf("?")>-1)? '&showdigits=true&autostart=false"' : '"')+' width="'+w+'" height="'+h+'" scale="exactfit" allowScriptAccess="always" swLiveConnect="true" quality="high" bgcolor="'+bgcolor+'"></embed>';
	return txt;
}
function PopVideo (titolo, file, mylayer){ 
	if (Oggetto("V"+mylayer)) {
			eval("V"+mylayer+'Object.Show()');
			if (mylayer=="FlashIpassi") PassFlash(mylayer, 'play');
	} else {
		var text;
		var obj = PopUP(titolo, '' ,((mylayer.indexOf("audio")>-1)? "../themes/speaker.gif" : "../themes/film.gif"), "V"+ mylayer);
	
	text =	'<table width="100%"  height="100%" border="0" cellspacing="0" cellpadding="0">';
	text += '<tr><td align="center">';
			if(mylayer.indexOf("audio")>-1) text +='<embed id="Audio'+ mylayer +'" src="musica/'+ file +'" type="audio/x-mpeg" align="center" height="90%" width="90%" play="true">';
			if(mylayer.indexOf("Flash")>-1) text += ScriviFlash(file, "95%" ,"95%", mylayer, '#ffffff');
	text += '</td></tr></table>';

		if (mylayer=="FlashIpassi"){ 
			var img=['piuSinistra.gif','piuStop.gif','piuStart.gif'];
			img=ImageLoadArray(img,Tema);
			var HTMLtext=''+
'<table>'+
	'<tr>'+
		'<td><a href="#" onclick="PassFlash(\''+mylayer+'\', \'rew\');ColorePulsante(\'Rew'+mylayer+'\');"'+
			'onmousedown="ColorePulsante(\'Rew'+mylayer+'\',\'#00FF50\');" title="Riavvolgi">'+
			'<img id="Rew'+mylayer+'" src="'+img[0].src+'" alt="Riavvolgi filmato" border="0"></a></td>'+
		'<td><a href="#" onclick="PassFlash(\''+mylayer+'\', \'stop\')" title="Ferma Proiezione">'+
			'<img id="Alt'+mylayer+'" src="'+img[1].src+'" alt="Ferma Proiezione" border="0"></a></td>'+
		'<td><a href="#" onclick="PassFlash(\''+mylayer+'\', \'play\')" title="Inizia Proiezione">'+
			'<img id="Start'+mylayer+'" src="'+img[2].src+'" alt="Inizia Proiezione" border="0"></a></td>'+
	'</tr>'+
'</table>';
			obj.WriteFooter(HTMLtext);
		}
		obj.Write(text)
		return obj;
	}
};
function doPassVar(obj, s, txt){eval("window.document."+obj).SetVariable(s, txt);};
function PassFlash(mylayer, stato){
	if (stato.toLowerCase()=='rew'){
		if (document.all) eval(mylayer).Rewind();
		else document.embeds[mylayer].Rewind();
	}
	if (stato.toLowerCase()=='stop'){
		if (document.all) eval(mylayer).StopPlay();
		else document.embeds[mylayer].StopPlay();
	}
	if (stato.toLowerCase()=='play'){
		if (document.all) eval('document.'+mylayer).Play();
		else document.embeds[mylayer].Play();
	}	
}
function StopMovie(mylayer){

	if (mylayer=="VFlashIpassi") PassFlash(mylayer.substring(1,mylayer.length), 'stop');
	else {
		if (mylayer.indexOf('audio')>-1) eval('Audio'+mylayer.substring(1,mylayer.length)+'.Stop()');
		if (mylayer.indexOf('Flash')>-1) doPassVar(mylayer.substring(1,mylayer.length), 'playpause', 'true');
	}
};
function HideOtherMovie(MyLayer){

	for (var i=0;Obj_Up.length>i; i++){
		if (Obj_Up[i]!=MyLayer && eval(Obj_Up[i]+"Object")){
			var obj=eval(Obj_Up[i]+"Object");
			if (obj.from_minimize!=true) obj.Hide();
		}
	}
};
function TimeBackground(lista, secondi){
	this.lista=lista;
	Oggetto('fondoRotante').style.background="#aa0000 url("+ this.lista[Math.round(Math.random()*(this.lista.length-1))] +") no-repeat fixed center ";	
	setTimeout("TimeBackground(this.lista, "+secondi +")", 1000*secondi)
};
function FotoBack(){
	Oggetto('fondoRotante').style.width=width_Body-20;
	Oggetto('fondoRotante').style.height=height_Body-100;
	TimeBackground(ListaSfondi,30);
};
function myOnLoad(){
	PopWindowInit();	
	FotoBack()
	SETmenu(width_Body, height_Body);
	writeMenus();
};
