function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion;
    this.dom=document.getElementById?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0; 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
    this.ns4=(document.layers && !this.dom)?1:0;
    this.opera=(window.opera)?1:0;
    this.safari=(navigator.userAgent.indexOf("afari")>-1)?1:0;
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
    return this;
} 

var bw=new verifyCompatibleBrowser();

var indexGallery = window.location.search.substring(1);
/*
* Indice dell'immagine grande attualmente visualizzata nella galleria.
*/
var indexImg;
/*Inizializzazione Array di ThumbNail*/
var leftrightslide=new Array();

//Numero delle fotografie caricate in una singola galleria.
var numPhoto;
switch(indexGallery){
	//Nome Galleria height="59" width="90" 
	case '1':
	case '2':
	case '3':
	case '4':
		numPhoto=18;
		break;
	case '5':
	case '7':
		numPhoto=9;
		break;
	case '6':
		numPhoto=5;
		break;
	case '8':
		numPhoto=20;
		break;
	case '9':
		numPhoto=27;
		break;
	default:
		indexGallery='1';
		numPhoto=11;
		break;
}
/*ritorna il codice dello slide dei thumbnail creato dinamicamente*/
function writeThumbnails(){
	/*CARICAMENTO DINAMICO dell'Array contenente i thumbnail della galleria.*/
	for(var i=0; i<numPhoto; i++) {
		leftrightslide[i]='<img src="img/art/tn/' + filling(String(i+1)) + '.jpg" border=0 onmouseover="setCursorHand(this);" onclick="showBigImage(' + i + ')">';
	}
	
	leftrightslide='<nobr>'+leftrightslide.join("")+'</nobr>';
	return leftrightslide;
}

/*
* SCRIPTS per lo scroll del testo e dei thumbnails.
*/
// begin absolutely positioned scrollable area object scripts 
var speedText=50;
var speedThumbs=10;
if (bw.ns4 || bw.ns5) speedThumbs=20;

var loop, timer;
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.';
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight;
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight;
    //this.scrollWidth=bw.ns4?this.css.document.width:(bw.opera)?getContentWidth(this.el):this.el.offsetWidth;
    this.scrollWidth=bw.ns4?this.css.document.width:(bw.opera||bw.safari||bw.ns5)?getContentWidth(this.el):this.el.offsetWidth;
    this.clipWidth=bw.ns4?this.css.clip.width:this.el.offsetWidth;
    //this.clipWidth=bw.ns4?this.css.clip.width:bw.safari?this.el.scrollWidth:this.el.offsetWidth;
    this.lft=MoveAreaLeft;this.rht=MoveAreaRight;
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object";
    eval(this.obj + "=this");
    return this 
}
function getContentWidth(el){
     var tmp=el.style.overflow;
     el.style.overflow='auto';
     var w=el.scrollWidth;
     el.style.overflow=tmp;
     return w;
}
function MoveArea(x,y){ 
    this.x=x;this.y=y;
    this.css.left=this.x + 'px'; 
    this.css.top=this.y + 'px';
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
		this.MoveArea(0,this.y-move);
		if(loop) setTimeout(this.obj+".down("+move+");",speedText);
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    		this.MoveArea(0,this.y-move);
    		if(loop) setTimeout(this.obj+".up("+move+");",speedText);
	} 
} 

function MoveAreaRight(move){
	if(this.x<0){ 
    		this.MoveArea(this.x+move,0);
    		if(loop) setTimeout(this.obj+".rht("+move+");",speedThumbs);
	} 
} 
function MoveAreaLeft(move){
	if(this.x>-this.scrollWidth+objContainerThumbs.clipWidth){ 
		this.MoveArea(this.x+move,0);
		if(loop) setTimeout(this.obj+".lft("+move+");",speedThumbs);
	} 
} 
 
function PerformScroll(speed){
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed);
	} 
} 
function PerformHorizontalScroll(speed){
	if(initialised){
		loop=true; 
		if(speed>0){ if( bw.ns4 || bw.ns5 )speed=3; objScrollerThumbs.rht(speed); }
		else{ if( bw.ns4 || bw.ns5 )speed=-3; objScrollerThumbs.lft(speed); }
	} 
} 
 
function CeaseScroll(){ 
    loop=false;
    if(timer) clearTimeout(timer);
} 
var initialised; 
function InitialiseScrollableArea(){ 
    //objContainer=new ConstructObject('divContainer');
    //objScroller=new ConstructObject('divContent','divContainer');
    //objScroller.MoveArea(0,0);

    objContainerThumbs=new ConstructObject('divContainerThumbs');
    objScrollerThumbs=new ConstructObject('divContentThumbs','divContainerThumbs');
		objScrollerThumbs.MoveArea(0,0);

    initialised=true; 
} 
// end absolutely positioned scrollable area object scripts
/*********************************************/

/*Caricamento dinamico delle Immagini Grandi di ogni singola anteprima galleria fotografica.*/
function LoadBigImages() {
	var arr=new Array();
	/* Immagini con width="420" ed height="285" massimi */
	for(var i=0; i<numPhoto; i++) {
		arr[i]='img/art/lg/' + filling(String(i+1)) + '.jpg';
	}
	return arr;
}
var bigImages = LoadBigImages();

function showBigImage(index){
	/*nuova gestione dell'onload dell'immagine. da testare con safari*/
	if(bw.opera) document.bigImg.onload=initImage(document.bigImg);
	else document.getElementById("idBigImg").onload=function(){
			if(timeOutVisibility!=null) {
				clearTimeout( timeOutVisibility );
			}
		  if( document.getElementById("idBigImg")!=null ){
			  setOpacity(document.getElementById("idBigImg"), 0);
			  window.setTimeout("document.getElementById('idBigImg').style.visibility = 'visible';",1);
		  	fadeIn(document.getElementById("idBigImg").name,0);
  		}
		}
	
	if( index!=indexImg ) {
		document.bigImg.style.visibility='hidden';
		indexImg=index;
		document.bigImg.src = bigImages[index];
	}
}
function showNextImg() {
	var appo= (indexImg==bigImages.length-1)?0:indexImg+1;
	showBigImage(appo);
}
function showPrevImg() {
	var appo= (indexImg==0)?bigImages.length-1:indexImg-1;
	showBigImage(appo);
}



var descGallery = LoadDescGallery();
var intGallery = LoadIntGallery();

function showTextGallery(){
	document.getElementById("intGal").innerHTML = intGallery[indexGallery];
	document.getElementById("divContent").innerHTML = descGallery[indexGallery];
	
	/*imposto dinamicamente l'altezza dei div contenenti il testo
		della gallery e le frecce per lo scrolling dello stesso*/
	document.getElementById("divContainer").style.height = (parseInt(document.getElementById("tableText").style.height) - document.getElementById("intGal").offsetHeight)+'px';
	document.getElementById("containerUpDownArrows").style.height = document.getElementById("divContainer").style.height;
}

function getGalName() {
	return intGallery[indexGallery];
}
function getGalText() {
	return descGallery[indexGallery];
}

/*
 * SCRIPTS per l'effetto di Opacita' variabile sul caricamento delle immagini grandi.
*/
var timeOutVisibility;

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
function fadeIn(objName,opacity) {
    obj = eval('document.' + objName);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      timeOutVisibility = window.setTimeout("fadeIn('"+objName+"',"+opacity+");", 100);
    }
}
function initImage(obj) {
	if(timeOutVisibility!=null) {
		clearTimeout( timeOutVisibility );
	}
  if( obj!=null ){
	  setOpacity(obj, 0);
	  window.setTimeout("obj.style.visibility = 'visible';",1);
  	fadeIn(obj.name,0);
  }
}