//**********************************************************************
//* Gestione PhotoGallery                                              *
//---------------------------------------------------------------------*
	var thumb = new Array ();
	var preview = new Array ();
	var imgElem = new Array ();
	var photographer = new Array ();
	var caption = new Array ();
	var epakey = new Array ();
	var date_p = new Array ();
	var el_imgpreview = null ;
	var el_epakey = null ;
	var el_caption = null ;
	var el_photo = null ;
	var el_date = null ;
	var loadingImg = "";
	var nullThumb = "";
	var thumbRow = 0 ;
	var images = 0 ;
	var firstIndex = 0 ;
	var lastIndex = 0 ;
	var maxIndex = 0 ;
	var lastIndex = 0 ;
	var lind = 0 ;
	var idInterval = null ;
	var flg_MOZ = false;
	var flg_IE = false ;
	
	var urlwebgate = new Array ();
	
	var alltitle = new Array();
	var alldescription = new Array();
	var el_alltitle = null;
	var el_alldescription = null;
	
	var currentcaption;
			
	function thumbShift(versus){
		//		alert("images"+images+"  First="+firstIndex+"   Last="+lastIndex+"   MaxI="+maxIndex+"   NRow="+thumbRow);
		if(versus == 1){  //Shift left
			if (firstIndex <= 0) return ;
			firstIndex = firstIndex - thumbRow ;
			if (firstIndex <= 0) firstIndex = 0 ;
		}else{  //Shift right
			if ((firstIndex+thumbRow) > maxIndex) return ;
			firstIndex = firstIndex + thumbRow ;
		}
		
		// Inserimento immagini di Loading
		if(loadingImg != ""){
			for (ind=0 ; ind < thumbRow; ind++){
				imgElem[ind].src = loadingImg ;				
			}
		}

		lastIndex = firstIndex + thumbRow -1 ;
		if(lastIndex > maxIndex) lastIndex = maxIndex ;
		ind2 = firstIndex ;
//		alert ("ImgLenght="+imgElem.lenght);
		for (ind=0 ; ind < thumbRow; ind++){
			if(ind2 <= lastIndex) {
				imgElem[ind].src = thumb[ind2] ;
			}else{
				imgElem[ind].src = nullThumb ;
			}
			ind2++ ;
		}
	}
	
	function thumbShiftAllPrizes(versus){
		var elemTdTitle;
		var idSigleprizes;
	
		//		alert("images"+images+"  First="+firstIndex+"   Last="+lastIndex+"   MaxI="+maxIndex+"   NRow="+thumbRow);
		if(versus == 1){  //Shift left
			if (firstIndex <= 0) return ;
			firstIndex = firstIndex - thumbRow ;
			if (firstIndex <= 0) firstIndex = 0 ;
		}else{  //Shift right
			if ((firstIndex+thumbRow) > maxIndex) return ;
			firstIndex = firstIndex + thumbRow ;
		}
		
		// Inserimento immagini di Loading
		if(loadingImg != ""){
			for (ind=0 ; ind < thumbRow; ind++){
				imgElem[ind].src = loadingImg ;				
			}
		}

		lastIndex = firstIndex + thumbRow -1 ;
		if(lastIndex > maxIndex) lastIndex = maxIndex ;
		ind2 = firstIndex ;
//		alert ("ImgLenght="+imgElem.lenght);
		for (ind=0 ; ind < thumbRow; ind++){
			if(ind2 <= lastIndex) {
				imgElem[ind].src = thumb[ind2];
				idSigleprizes="idTitlePrizes"+ind;
				elemTdTitle = document.getElementById(idSigleprizes);
				elemTdTitle.innerHTML = alltitle[ind2];	
			}else{
				imgElem[ind].src = nullThumb;
				idSigleprizes="idTitlePrizes"+ind;
				elemTdTitle = document.getElementById(idSigleprizes);
				elemTdTitle.innerHTML = "";	
			}
			ind2++ ;
		}
	}

	function showPreview(lbox){
		if(idInterval) clearTimeout(idInterval) ;
		lind = lbox + firstIndex ;
		if(lind<0 || lind>maxIndex) return ;
		if(!el_imgpreview) loadElements();
		newImg = new Image();
		newImg.src = preview[lind] ;
//		alert("Complete="+newImg.complete);
		currentcaption = caption[lind];
		//Start Opacity
		idInterval=setTimeout("alphaDecrease()",2);
	}
	
	function waitNewImg(){
	
		if(idInterval)clearInterval(idInterval);
		if(!newImg.complete){
			idInterval=setTimeout("waitNewImg()",50);
		}else{
//			idInterval=setTimeout("changePreview()",2);
			//Immagine caricata: sostituzione src e caption
			el_imgpreview.src = newImg.src ;
			
			if(el_epakey){
				if (epakey[lind]==''){
					el_epakey.innerHTML = '&nbsp';
				}
				else{
					el_epakey.innerHTML = epakey[lind];
				}
			}
			
			if(el_caption){
				if (caption[lind]==''){
					el_caption.innerHTML = '&nbsp';
				}
				else{
					el_caption.innerHTML = caption[lind];
				}
			}
			
			if(el_photo){
				if (photographer[lind]==''){
					el_photo.innerHTML = '&nbsp';
				}else{
					el_photo.innerHTML = photographer[lind];
				}
			}
						
			if(el_date){
				if (date_p[lind]==''){
					el_date.innerHTML = '&nbsp';
				}else{
					el_date.innerHTML = date_p[lind];
				}
			}
			            
			if(el_alltitle){
				if (alltitle[lind]==''){
					el_alltitle.innerHTML = '&nbsp';
				}else{
					el_alltitle.innerHTML = alltitle[lind];
				}
			}
			
            if(el_alldescription){
				if (alldescription[lind]==''){
					el_alldescription.innerHTML = '&nbsp';
				}else{
					el_alldescription.innerHTML = alldescription[lind];
				}
			}
			
			
			if(el_urlwebgate){
				if (urlwebgate[lind]==''){
					el_urlwebgate.onClick = '&nbsp';
			
		
				}else{
				    
					//el_urlwebgate.onclick = 'function (){ urlwebgate[lind]; }';
					el_urlwebgate.href=urlwebgate[lind];
				}
			}
			
			/*
			if(el_epakey)el_epakey.innerHTML = epakey[lind] ;
			if(el_caption)el_caption.innerHTML = caption[lind] ;
			if(el_photo)el_photo.innerHTML = photographer[lind] ;
			if(el_date)el_date.innerHTML = date_p[lind] ;
			if(el_alltitle)el_alltitle.innerHTML = alltitle[lind] ;
			if(el_alldescription)el_alldescription.innerHTML = alldescription[lind] ;
			*/
			
			idInterval=setTimeout("alphaIncrease()",2);
		}
	}
		
		
		
	function changePreview(){
		
		if(idInterval) clearTimeout(idInterval) ;
		
		el_imgpreview.src = newImg.src ;
		if(el_epakey)el_epakey.innerHTML = epakey[lind] ;
		if(el_caption)el_caption.innerHTML = caption[lind] ;
		if(el_photo)el_photo.innerHTML = photographer[lind] ;
		if(el_date)el_date.innerHTML = date_p[lind] ;
        if(el_alltitle)el_alltitle.innerHTML = alltitle[lind] ;
        if(el_alldescription)el_alldescription.innerHTML = alldescription[lind] ;
		
		idInterval=setTimeout("alphaIncrease()",2);
	}	

	function alphaDecrease(){
		var opacity ;
		if(idInterval) clearTimeout(idInterval) ;
		if(flg_MOZ) {
			opacity = (el_imgpreview.style.opacity * 100) - 10;
			if(opacity < 0) opacity = 0;
			el_imgpreview.style.opacity = opacity / 100 ;
		}else if(flg_IE){
			opacity = el_imgpreview.filters.alpha.opacity - 10 ;
			if(opacity < 0) opacity = 0;
			el_imgpreview.filters.alpha.opacity = opacity;
		}else
			opacity = 0 ;
//		alert ("ci siamo- Opacity= "+opacity);
//		alert("alphadecrease");
		if(opacity > 0){
			idInterval=setTimeout("alphaDecrease()",40);
		}else {
			idInterval=setTimeout("waitNewImg()",2);
		}
	}
	
	function alphaIncrease(){
		var opacity ;
		if(idInterval) clearTimeout(idInterval) ;
		if(flg_MOZ) {
			opacity = (el_imgpreview.style.opacity * 100) + 5;
			if(opacity > 100) opacity = 100 ;
			el_imgpreview.style.opacity = opacity / 100;
		}else if(flg_IE){
			opacity = el_imgpreview.filters.alpha.opacity + 5 ;
			if(opacity > 100) opacity = 100 ;
			el_imgpreview.filters.alpha.opacity = opacity  ;
		}else
			opacity = 100	
		
		if(opacity < 100){
			idInterval=setTimeout("alphaIncrease()",10);
		}
	}
	
	
	function loadElements(){
		el_imgpreview = getElementIdKey("imgpreview") ;
		el_epakey = getElementIdKey("fgepakey") ;
		el_caption = getElementIdKey("fgcaption") ;
		el_photo = getElementIdKey("fgphoto") ;
		el_date = getElementIdKey("fgdate") ;
		el_alltitle = getElementIdKey("prizestitle") ;
		el_alldescription = getElementIdKey("prizesdescription") ;
		
		el_urlwebgate = getElementIdKey("urlwebgate") ;
		
//		alert("Navigator:"+navigator.userAgent) ;

		if (el_imgpreview.filters)
			flg_IE = true ;
		else if(el_imgpreview.style.opacity) 
			flg_MOZ = true;
			
	}	

	function arrowOver(elem, versus, over, url){
		if(over == 2)
			elem.src = url ;
		if(versus == 1){ 
			if(firstIndex <= 0){
				return ;
			}
		}else{
			if ((firstIndex+thumbRow) > maxIndex){
				return ;
			}
		}
		elem.src = url ;
	}

	function getElementIdKey(id_elemento) {
 	var elemento=null;
 	if(document.all)
  		elemento = document.all[id_elemento];
 	else
  		elemento = document.getElementById(id_elemento);
 	return elemento;
}

	function getElementIdKey_orig(id_elemento) {
 	var elemento=null;
 	if(document.getElementById)
  		elemento = document.getElementById(id_elemento);
 	else
  		elemento = document.all[id_elemento];
 	return elemento;
}

//**********************************************************************
//* Apertura finestra per Preview Live Feed                                              *
//---------------------------------------------------------------------*
	var w_plf = null ;
	function openPLF(url,name,w_width,w_height){
	if(w_plf) w_plf.close();
	wleft = (screen.width - w_width) /2 ;
	wtop = (screen.height - w_height) / 2 ;
	wfeatures="menubar=no,height="+w_height+",width="+w_width+",top=" + wtop + ",left=" + wleft + ",location=yes,toolbar=yes,titlebar=yes,resizable=yes,scrollbars=yes";
//	alert ("wfeatures="+wfeatures);
	w_plf=window.open(url,name,wfeatures) ; 
	w_plf.focus() ;	 
	
	}


