/*------------------------------------------------------------*/
/*                                                            */
/*   Pgm. contenente funzioni di configurazione web           */ 
/*                                                            */  
/*                                                            */
/*------------------------------------------------------------*/ 

// variabili globali

var butblu = new Array()
var butred = new Array()
var counterImage
var frameImage = 12
var pageFrame = 5
var photo = new Array()
var qtyPhotos = 72
var qtyPhotoConf = 10
var logo = new Image() 
var backGround = new Image()
var prevPhotored = new Image()
var prevPhotoblu = new Image()
var nextPhotored = new Image()
var nextPhotoblu = new Image()
var prevPhotoBkg = new Image()
var nextPhotoBkg = new Image()
var loadCookie
var loadFlash
var homePage

// Precaricamento immagini logo/sfondo/bottoni

function loadImg() {
	
	var butQty = 16 
	var i
		
	for (i = 1; i <= butQty; i++) {
		butred[i] = new Image()
		butred[i].src = eval("'../image/butred" + i + ".jpg'")
		butblu[i] = new Image()
		butblu[i].src = eval("'../image/butblu" + i + ".jpg'")
	}

	butred[i] = new Image()
	butred[i].src = "../image/prevred.jpg"
	butblu[i] = new Image()
	butblu[i].src = "../image/prevblu.jpg"
	
	butred[++i] = new Image()
	butred[i].src = "../image/nextred.jpg"
	butblu[i] = new Image()
	butblu[i].src = "../image/nextblu.jpg"

	logo.src = "../image/logo.jpg"
        
	if (loadFlash == "no" && homePage == "yes")
		backGround.src = "../image/nextsta.jpg"
	else
		backGround.src = "../image/nextbkg.jpg"

	prevPhotored.src = "../image/prevphotored.jpg"
	prevPhotoblu.src = "../image/prevphotoblu.jpg"
	nextPhotored.src = "../image/nextphotored.jpg"
	nextPhotoblu.src = "../image/nextphotoblu.jpg"
	prevPhotoBkg.src = "../image/prevphotobkg.jpg"
	nextPhotoBkg.src = "../image/nextphotobkg.jpg"

	counterImage = 0	
}

// precaricamento immagini photos

function loadPhotos() {
	var index
	
	for (index=1; index <= qtyPhotos; index++) {
		photo[index] = new Image()
		photo[index].src = eval("'../photos/thumbnail/photo" + index + ".jpg'")
	}
}

// precaricamento immagini conference photos

function loadPhotosConf() {
	var index
	
	for (index=1; index <= qtyPhotosConf; index++) {
		photo[index] = new Image()
		photo[index].src = eval("'../confpho/thumbnail/photo" + index + ".jpg'")
	}
}


// Rollover immagini bottoni per attivazione cambio colore

function buttonActive(buttonColor, numberButton) {

	var buttonOn
	var buttonOff
	
	buttonOn = "but" + buttonColor + "[" + numberButton + "]"
	buttonOff = "button" + numberButton
	eval("document." + buttonOff + ".src=" + buttonOn + ".src")
}

// Emissione windows con immagine ingrandita

function imageBig(indexPhoto) {
	var nameImage
	var positionGallery
	var indexGallery

	positionGallery = counterImage * frameImage
	indexGallery = indexPhoto + positionGallery
	nameImage = "photo" + indexGallery + ".jpg"
	newWindow=window.open("", "Image", "width=790 height=575")
	newWindow.document.write("<html><head><title>Image</title></head><body><img src='../photos/" + nameImage +
		"'></body></html>")
}

// Caricamento set di photo

function loadSetPhoto(direction) {
	var position
	var index
	var picture
	var elemId
	
	if (counterImage == 0 || counterImage < pageFrame) {	
		position = counterImage * frameImage
		
		for (index=1; index <= frameImage; index++) {
			position ++
			picture = eval("photo[" + position + "].src")
			eval("document.photo" + index + ".src ='" + picture + "'")	
		}
		
		switch (direction) {
	
		case "prev":
			if (counterImage == 0) {
				elemId=document.getElementById("ancorprev")
				elemId.parentNode.removeChild(elemId)
			}
			else if (counterImage == pageFrame-2)
				createButtonPhoto("next")
			break
	
		case "next":
			
			if (counterImage == 0) 
				createButtonPhoto("next")
			else if (counterImage == 1)
				createButtonPhoto("prev")
			else if (counterImage == pageFrame-1 ) {
				elemId=document.getElementById("ancornext")
				elemId.parentNode.removeChild(elemId)
			}
			
			break
		}
	}
}

// Rollover immagini bottoni photo per attivazione cambio colore

function buttonActivePhoto(color, direction) {
	eval("document." + direction + "photo.src =" + direction + "Photo" + color + ".src")
}

// Gestione caricamento bottoni avanzamento Photos

function createButtonPhoto(direction) {

	var newElemDirec
	var idElement
	var imageDirec
	var actionFunc1
	var actionFunc2
	var actionFunc3
	var imageButton
	var operator

	switch (direction) {
	
	case "prev":
		operator="--"
		break

	case "next":
		operator="++"
		break
	}

	imageButton=eval(direction + "Photored.src")
	actionFunc1="buttonActivePhoto('blu','" + direction + "')"
	actionFunc2="buttonActivePhoto('red','" + direction + "')"
	actionFunc3="counterImage" + operator + ";loadSetPhoto('" + direction + "')"

	if (document.all) {
		eval("document.all." + direction + "photox.innerHTML=\"<a name=ancor" + direction + " href='javascript:void(0)'><img border=0 name=" + direction +
			"photo src=" + imageButton + " onMouseOver=" + actionFunc1 + " onMouseOut=" + actionFunc2 + " onClick=" + actionFunc3 + "></a>\"")  
	}
	else {
		idElement=eval("document.getElementById('" + direction + "photox')")
		newElemDirec=document.createElement("A")
		newElemDirec.setAttribute("href", "javascript:void(0)")
		eval("newElemDirec.setAttribute('id', 'ancor" + direction + "')") 
		imageDirec=document.createElement("IMG")
		imageDirec.setAttribute("border","0")
		eval("imageDirec.setAttribute('name', '" + direction + "photo')")
		imageDirec.setAttribute("border", "0")
		imageDirec.setAttribute("onMouseOver", actionFunc1)
		imageDirec.setAttribute("onMouseOut", actionFunc2)
		imageDirec.setAttribute("onClick", actionFunc3)
		eval("imageDirec.setAttribute('src', '" + imageButton + "')")
		newElemDirec.appendChild(imageDirec)
		idElement.appendChild(newElemDirec)
	}
}

// Generazione cookie

function setCookie(name, value, expire) {
	
        document.cookie=name + "=" + escape(value) + "; expires=" + expire.toUTCString()
}

// Periodo validità cookie

function expCookie(expire, addHours, addMinutes, addSeconds) {
	
        var hours=expire.getHours()
	var minutes=expire.getMinutes()
	var period=(hours * 60 + minutes) * 60 * 1000 
	expire.setTime(expire.getTime() - period)
	period=addHours * addMinutes * addSeconds * 1000
	expire.setTime(expire.getTime() + period)
	return expire	
}

// Recupero informazioni cookie

function getCookie(name) {

	var search=name + "="
	if (document.cookie.length > 0) {
		offset=document.cookie.indexOf(search)
		if (offset != -1) {
			offset=search.length
			end=document.cookie.indexOf(";", offset)
			if (end == -1)
				end=document.cookie.length
                        return unescape(document.cookie.substring(offset, end))
		}
	}
}

// Controllo cookie

function cntCookie(name, value, expire) {

	if (getCookie(name) != null) {
                loadCookie=true
        }
	else {
                setCookie(name, value, expire)
		loadCookie=false	
	}
}