// Marco Coan - basic function for animation - start on Augost2010

// --------------------------------------------------------------------------------
// sezione AJAX
// --------------------------------------------------------------------------------



function ajax(filePHP,data) {
// ajax - filePHP = file php da richiamare (incluso path) - data = dati da inviare a seconda del php richiamato (variabile=valore)
  
    this.filePHP = filePHP;
    this.data = data;
  
    if (window.XMLHttpRequest) { 
      this.http_request = new XMLHttpRequest();
      if (this.http_request.overrideMimeType) {
        this.http_request.overrideMimeType('text/xml');
      }
    } else if (window.ActiveXObject) { // IE
      try {
        this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
    }
    // LANCIA RICHIESTA...
    this.http_request.open('POST', this.filePHP, true);
    this.http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    this.http_request.send(this.data); 
}

// --------------------------------------------------------------------------------
// sezione VIDEO
// --------------------------------------------------------------------------------

function playVideoInterfaceRnd(divContainer,directory,width,height,fixedDelay){
// il video con suffisso FIRST.ext verr girato pi probabilmente (es: "video MAIN.mp4")
// il video con suffisso LAST.ext verr girato meno probabilmente (es: "video LAST.mp4")
// fixedDelay  il valore FISSO di pausa tra un video e l'altro e anche il valore di RANDOM calcolato.
// l'immagine poster deve essere una .jpg o .png - si pu aggiungere anche una .gif per iphone
// inserire i video in una cartellina, allegare anche un "nomeQualunque.jpg" (jpg/png/gif) come posterImg
// nota: questa funzione NON prevede il "loop" ed  sempre "autoplay" per ragioni intrinseche alla logica
  
  this.videoArray = new Array();
  this.divContainer = divContainer;
  this.directory = directory;
  this.width = width;
  this.height = height;
  this.fixedDelay = fixedDelay;
  this.posterImg = undefined;
  this.videoMain = undefined;
  this.videoLast = undefined;
  this.videoclip = undefined;
  this.videoMedia = this.divContainer+"_media";
  this.template = undefined;
  var me = this;
  
  var scanDir = new ajax("code/scanDir.php","dir=../"+this.directory);

  scanDir.http_request.onreadystatechange = function(){
    if (scanDir.http_request.readyState == 4) {
      if (scanDir.http_request.status == 200) {
        me.inizialize();
      }
    }
  }
  
  this.inizialize = function(){
    // costruzione lista video
    files = (scanDir.http_request.responseText).split(";");
    checkName = new Array();
    for(scan=0;scan<files.length;scan++){
       videoName = files[scan].split(".")[0];
       // controlla se il file  un immagine e salta da lista video, e se  immagine poster (jpg o png) aggiunge a variabile this.posterImg
       if(files[scan].toLowerCase().indexOf(".jpg") != -1 || files[scan].toLowerCase().indexOf(".png") != -1 || files[scan].toLowerCase().indexOf(".gif") != -1){
         if(files[scan].toLowerCase().indexOf(".jpg") != -1 || files[scan].toLowerCase().indexOf(".png") != -1){
            this.posterImg = files[scan];
         }
       } else {
        // controlla se  mainRnd
        if(files[scan].toLowerCase().indexOf("main.") != -1 && this.videoMain == undefined){
          this.videoMain = videoName;
        } else {
          // controlla se  lastRnd
          if(files[scan].toLowerCase().indexOf("last.") != -1 && this.videoLast == undefined){
            this.videoLast = videoName;
            this.videoLastCounter = 0;
          } else {
            // inserisci video
            if(checkName[checkName.length-1] != videoName){
              this.videoArray.push(videoName);
            }
          } 
        }
      }
      checkName.push(videoName);
    }
     
    // flash autonomo per piattaforme non html5
    if( !!document.createElement('video').canPlayType != true){
      // parte object
      this.template = '<object '+
      'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '+
      'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" '+
      'width="'+this.width+'" '+
      'height="'+this.height+'"'+
      'hspace="0" '+
      'vspace="0" '+
      'align="top"> '+
      '<param name="FlashVars" value="targetWidth='+this.width+'&targetHeight='+this.height+'&directory=../'+this.directory+'&videoMain='+this.videoMain+'&videoLast='+this.videoLast+'&fixedDelay='+this.fixedDelay+'&posterImg='+this.posterImg+'&videoArray='+this.videoArray.join(';')+'" />'+
      '<param name="allowScriptAccess" value="sameDomain" /> '+
      '<param name="loop" value="false" /> '+
      '<param name="scale" value="noscale" />'+
      '<param name="quality" value="high" /> '+
      '<param name="salign" value="lt" /> '+
      '<param name="wmode" value="transparent" /> '+
      '<param name="bgcolor" value="#ffffff" /> '+
      '<param name="movie" value="code/playVideoInterfaceRnd.swf" /> '+
      // parte embed
      '<embed type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" '+
      'width="'+this.width+'" '+
      'height="'+this.height+'" '+
      'hspace="0" '+
      'vspace="0" '+
      'align="top" '+
      'FlashVars = "targetWidth='+this.width+'&targetHeight='+this.height+'&directory=../'+this.directory+'&videoMain='+this.videoMain+'&videoLast='+this.videoLast+'&fixedDelay='+this.fixedDelay+'&posterImg='+this.posterImg+'&videoArray='+this.videoArray.join(';')+'" '+
      'loop="false" '+
      'scale="noscale" '+
      'quality="high" '+
      'salign="lt" '+
      'wmode="transparent" '+
      'bgcolor="#ffffff" '+
      'allowScriptAccess="sameDomain" '+
      'src="code/playVideoInterfaceRnd.swf"/></object>';
      document.getElementById(this.divContainer).innerHTML = this.template;
      return;                
    }
    
    // salta con piattaforme incompatibili con video interfaccia
    if(navigator.platform == "iPhone"){
        this.template = '<img src="'+this.directory+'/'+this.posterImg.split('.')[0]+'.gif" width="'+this.width+'" height="'+this.height+'" onerror="src='+this.directory+"/"+this.posterImg+'" />';
        document.getElementById(this.divContainer).innerHTML = this.template;
        return;
    }
    this.playRnd();
  }
  
  this.playRnd = function(){
    // ritarda funzione
    if(this.flagDelay==undefined){
      // scambia con immagine fissa (stesso file del poster)
      this.template = '<img src="'+this.directory+'/'+this.posterImg+'" width="'+this.width+'" height="'+this.height+'" />';
      document.getElementById(this.divContainer).innerHTML = this.template;
      this.flagDelay = true;
      trigger = parseInt(Math.floor(Math.random()*fixedDelay));
      window.setTimeout(function(){me.playRnd();},this.fixedDelay+trigger);
      return;
    } else {
      this.flagDelay = undefined;
    }
    // lancia video rnd
    totalRnd = this.videoArray.length;
    if(this.videoMain != undefined){
      totalRnd +=10;
    }
    rnd = parseInt(Math.floor(Math.random()*totalRnd));
    if(rnd<this.videoArray.length){
      this.videoclip = this.videoArray[rnd];
      // seconda estrazione per video last (amentare il valor moltiplicato per minor probabilit)
      if(this.videoLast != undefined){
        if(this.videoLastCounter > totalRnd){
           rndLast = parseInt(Math.floor(Math.random()*3));
           if(rndLast==0){
             this.videoLastCounter = 0;
             this.videoclip = this.videoLast;
           }
        } else {
           this.videoLastCounter++;
        }
      }
    } else {
      this.videoclip = this.videoMain;
    }
    
    this.template =''+
    '<video id="'+this.videoMedia+'" width="'+this.width+'" height="'+this.height+'" ';
    if(this.posterImg.toLowerCase().indexOf(".jpg") != -1 || this.posterImg.toLowerCase().indexOf(".png") != -1 ){
   	this.template += 'poster="'+this.posterImg+'" ';
    }
    this.template += ' >'+
    '<source src="'+this.directory+'/'+this.videoclip+'.mp4" type="video/mp4;"> '+
    '<source src="'+this.directory+'/'+this.videoclip+'.m4v" type="video/m4v;"> '+
    '<source src="'+this.directory+'/'+this.videoclip+'.ogg" type="video/ogg;"> '+
    '<source src="'+this.directory+'/'+this.videoclip+'.webm" type="video/webm;"> '+
    'Il tuo navigatore non supporta ancora videoHtml5'+
    '</video>';
    document.getElementById(this.divContainer).innerHTML = this.template;
    document.getElementById(this.videoMedia).play();
    
    // controlla finale video 
    this.enterFrame = window.setInterval(function(){me.checkEnd();},100); 
  }
  
  // funzione di riaccensione immagine o video al termine dello spezzone video random
  this.checkEnd = function(){
      if(document.getElementById(this.videoMedia).ended != false){
         window.clearInterval(this.enterFrame);
         this.playRnd();
      }
  }
  
}  


function playVideoInterface(divContainer,videoclip,width,height,loop){
// videoclip dev'essere comprensivo dell'estensione (verr tolta in automatico)
// l'immagine poster DEVE AVERE LO STESSO NOME del video e deve essere una .jpg o .png - si pu aggiungere anche una .gif per iphone
// nota: questa funzione NON prevede "autoplay" per ragioni intrinseche alla logica
   
  this.divContainer = divContainer;
  this.videoclip = (videoclip.split("."))[0];
  this.posterImg = this.videoclip.split("/")[this.videoclip.split("/").length-1];
  this.width = width;
  this.height = height;
  this.loop = loop;
  this.videoMedia = this.divContainer+"_media";
  this.directory = this.videoclip.split("/"+this.posterImg)[0];
  this.template
  var me = this;
  
  var checkPoster = new ajax("code/findIfJpgOrPng.php","dir=../"+this.directory+"&targetFile="+this.posterImg);

  checkPoster.http_request.onreadystatechange = function(){
    if (checkPoster.http_request.readyState == 4) {
      if (checkPoster.http_request.status == 200) {
         me.inizialize();
      }
    }
  }
  
  this.inizialize = function(){
		// ricevi immagine poster da funzione ajax
		this.posterImg = this.directory+"/"+checkPoster.http_request.responseText;
		  
		this.template =''+
		'<video id="'+this.videoMedia+'" width="'+this.width+'" height="'+this.height+'" ';
		if(this.posterImg.toLowerCase().indexOf(".jpg") != -1 || this.posterImg.toLowerCase().indexOf(".png") != -1 ){
			this.template += 'poster="'+this.posterImg+'" ';
		}
	  
		this.template += '>'+
	  
		'<source src="'+this.videoclip+'.mp4" type="video/mp4;"> '+
		'<source src="'+this.videoclip+'.m4v" type="video/m4v;"> '+
		'<source src="'+this.videoclip+'.ogg" type="video/ogg;"> '+
		'<source src="'+this.videoclip+'.webm" type="video/webm;"> '+
		'Il tuo navigatore non supporta ancora videoHtml5'+
		'</video>';
	
		if(navigator.platform == "iPhone"){
			this.template = '<img src="'+this.posterImg.split('.')[0]+'.gif" width="'+this.width+'" height="'+this.height+'" onerror="src='+this.posterImg+'" />';
		}
	 
		if( !!document.createElement('video').canPlayType != true){
			// parte object
			this.template = '<object '+
			'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '+
			'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" '+
			'width="'+this.width+'" '+
			'height="'+this.height+'"'+
			'hspace="0" '+
			'vspace="0" '+
			'align="top"> '+
			'<param name="FlashVars" value="targetWidth='+this.width+'&targetHeight='+this.height+'&targetSource=../'+this.videoclip+'.flv&targetLoop='+this.loop+'" />'+
			'<param name="allowScriptAccess" value="sameDomain" /> '+
			'<param name="loop" value="false" /> '+
			'<param name="scale" value="noscale" />'+
			'<param name="quality" value="high" /> '+
			'<param name="salign" value="lt" /> '+
			'<param name="wmode" value="transparent" /> '+
			'<param name="bgcolor" value="#ffffff" /> '+
			'<param name="movie" value="code/playVideoInterface.swf" /> '+
			// parte embed
			'<embed type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" '+
			'width="'+this.width+'" '+
			'height="'+this.height+'" '+
			'hspace="0" '+
			'vspace="0" '+
			'align="top" '+
			'FlashVars = "targetWidth='+this.width+'&targetHeight='+this.height+'&targetSource=../'+this.videoclip+'.flv&targetLoop='+this.loop+'" '+
			'loop="false" '+
			'scale="noscale" '+
			'quality="high" '+
			'salign="lt" '+
			'wmode="transparent" '+
			'bgcolor="#ffffff" '+
			'allowScriptAccess="sameDomain" '+
			'src="code/playVideoInterface.swf"/></object>';                
		}
	  
		document.getElementById(this.divContainer).innerHTML = this.template;
		document.getElementById(this.videoMedia).play();
		
		// Funzione javascript loop
	  if(this.loop=="loop"){
			this.enterFrame = window.setInterval(function(){me.checkEnd();},50);
		 		this.checkEnd = function(){
			 	if(document.getElementById(this.videoMedia).ended == true){
				 	document.getElementById(this.videoMedia).play();
			 	}
		 	}
	  }   
  }
  
}  
  
  
function playVideo(divContainer,videoclip,width,height,autoplay,loop,controls){
// videoclip dev'essere comprensivo dell'estensione (verr tolta in automatico)
// l'immagine poster DEVE AVERE LO STESSO NOME del video e deve essere una .jpg o .png - si pu aggiungere anche una .gif per iphone
  
  this.divContainer = divContainer;
  this.videoclip = (videoclip.split("."))[0];
  this.width = width;
  this.height = height;
  this.controls = controls;
  this.autoplay = autoplay;
  this.loop = loop;
  this.template;
  this.videoMedia = this.divContainer+"_media";
  var me = this;
  
  this.template =''+
  '<video id="'+this.videoMedia+'" width="'+this.width+'" height="'+this.height+'" poster="'+this.videoclip+'.jpg" ';
  
  if(this.autoplay=="autoplay"){
    if(this.controls=="controls"){
      this.template += 'controls ';
    }
  } else {
     this.template += 'controls ';
  }
 
  this.template += '>'+
  '<source src="'+this.videoclip+'.mp4" type="video/mp4;"> '+
  '<source src="'+this.videoclip+'.m4v" type="video/m4v;"> '+
  '<source src="'+this.videoclip+'.ogg" type="video/ogg;"> '+
  '<source src="'+this.videoclip+'.webm" type="video/webm;"> '+
  'Il tuo navigatore non supporta ancora video Html5'+
  '</video>';

  if( !!document.createElement('video').canPlayType != true){
    // parte object
    this.template = '<object '+
    'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '+
    'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" '+
    'width="'+this.width+'" '+
    'height="'+this.height+'"'+
    'hspace="0" '+
    'vspace="0" '+
    'align="top"> '+
    '<param name="FlashVars" value="targetWidth='+this.width+'&targetHeight='+this.height+'&targetSource=../'+this.videoclip+'.flv&targetLoop='+this.loop+'&targetControls='+this.controls+'&targetAutoplay='+this.autoplay+'" />'+
    '<param name="allowScriptAccess" value="sameDomain" /> '+
    '<param name="loop" value="false" /> '+
    '<param name="scale" value="noscale" />'+
    '<param name="quality" value="high" /> '+
    '<param name="salign" value="lt" /> '+
    '<param name="wmode" value="transparent" /> '+
    '<param name="bgcolor" value="#ffffff" /> '+
    '<param name="movie" value="code/playVideo.swf" /> '+
    // parte embed
    '<embed type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" '+
    'width="'+this.width+'" '+
    'height="'+this.height+'" '+
    'hspace="0" '+
    'vspace="0" '+
    'align="top" '+
    'FlashVars = "targetWidth='+this.width+'&targetHeight='+this.height+'&targetSource=../'+this.videoclip+'.flv&targetLoop='+this.loop+'&targetControls='+this.controls+'&targetAutoplay='+this.autoplay+'" '+
    'loop="false" '+
    'scale="noscale" '+
    'quality="high" '+
    'salign="lt" '+
    'wmode="transparent" '+
    'bgcolor="#ffffff" '+
    'allowScriptAccess="sameDomain" '+
    'src="code/playVideo.swf"/></object>';         
  }
  
  document.getElementById(this.divContainer).innerHTML = this.template;
  if(this.autoplay=="autoplay"){
  		document.getElementById(this.videoMedia).play();
  }
  
  // Funzione javascript loop
  if(this.loop=="loop"){
    	this.enterFrame = window.setInterval(function(){me.checkEnd();},50);
    	this.checkEnd = function(){
       	if(document.getElementById(this.videoMedia).ended == true){
          	document.getElementById(this.videoMedia).play();
       	}
    	}
   }
}  
  
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
// sezione ANIMAZIONI
// --------------------------------------------------------------------------------
function mouseScreenPosition(e) {
      var x, y;
      if (!e) e = window.event;
      if (e.pageX || e.pageY){
         x = e.pageX;
         y = e.pageY;
      }
      else if (e.clientX || e.clientY){
         x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
         y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
      }
      return Array(x,y);
}


function mouseDivPosition(e,targetDiv) {
		// ATTENZIONE! targetDiv  il nome semplice dell'elemento, NON un getElementById ad un elemento
		var coords = { x: 0, y: 0};
		var CalculatedTotalOffsetLeft = 0;
		var CalculatedTotalOffsetTop = 0 ;
		var Element = document.getElementById(targetDiv);
        if(!e) { // then we have a non-DOM (probably IE)  browser
       			 e = window.event;
					 if(Element.offsetParent) {
						  while(1) {
							 CalculatedTotalOffsetLeft += Element.offsetLeft;
							 CalculatedTotalOffsetTop += Element.offsetTop;
							 if(!Element.offsetParent) { break; }
							 Element = Element.offsetParent;
						  }
					 }
					 coords.x = (e.clientX+ document.body.scrollLeft + document.documentElement.scrollLeft)-CalculatedTotalOffsetLeft;
                coords.y = (e.clientY+ document.body.scrollTop + document.documentElement.scrollTop)-CalculatedTotalOffsetTop;
        } else {     // we assume  DOM modeled  javascript
                while (Element.offsetParent) {
							CalculatedTotalOffsetLeft += Element.offsetLeft ;     
							CalculatedTotalOffsetTop += Element.offsetTop ;
							Element = Element.offsetParent ;
                }
                coords.x = e.pageX - CalculatedTotalOffsetLeft ;
                coords.y = e.pageY - CalculatedTotalOffsetTop ;
        }
        return Array(coords.x,coords.y);
}



function mouseItem(e) {
	if(!e) { // then we have a non-DOM (probably IE)  browser
		e = window.event;
		return e.srcElement;
	} else {
		return e.target;
	}
}





function mouseFade(mouseItem,targetDiv,fadeVelocity){
// controllo fade in/out al passare del mouse sopra un oggetto (anche esterno)
// settare mouseItem = la SORGENTE del lancio, che rileva il mouseOver e mouseOut
// targetDiv  la destinazione del contenitore della grafica da dissolvere in/out
// fadeVelocity (epresso in millisecondi) la velocit di dissolvenza
   
   this.targetDiv = targetDiv;
   this.mouseItem = mouseItem;
   this.fadeVelocity = fadeVelocity;
   this.fade = Number(document.getElementById(targetDiv).style.opacity);
   var me = this;
   
   document.getElementById(this.mouseItem).onmouseover = function() {
      me.fadeIn();  
   }
   document.getElementById(this.mouseItem).onmouseout = function() {
      me.fadeOut();  
   }
   
   this.fadeIn = function(){ 
      if(this.fade <1){
         this.fade += 0.1;
         document.getElementById(this.targetDiv).style.opacity = this.fade;
         document.getElementById(this.targetDiv).style.filter = "alpha(opacity="+this.fade*100+")";
         this.enterFrameFadeIn = setTimeout(function(){me.fadeIn();},this.fadeVelocity);
         clearTimeout(this.enterFrameFadeOut );
      } else { 
         clearTimeout(this.enterFrameFadeIn ); 
      }
   }
   
   this.fadeOut = function(){
      if(this.fade >0){
         this.fade -= 0.1;
         document.getElementById(this.targetDiv).style.opacity = this.fade;
         document.getElementById(this.targetDiv).style.filter = "alpha(opacity="+this.fade*100+")"; 
         this.enterFrameFadeOut = setTimeout(function(){me.fadeOut();},this.fadeVelocity); 
         clearTimeout(this.enterFrameFadeIn );
      } else {
         clearTimeout(this.enterFrameFadeOut ); 
      }
   }
 
}





function menuScrollUp(targetMask,targetDiv) {

	var me = this;
	this.targetMask = document.getElementById(targetMask);
	this.targetDiv = document.getElementById(targetDiv);
	
	if(this.targetDiv.offsetTop-this.targetMask.offsetHeight > -this.targetDiv.offsetHeight+this.targetMask.offsetHeight){
		this.newPosition = this.targetDiv.offsetTop-this.targetMask.offsetHeight;
	} else {
		this.newPosition = -this.targetDiv.offsetHeight+this.targetMask.offsetHeight;
	}
	
	this.move = function(){
		if(this.targetDiv.offsetTop > this.newPosition){
			this.targetDiv.style.top = this.targetDiv.offsetTop + (this.newPosition-this.targetDiv.offsetTop)/2-1 +"px";
			this.onEnterFrame = window.setTimeout(function(){me.move();},50);
		} else {
			window.clearTimeout(this.onEnterFrame);
		}
	}
	
	this.move();
}


function menuScrollDown(targetMask,targetDiv) {

	var me = this;
	this.targetMask = document.getElementById(targetMask);
	this.targetDiv = document.getElementById(targetDiv);
	
	if(this.targetDiv.offsetTop+this.targetMask.offsetHeight <0){
		this.newPosition = this.targetDiv.offsetTop+this.targetMask.offsetHeight;
	} else {
		this.newPosition = 0;
	}
	
	this.move = function(){
		if(this.targetDiv.offsetTop < this.newPosition){
			this.targetDiv.style.top = this.targetDiv.offsetTop - Math.round((this.newPosition+this.targetDiv.offsetTop)/2)+1 +"px";
			this.onEnterFrame = window.setTimeout(function(){me.move();},50);
		} else {
			window.clearTimeout(this.onEnterFrame);
		}
	}
	
	this.move();
}































function changePage(targetDiv,direction,targetURL){
	// QUESTA FUNZIONE NON DEV'ESSERE ISTANZIATA CON "NEW" per permettere l'abort in caso di pi click
	
	
	
	// ABORT in caso di funzionamento in corso
	if(this.enterFrame!=undefined){return;}
	
	var me = this;
	this.targetDiv = document.getElementById(targetDiv);
	this.direction = direction.toLowerCase(); // valori possibili: left,right,up,down
	this.width = this.targetDiv.offsetWidth;
	this.height = this.targetDiv.offsetHeight;
	this.targetURL = targetURL;
	/*alert(this.targetURL);*/


	this.includeNewPage = function() {
		// CAMBIO PAGINA
		var changePage = new ajax("code/changePage.php","page="+this.targetURL);
		// attende risposta
		//alert("includeNewPage");
		changePage.http_request.onreadystatechange = function(){
			if (changePage.http_request.readyState == 4) {
				if (changePage.http_request.status == 200) {
				  me.targetDiv.innerHTML = changePage.http_request.responseText;
				  me.moveIn();
				}
			}
		}
	}
	
	this.moveOut = function(){
		if(me.direction == "left"){
			// USCITA A SINISTRA
			this.position = me.targetDiv.offsetLeft;
			if(this.position > -me.width){
				// accelerato
				me.targetDiv.style.left = this.position+Math.round((this.position/6-1))+"px";
				// fisso
				//me.targetDiv.style.left = this.position-50+"px";
				me.enterFrame = window.setTimeout(function(){me.moveOut();},10);
				return;
			} else {
				
				window.clearTimeout(me.enterFrame);
				me.enterFrame = undefined;
				// inizializza il punto d'entrata del targetDiv
				me.targetDiv.style.left = me.width+"px";
				me.includeNewPage();
			}
		} 
		if(me.direction == "right"){
			// USCITA A DESTRA
			this.position = me.targetDiv.offsetLeft;
			if(this.position < me.width){
				// accelerato
				me.targetDiv.style.left = this.position+Math.round((this.position/6+1))+"px";
				// fisso
				//me.targetDiv.style.left = this.position+50+"px";
				me.enterFrame = window.setTimeout(function(){me.moveOut();},10);
				return;
			} else {
				window.clearTimeout(me.enterFrame);
				me.enterFrame = undefined;
				// inizializza il punto d'entrata del targetDiv
				me.targetDiv.style.left = -me.width+"px";
				me.includeNewPage();
			}
		}
		if(me.direction == "up"){
			// USCITA IN ALTO
			this.position = me.targetDiv.offsetTop;
			if(this.position > -me.height){
				// accelerato
				me.targetDiv.style.top = this.position+Math.round((this.position/6-1))+"px";
				// fisso
				//me.targetDiv.style.top = this.position-50+"px";
				me.enterFrame = window.setTimeout(function(){me.moveOut();},10);
				return;
			} else {
				window.clearTimeout(me.enterFrame);
				me.enterFrame = undefined;
				// inizializza il punto d'entrata del targetDiv
				me.targetDiv.style.top = me.height+"px";
				me.includeNewPage();
			}
		} 
		if(me.direction == "down"){
			// USCITA IN BASSO
			this.position = me.targetDiv.offsetTop;
			if(this.position < me.height){
				// accelerato
				me.targetDiv.style.top = this.position+Math.round((this.position/6+1))+"px";
				// fisso
				//me.targetDiv.style.top = this.position+50+"px";
				me.enterFrame = window.setTimeout(function(){me.moveOut();},10);
				return;
			} else {
				window.clearTimeout(me.enterFrame);
				me.enterFrame = undefined;
				// inizializza il punto d'entrata del targetDiv
				me.targetDiv.style.top = -me.height+"px";
				me.includeNewPage();
			}
		}
	}
	
	this.moveIn = function() {
		if(me.direction == "left"){
			this.position = me.targetDiv.offsetLeft;
			if(this.position >0){
				// ENTRATA VERSO SINISTRA
				// accelerato
				me.targetDiv.style.left = this.position-Math.round((this.position/6+1))+"px";
				// fisso
				//me.targetDiv.style.left = this.position-50+"px";
				this.enterFrame = window.setTimeout(function(){me.moveIn();},10);
				return;
			} else {
				window.clearTimeout(this.enterFrame);
				this.enterFrame = undefined;
			}
		}
		if(me.direction == "right"){
			this.position = me.targetDiv.offsetLeft;
			if(this.position <0){
				// ENTRATA VERSO DESTRA
				// accelerato
				me.targetDiv.style.left = this.position-Math.round((this.position/6-1))+"px";
				// fisso
				//me.targetDiv.style.left = this.position+50+"px";
				this.enterFrame = window.setTimeout(function(){me.moveIn();},10);
				return;
			} else {
				window.clearTimeout(this.enterFrame);
				this.enterFrame = undefined;
			}
		}
		if(me.direction == "up"){
			this.position = me.targetDiv.offsetTop;
			if(this.position >0){
				// ENTRATA VERSO SINISTRA
				// accelerato
				me.targetDiv.style.top = this.position-Math.round((this.position/6+1))+"px";
				// fisso
				//me.targetDiv.style.top = this.position-50+"px";
				this.enterFrame = window.setTimeout(function(){me.moveIn();},10);
				return;
			} else {
				window.clearTimeout(this.enterFrame);
				this.enterFrame = undefined;
			}
		}
		if(me.direction == "down"){
			this.position = me.targetDiv.offsetTop;
			if(this.position <0){
				// ENTRATA VERSO DESTRA
				// accelerato
				me.targetDiv.style.top = this.position-Math.round((this.position/6-1))+"px";
				// fisso
				//me.targetDiv.style.top = this.position+50+"px";
				this.enterFrame = window.setTimeout(function(){me.moveIn();},10);
				return;
			} else {
				window.clearTimeout(this.enterFrame);
				this.enterFrame = undefined;
			}
		}
		
	}
	
	//alert(this.targetDiv.offsetWidth);
	this.moveOut();
}





function pushUp(targetDiv,startValue,endValue,pushStep){
	// FUNZIONE DA ISTANZIARE
	// questa funzione fa alzare un div dal bordo inferire di un sito (o di una maschera) con effetto elastico.
	// si alza al mouseover, si abbassa al mouseout, utile per bottoni.
	
	if(this.enterFrameIn!=undefined){return;}
	if(this.enterFrameOut!=undefined){return;}
	
	var me = this;
	this.targetDiv = document.getElementById(targetDiv);
	this.startValue = startValue;
	this.endValue = endValue;
	this.pushStep = pushStep;
	this.moveIn = function(){
	
		if(me.enterFrameOut != undefined){
			window.clearTimeout(me.enterFrameOut);
			me.enterFrameOut = undefined;
		}
	
		this.position = me.targetDiv.offsetTop;
		if(this.position != me.endValue){
			if(this.position > me.endValue){
				me.targetDiv.style.top = this.position-me.pushStep +"px";
				// controlla elastico massimo
				if(me.targetDiv.offsetTop<me.endValue){
					me.targetDiv.style.top = this.endValue -3+"px";
				}
			} else {
				me.targetDiv.style.top = this.position+1+"px";
			}
			me.enterFrameIn = setTimeout(function(){me.moveIn()},10);
		} else {
			window.clearTimeout(me.enterFrameIn);
			me.enterFrameIn = undefined;
		}
	}
	
	this.moveOut = function() {
	
		if(me.enterFrameIn != undefined){
			window.clearTimeout(me.enterFrameIn);
			me.enterFrameIn = undefined;
		}
	
		this.position = me.targetDiv.offsetTop;
		if(this.position != me.startValue){
			if(this.position < me.startValue){
				tempValue = this.position+me.pushStep;
				me.targetDiv.style.top = this.position+me.pushStep +"px";
				// controlla elastico massimo
				if(me.targetDiv.offsetTop>me.startValue){
					me.targetDiv.style.top = this.startValue +3+"px";
				}
			} else {
				me.targetDiv.style.top = this.position-1+"px";
			}
			me.enterFrameOut = setTimeout(function(){me.moveOut()},10);
		} else {
			window.clearTimeout(me.enterFrameOut);
			me.enterFrameOut = undefined;
		}
	}
	
	this.targetDiv.onmouseout = function() {
      me.moveOut();  
   }
   this.targetDiv.onmouseover = function() {
      me.moveIn();  
   }
   
}



function bookmarkSite(title,url){
	// inserisce un sito in un bookmark
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else {
		if	(document.all) {
			window.external.AddFavorite(url, title);
		}
	}
}




function slideshow(targetDiv,targetFolder,slideTime){
	
	this.targetDiv = document.getElementById(targetDiv);
	this.targetFolder = targetFolder;
	this.slideTime = slideTime;
	this.counter = 0;
	this.slideArray = new Array();
	this.enterFrame = undefined;
	var me = this;
	
	var scanDir = new ajax("code/scanDir.php","dir=../"+this.targetFolder);

	scanDir.http_request.onreadystatechange = function(){
	  if (scanDir.http_request.readyState == 4) {
		if (scanDir.http_request.status == 200) {
			me.slideArray = (scanDir.http_request.responseText).split(";");
		  	me.changeSlide();
		}
	  }
	}
  
  
	this.changeSlide = function(){
		
		tempDiv = document.createElement("div");
		tempName = "slideshow_"+this.counter;
		oldName = "slideshow_"+(this.counter-1);
		tempDiv.setAttribute("id",tempName);
		this.counter++;
		tempDiv.style.position = "absolute";
		tempDiv.style.zIndex = this.counter;
		tempDiv.style.opacity = "0";
		tempDiv.style.filter = "Alpha(opacity=0)";
				
		tempHtml = "<img src='"+this.targetFolder+"/"+this.slideArray[0]+"' />";
		tempDiv.innerHTML = tempHtml;
		this.slideArray.push(this.slideArray.shift());
		
		
		this.targetDiv.appendChild(tempDiv);
		this.newDiv = document.getElementById(tempName);
		this.oldDiv = document.getElementById(oldName);
		this.fadeIn();
	}
	
	this.fadeIn = function(){
		
		alpha = Number(this.newDiv.style.opacity);
		
		if(alpha<1){
			// fade in
			this.newDiv.style.opacity = alpha+0.05;
			this.newDiv.style.filter = "Alpha(opacity="+((alpha+0.05)*100)+")";
			// fade out
			if(this.oldDiv){
				this.oldDiv.style.opacity = 1-(alpha+0.05);
				this.oldDiv.style.filter = "Alpha(opacity="+(100-(alpha+0.05)*100)+")";
			}
			this.enterFrame = window.setTimeout(function(){me.fadeIn();},50);
		} else {
			// cancella il vecchio oldDiv
			if(this.oldDiv){
				this.targetDiv.removeChild(this.oldDiv);
			}
			window.clearTimeout(this.enterFrame);
			this.enterFrame = window.setTimeout(function(){me.changeSlide();},this.slideTime);
			this.oldDiv.style.opacity = 100;
			this.oldDiv.style.filter = "Alpha(opacity=100)";

		}
	}
	
	
	
	
}






function menuUp(lanchDiv,menuDiv,offsetPos) {
	this.lanchDiv = document.getElementById(lanchDiv);
	this.menuDiv = document.getElementById(menuDiv);
	this.offsetPos = offsetPos;
	this.delay = 0;
	var me = this;
	//this.menuDiv.style.top = this.lanchDiv.offsetHeight+"px";
	
	
	this.lanchDiv.onmouseover = function() {
	me.delay = 0;
      me.enter();  
   }
	this.lanchDiv.onmouseout = function() {
		me.delay = 0;
      	me.exit();  
   }

   this.enter = function(){
   	window.clearTimeout(this.onExitFrame);
   	if(this.menuDiv.offsetTop > this.lanchDiv.offsetHeight - this.offsetPos){
			if(this.delay < 2){
					this.delay++;
				} else {
   			this.menuDiv.style.top = (this.menuDiv.offsetTop-1-(this.menuDiv.offsetTop-(this.lanchDiv.offsetHeight-this.offsetPos))/2) + "px";
   		}
   		this.onEnterFrame = window.setTimeout(function(){me.enter();},20);
   	} else {
   		window.clearTimeout(this.onEnterFrame);
   	}
   }
   
    this.exit = function(){
    
    	window.clearTimeout(this.onEnterFrame);
   	if(this.menuDiv.offsetTop < this.lanchDiv.offsetHeight){
   		if(this.delay < 2){
   			this.delay++;
   		} else {
   			this.menuDiv.style.top = (this.menuDiv.offsetTop+1+(this.lanchDiv.offsetHeight-this.menuDiv.offsetTop)/2) + "px";
   		}
   		this.onExitFrame = window.setTimeout(function(){me.exit();},20);
   	} else {
   		window.clearTimeout(this.onExitFrame);
   	}
   }
   
	
}









function gallery(targetDiv, targetDivWidth, targetDivHeight, targetMaskThumb, thumbWidth, thumbHeight, thumbMargin, textPadding, targetFolder, slideTime){
	
	// Si possono associare file txt o html con lo stesso nome della fotografia
	// Si pu associare una regola stile nel template per i files html inclusi come descrizione
	// utilizzando la classe .anteprimaGallery come master

	var me = this;
	this.targetDiv = targetDiv; // id del div grande
	this.targetDivWidth = targetDivWidth; // width div grande
	this.targetDivHeight = targetDivHeight; // height div grande
	this.targetMaskThumb = targetMaskThumb; // id della maschera principale in cui scorrono le thumb
	this.thumbWidth = thumbWidth; // larghezza delle thumb
	this.thumbHeight = thumbHeight; // altezza delle thumb (e quindi della maschera principale in cui scorrono le thumb)
	this.thumbMargin = thumbMargin; // margind destro thumb
	this.textPadding = textPadding;
	this.nameDiv = targetDiv; // nome univoco della gallery (AUTOMATICO)
	this.offsetScroll = 1;
	this.velocityScroll = 100;
	this.counter = 0;
	this.text = "";
	this.targetFolder = targetFolder;
	this.slideTime = slideTime;
	this.slideArray = new Array();
	this.slideText = new Array();
	this.enterFrame = undefined;
	this.enterFrameOutAutoText = undefined;

	document.write("<div class='anteprimaGallery' id='gallery_"+this.targetDiv+"'></div>");
	this.masterDiv = document.getElementById("gallery_"+this.targetDiv);
	
	// creazione div grande
	var createGalleryDiv = document.createElement("div");
	createGalleryDiv.setAttribute("id", this.targetDiv);
	createGalleryDiv.style.width = this.targetDivWidth+"px";
	createGalleryDiv.style.height = this.targetDivHeight+"px";
	createGalleryDiv.style.overflow = "hidden";
	createGalleryDiv.style.position = "relative";
	createGalleryDiv.style.margin = "0";
	// ---------------------------------------------------------------------------------------------------------
	// INTERVENIRE QUI PER IL MARGIN BOTTOM TRA LA FOTO GRANDE E LA PICCOLA EVENTUALMENTE INSERENDO VALORE FISSO
	// ---------------------------------------------------------------------------------------------------------
	createGalleryDiv.style.marginBottom = this.thumbMargin+"px";
	// ---------------------------------------------------------------------------------------------------------
	this.masterDiv.appendChild(createGalleryDiv);
	this.galleryDiv = document.getElementById(this.targetDiv);
	// creazione div testo
	var createTextDiv = document.createElement("div");
	createTextDiv.setAttribute("id", "text_"+this.targetDiv);
	createTextDiv.style.background = "url(code/galleryTextBackground.png)";
	createTextDiv.style.color = "#fff";
	createTextDiv.style.zIndex = this.counter+10;
	createTextDiv.style.width = this.targetDivWidth-this.textPadding*2+"px";
	createTextDiv.style.position = "absolute";
	createTextDiv.style.top = this.targetDivHeight+"px";
	createTextDiv.style.left = this.textPadding+"px";
	this.galleryDiv.appendChild(createTextDiv);
	this.textDiv = document.getElementById("text_"+this.targetDiv);
	
	var scanDir = new ajax("code/scanDir.php","dir=../"+this.targetFolder);

	scanDir.http_request.onreadystatechange = function(){
	  if (scanDir.http_request.readyState == 4) {
		if (scanDir.http_request.status == 200) {
			var rispostaPhp = (scanDir.http_request.responseText).split(";");
			for(scan = 0; scan <rispostaPhp.length; scan++){
				if(rispostaPhp[scan].toLowerCase().indexOf(".txt") != -1 || rispostaPhp[scan].toLowerCase().indexOf(".htm") != -1 || rispostaPhp[scan].toLowerCase().indexOf(".html") != -1){
					me.slideText.push(rispostaPhp[scan]);
				} else {
					if(rispostaPhp[scan].toLowerCase().indexOf(".jpg") != -1 || rispostaPhp[scan].toLowerCase().indexOf(".gif") != -1 || rispostaPhp[scan].toLowerCase().indexOf(".gif") != -1){
						me.slideArray.push(rispostaPhp[scan]);	
					}
				}
			}
			if(me.targetMaskThumb){ me.thumball(); }
			me.changeSlide();
		}
	  }
	}
  
  // FUNZIONI DI SCROLLING
  this.scrollLeft = function(scrollDiv,maskDiv) {
		if(scrollDiv.offsetLeft>-scrollDiv.offsetWidth+maskDiv.offsetWidth){
			scrollDiv.style.left = scrollDiv.offsetLeft-this.offsetScroll/10 +"px";
			if(scrollDiv.offsetLeft<-scrollDiv.offsetWidth+maskDiv.offsetWidth){
				scrollDiv.style.left = -scrollDiv.offsetWidth+maskDiv.offsetWidth +"px";
			}
			this.enterFrameScrolling = window.setTimeout(function(){me.scrollLeft(scrollDiv,maskDiv);},me.velocityScroll);
		};
	}
	this.scrollRight = function(scrollDiv,maskDiv) {
		if(scrollDiv.offsetLeft+this.offsetScroll/10 <0){
			scrollDiv.style.left = scrollDiv.offsetLeft+this.offsetScroll/10 +"px";
		} else {
			scrollDiv.style.left = "0";
		}
		this.enterFrameScrolling = window.setTimeout(function(){me.scrollRight(scrollDiv,maskDiv);},me.velocityScroll);
	}
	this.scrollStop = function(){
		if(this.enterFrameScrolling){
				window.clearTimeout(this.enterFrameScrolling);
				this.enterFrameScrolling = undefined;
		}
	}
	//
	
  	this.thumball = function(){
		// creazione maschera thumb
		var createThumbMaskDiv = document.createElement("div");
		createThumbMaskDiv.setAttribute("id", this.targetMaskThumb);
		createThumbMaskDiv.style.width = this.targetDivWidth+"px";
		createThumbMaskDiv.style.height = this.thumbHeight+"px";
		createThumbMaskDiv.style.overflow = "hidden";
		createThumbMaskDiv.style.position = "relative";
		// ---------------------------------------------------------------------------------------------------------
		// INTERVENIRE QUI PER IL MARGIN BOTTOM TRA IL DIV CONTENITORE MINIATURE ED IL RESTO DELLA PAGINA HTML
		// ---------------------------------------------------------------------------------------------------------
		createThumbMaskDiv.style.marginBottom = this.thumbMargin+"px";
		// ---------------------------------------------------------------------------------------------------------
		this.masterDiv.appendChild(createThumbMaskDiv);
		this.maskTuhmbContainer = document.getElementById(this.targetMaskThumb);
		// creazione contenitore miniature
		var createThumbContainer = document.createElement("div");
		createThumbContainer.setAttribute("id", this.targetMaskThumb+"_thumbs");
		createThumbContainer.style.position = "absolute";
		createThumbContainer.style.left = "0";	
		createThumbContainer.style.top = "0";	
		createThumbContainer.style.height = this.thumbHeight+"px";
		this.maskTuhmbContainer.appendChild(createThumbContainer);
		this.thumbContainer = document.getElementById(this.targetMaskThumb+"_thumbs");
		// creazione miniature
		this.thumbContainer.style.width = "0";
		for (scan=0;scan<=this.slideArray.length-1;scan++){
			var miniDiv = document.createElement("div");
			miniDiv.setAttribute("id", this.nameDiv+"_thumb_"+scan);
			miniDiv.style.width = this.thumbWidth+"px";
			miniDiv.style.overflow = "hidden";
			miniDiv.style.position = "relative";
			// normal
			miniDiv.style.float = "left";
			// ie
			miniDiv.style.styleFloat = "left";
			//firefox
			miniDiv.style.cssFloat = "left";
			miniDiv.style.margin = "0";
			if(scan<this.slideArray.length-1){
				miniDiv.style.marginRight = this.thumbMargin+"px";
			}
			var tempHtml = "<img src='"+this.targetFolder+"/"+this.slideArray[scan]+"' width='"+this.thumbWidth+"' alt='"+this.slideArray[scan]+"' title='"+this.slideArray[scan]+"'  />";
			miniDiv.innerHTML = tempHtml;
			miniDiv.targetLink = this.slideArray[scan];
			miniDiv.onclick = function() {
				me.changeSlide(this.targetLink);
			}
			miniDiv.onmouseover = function() {
			}
			miniDiv.onmouseout = function() {
			}
			this.thumbContainer.appendChild(miniDiv);
			if(scan<this.slideArray.length-1){
				this.thumbContainer.style.width = this.thumbContainer.offsetWidth + this.thumbWidth + this.thumbMargin +"px";
			} else {
				this.thumbContainer.style.width = this.thumbContainer.offsetWidth + this.thumbWidth +"px";
			}
		}	
		
		// controllo mouse
		this.maskTuhmbContainer.onmousemove = function(e){
			var mouseLoc = mouseDivPosition(e,me.targetMaskThumb);
			var offsetRilevamento = me.maskTuhmbContainer.offsetWidth/3;
			//window.status = mouseLoc+" - "+me.maskTuhmbContainer.offsetLeft;
			if(mouseLoc[0] < offsetRilevamento){
				me.offsetScroll = offsetRilevamento - mouseLoc[0];
				me.velocityScroll = 1+(mouseLoc[0]/5);
				if(me.enterFrameScrolling == undefined){
					me.scrollRight(me.thumbContainer,me.maskTuhmbContainer);
				}
			} else {
				if(mouseLoc[0] > me.maskTuhmbContainer.offsetWidth-offsetRilevamento){
					me.offsetScroll = offsetRilevamento - (me.maskTuhmbContainer.offsetWidth - mouseLoc[0]);
					me.velocityScroll = 1+( (me.maskTuhmbContainer.offsetWidth - mouseLoc[0])/5);
					if(me.enterFrameScrolling == undefined){
						me.scrollLeft(me.thumbContainer,me.maskTuhmbContainer);
					}
				} else {
					me.scrollStop();
				}
			}
		}
		this.maskTuhmbContainer.onmouseout = function() {
			me.scrollStop();
		}
	}
	
  
  this.changeSlide = function(image){
		// se image = undefined  slide puro, se image = immagine.jpg cerca immagine e carica (per thumball)
		if(image){
			this.image = image;
		}
		tempDiv = document.createElement("div");
		tempName = "slideshow_"+this.counter;
		oldName = "slideshow_"+(this.counter-1);
		tempDiv.setAttribute("id",tempName);
		this.counter++;
		tempDiv.style.position = "absolute";
		tempDiv.style.zIndex = this.counter;
		this.textDiv.style.zIndex = this.counter+10;
		tempDiv.style.opacity = "0";
		tempDiv.style.filter = "Alpha(opacity=0)";
		
		if(this.image){
			for(scan = 0; scan<this.slideArray.length-1; scan++){
				if(this.slideArray[0] != this.image){
					this.slideArray.push(this.slideArray.shift());
				} else {
					break;
				}
			}
		}
		tempHtml = "<img src='"+this.targetFolder+"/"+this.slideArray[0]+"' />";
		tempDiv.innerHTML = tempHtml;
		this.text = this.slideArray[0].split(".")[0];
		this.slideArray.push(this.slideArray.shift());
		this.galleryDiv.appendChild(tempDiv);
		this.newDiv = document.getElementById(tempName);
		this.oldDiv = document.getElementById(oldName);
		if(this.enterFrame){
			window.clearTimeout(this.enterFrame);
		}
		this.image = undefined;
		this.fadeIn();
		this.changeText();
	}
	
	
	
	this.fadeInText = function(){
		if(this.textDiv.offsetTop > this.targetDivHeight-this.textDiv.offsetHeight){
			if(this.textDiv.offsetTop-2 > this.targetDivHeight-this.textDiv.offsetHeight){
				this.textDiv.style.top = this.textDiv.offsetTop-2+"px";
			} else {
				this.textDiv.style.top = this.targetDivHeight-this.textDiv.offsetHeight+"px";
			}
			this.enterFrameChangeText = window.setTimeout(function(){me.fadeInText();},10);
		} else {
			window.clearTimeout(this.enterFrameOutAutoTextTimer);
			this.enterFrameOutAutoTextTimer = window.setTimeout(function(){me.fadeOutAutoText();},me.slideTime/2);	
			this.enterFrameOutAutoText = "on";
		}
	}
	this.fadeOutText = function(){
		if(this.textDiv.offsetTop < this.targetDivHeight){
			if(this.textDiv.offsetTop+2 < this.targetDivHeight){
				this.textDiv.style.top = this.textDiv.offsetTop+2+"px";
			} else {
				this.textDiv.style.top = this.targetDivHeight+"px";
			}
			this.enterFrameChangeText = window.setTimeout(function(){me.fadeOutText();},10);
		} else {
			this.changeText();
		}
	}
	
	this.fadeOutAutoText = function(){
		if(this.textDiv.offsetTop < this.targetDivHeight && this.enterFrameOutAutoText != undefined){
			this.textDiv.style.top = this.textDiv.offsetTop+1+"px";
			window.setTimeout(function(){me.fadeOutAutoText();},10);
		}
	}
	
	this.changeText = function(){
		this.enterFrameOutAutoText = undefined;
		window.clearTimeout(this.enterFrameChangeText);
		window.clearTimeout(this.enterFrameOutAutoTextTimer);
		this.movementText = undefined;
		if(this.textDiv.offsetTop < this.targetDivHeight){
			this.fadeOutText();
			return;
		}
		// esegue test se trova un file txt o html associato
		var textTarget = undefined;
		for(scanText=0;scanText<this.slideText.length;scanText++){
			if	(this.slideText[scanText].indexOf(this.text) != -1) {
				textTarget = this.targetFolder+"/"+this.slideText[scanText];
				break;
			}
		}
		// se trova il file lo carica ed esegue il fadeInText - se non lo trova esegue subito con nome file come testo
		if(textTarget){
			var scanText = new ajax("code/readTextFile.php","page=../"+textTarget);
			scanText.http_request.onreadystatechange = function(){
			  if (scanText.http_request.readyState == 4) {
				if (scanText.http_request.status == 200) {
					me.text = scanText.http_request.responseText;
					me.textDiv.innerHTML = "<div style='padding:20px;'>"+me.text+"</div>";
					me.fadeInText();
				}
			  }
			}
		} else {
			this.textDiv.innerHTML = "<div style='padding:20px;'>"+this.text+"</div>";
			this.fadeInText();
		}
	}
	
	this.fadeIn = function(){
		alpha = Number(this.newDiv.style.opacity);
		if(alpha<1){
			// fade in
			this.newDiv.style.opacity = alpha+0.05;
			this.newDiv.style.filter = "Alpha(opacity="+((alpha+0.05)*100)+")";
			// fade out
			if(this.oldDiv){
				this.oldDiv.style.opacity = 1-(alpha+0.05);
				this.oldDiv.style.filter = "Alpha(opacity="+(100-(alpha+0.05)*100)+")";
			}
			this.enterFrame = window.setTimeout(function(){me.fadeIn();},50);
		} else {
			// cancella il vecchio oldDiv
			if(this.oldDiv){
				this.galleryDiv.removeChild(this.oldDiv);
			}
			window.clearTimeout(this.enterFrame);
			this.enterFrame = window.setTimeout(function(){me.changeSlide();},this.slideTime);
			this.oldDiv.style.opacity = 100;
			this.oldDiv.style.filter = "Alpha(opacity=100)";

		}
	}
}

