/* global variables */
var coloreOver = "#e2007a";
var coloreStandard = "#9fa7aa";
var contents;
var fxStarted = false;
var objectFx;
var fxDissolveSpeed = 1;
var fxSlideSpeed = 1;
var fxRetryDelay = 0.1;
var fxSlideWidth = 125;
var fxLastSlidedObject = "";
var selectedPhoto = 1;
var fxLoadedPhotos = 0;
var fxPreloadingImage;
var loginStatus = false;
var loginHeight = 0;
var loginMoving = false;
var loginMovementSteps = 10;
var loginDiv;
/* debug */
function debug(testo)
{
if (document.getElementById("debug"))
{
document.getElementById("debug").innerHTML = testo;
}
else
{
alert(testo);	
}
}
/* initialize content gallery */
function initializeContentGallery()
{
var container = document.getElementById("elementsContainer");
setTimeout("setContainerProperties()", 1000);
cont1 = 0;
for (i = 0; i < container.childNodes.length; i++)  { if (container.childNodes[i].nodeName == "DIV") {  cont1 = cont1 + 1; } }
contents = new Array(cont1);
cont1 = 0;
for (i = 0; i < container.childNodes.length; i++)
{
if (container.childNodes[i].nodeName == "DIV")
{
cont2 = 0;
for (k = 0; k < container.childNodes[i].childNodes.length; k++) { if (container.childNodes[i].childNodes[k].nodeName == "DIV") { cont2 = cont2 + 1; } }
contents[cont1] = new Array(cont2 + 1);
contents[cont1][cont2] = container.childNodes[i].id;
cont2 = 0;
for (k = 0; k < container.childNodes[i].childNodes.length; k++)
{
if (container.childNodes[i].childNodes[k].nodeName == "DIV")
{
cont3 = 0;
for (z = 0; z < container.childNodes[i].childNodes[k].childNodes.length; z++) { if (container.childNodes[i].childNodes[k].childNodes[z].nodeName == "DIV") { cont3 = cont3 + 1; } }
contents[cont1][cont2] = new Array(cont3);
cont3 = 0;
contents[cont1][cont2][cont3] = container.childNodes[i].childNodes[k].id;
cont3 = 1;
for (z = 0; z < container.childNodes[i].childNodes[k].childNodes.length; z++) 
{ 
if (container.childNodes[i].childNodes[k].childNodes[z].nodeName == "DIV")
{ 
contents[cont1][cont2][cont3] = container.childNodes[i].childNodes[k].childNodes[z].innerHTML;
cont3 = cont3 + 1;
} 
}
cont2 = cont2 + 1;
}
}
cont1 = cont1 + 1;
}
}
}
/* start dissolve */
function startDissolve(target, direction)
{
if (fxStarted == false)
{
if (document.getElementById(target))
{
objectFx = document.getElementById(target);
fxStarted = true;
dissolve(direction, 0);
}
}
else
{
setTimeout("startDissolve('" + target + "', '" + direction + "')", (fxRetryDelay * 1000));
}
}
/* dissolve */
function dissolve(direction, counter)
{
if (counter <= 25)
{
if (counter == 0)
{
objectFx.style.display = "block";
}
if (direction == "down")
{
objectFx.style.filter = "alpha(opacity=" + parseInt(100 - ((counter * 4) / 100) * 100) + ")";
objectFx.style.opacity = 1 - ((counter * 4) / 100);
objectFx.style.MozOpacity = 1 - ((counter * 4) / 100);
}
else if (direction == "up") 
{
objectFx.style.filter = "alpha(opacity=" + parseInt(0 + ((counter * 4) / 100) * 100) + ")";
objectFx.style.opacity = 0 + ((counter * 4) / 100);
objectFx.style.MozOpacity = 0 + ((counter * 4) / 100);
}
setTimeout("dissolve('" + direction + "', " + (counter + 1) + ")", (fxDissolveSpeed * gpt_attesaFotogrammaSuccessivo));
}
else
{
if (direction == "down")
{
objectFx.style.display = "none";
}
fxStarted = false;
}
}
/* set container properties */
function setContainerProperties()
{
if (document.getElementById("elementsContainer") && document.getElementById("navigation"))
{
var container = document.getElementById("elementsContainer");
var navigation = document.getElementById("navigation");
var minHeight = gpt_getStyle(navigation, 'height');
container.style.minHeight = minHeight;
}
}
/* show content */
function showContent(target)
{
var position;
var spegni;
if (document.getElementById("content" + target).style.display == "" || document.getElementById("content" + target).style.display == "none")
{
if (fxStarted == false)
{
for (i = 0; i < contents.length; i++)
{
if (document.getElementById(contents[i][contents[i].length - 1]).style.display == "block")
{
spegni = contents[i][contents[i].length - 1];
}
else
{
document.getElementById(contents[i][contents[i].length - 1]).style.display = "none";
for (k = 0; k < contents[i].length - 1; k++)
{
if (contents[i][k] != "")
{
if (document.getElementById(contents[i][k][0]))
{
document.getElementById(contents[i][k][0]).style.display = "none";
}
}
}
}
}
startDissolve(spegni, "down");
for (i = 0; i < contents.length; i++)
{
if (contents[i][contents[i].length - 1] == ("content" + target)) 
{
position = i;
}
}
document.getElementById(contents[position][contents[position].length - 1]).style.opacity = 1;
document.getElementById(contents[position][contents[position].length - 1]).style.MozOpacity = 1;
document.getElementById(contents[position][contents[position].length - 1]).style.filter = "alpha(opacity=100)";
if (contents[position].length == 0)
{
startDissolve(contents[position][contents[position].length - 1], "up");		
}
else
{
startDissolve(contents[position][contents[position].length - 1], "up");		
}
for (k = 0; k < contents[position].length - 1; k++)
{
if (document.getElementById(contents[position][k][0]))
{
startDissolve(contents[position][k][0], "up");
}
}
}
else
{
setTimeout("showContent('" + target + "')", (fxRetryDelay * 1000));	
}
}
}
/* slide description */
var descriptionsMoving = "";
var mouseOver = "";
function showSlide(target, action)
{
if (action == true)
{
mouseOver = target;
setTimeout("slideDescription('" + target + "', false)", 500);
}
else
{
slideDescription(target, true);
}
}
function slideDescription(target, onlySlideOut)
{
if (mouseOver == target)
{
if (fxStarted == false)
{
for (k = 0; k < document.getElementById(target).childNodes.length; k++)
{
if (document.getElementById(target).childNodes[k].nodeName == "DIV")
{
for (z = 0; z < document.getElementById(target).childNodes[k].childNodes.length; z++)
{
if (document.getElementById(target).childNodes[k].childNodes[z].nodeName == "DIV")
{
objectFx = document.getElementById(target).childNodes[k].childNodes[z];
fxStarted = true;
slide(0, onlySlideOut, target);
}
}
}
}
}
else
{
setTimeout("slideDescription('" + target + "', " + onlySlideOut + ")", (fxRetryDelay * 1000));
}
}
}
/* slide */
function slide(counter, onlySlideOut, description)
{
if (counter <= 25)
{
if (fxLastSlidedObject != "")
{
if (onlySlideOut == true)
{
if (fxLastSlidedObject.style.marginLeft != ((0 - fxSlideWidth)) + "px")
{
fxLastSlidedObject.style.marginLeft = ((0 - fxSlideWidth) + (fxSlideWidth - (parseInt(fxSlideWidth / 25) * counter)))+ "px";				
}
}
}
if (onlySlideOut == false)
{
objectFx.style.marginLeft = ((0 - fxSlideWidth) + (parseInt(fxSlideWidth / 25) * counter))+ "px";
}
setTimeout("slide(" + (counter + 1) + ", " + onlySlideOut + ", '" + description + "')", (fxSlideSpeed * 40));
}
else
{
fxLastSlidedObject = objectFx;
fxStarted = false;
descriptionsMoving = "";
}
}
/* initialize photogallery */
function initializePhotoGallery()
{
var idMedium = "";
var container = document.getElementById("thumbs");
var cont1 = 0;
for (i = 0; i < container.childNodes.length; i++)
{
if (container.childNodes[i].nodeName == "A")
{
idMedium = container.childNodes[i].id;
idMedium = "medium" + idMedium.substring(5);
document.getElementById(idMedium).style.display = "none";			
cont1 = cont1 + 1;
}
}
startDissolve("photoGallery", "up");
showPhoto(selectedPhoto); 
}
/* show photo */
function showPhoto(target) 
{
var k = 0;
for (i = 0; i < document.getElementById("medium" + target).childNodes.length; i++)
{
if (document.getElementById("medium" + target).childNodes[i].nodeName == "IMG")
{
fxPreloadingImage = document.getElementById("medium" + target).childNodes[i];
}
}
if (target != selectedPhoto)
{
startDissolve("medium" + selectedPhoto, "down");
startDissolve("medium" + target, "up");
document.getElementById("thumb" + selectedPhoto).className = "thumb";
document.getElementById("thumb" + target).className = "thumbSelected";
fxLoadedPhotos = fxLoadedPhotos + 1;
selectedPhoto = target;
document.getElementById("photoDescription").innerHTML = "<div>" + document.getElementById("medium" + selectedPhoto).title + "</div>";
}
else if (fxLoadedPhotos == 0)
{
document.getElementById("medium" + target).style.opacity = 1;
document.getElementById("medium" + target).style.MozOpacity = 1;
document.getElementById("medium" + target).style.filter = "alpha(opacity=100)";
document.getElementById("medium" + target).style.display = "block";
document.getElementById("thumb" + selectedPhoto).className = "thumbSelected";
document.getElementById("photoDescription").innerHTML = "<div>" + document.getElementById("medium" + selectedPhoto).title + "</div>";
}
}
/* show login */
function showHideLogin(cont)
{
if (loginMoving == false || (loginMoving == true && cont > 0))
{
if (loginStatus == false)
{
if (cont <= (loginMovementSteps + 1))
{
loginMoving = true;
loginDiv.style.height = parseInt((cont * loginHeight)) + "px";
setTimeout("showHideLogin(" + (cont + 1) + ")", (fxDissolveSpeed * gpt_attesaFotogrammaSuccessivo));
}
else
{
loginStatus = true;
loginMoving = false;
}
}
else
{
if (cont <= (loginMovementSteps + 1))
{
loginMoving = true;
loginDiv.style.height = parseInt(((loginHeight * (loginMovementSteps + 1)) - (cont * loginHeight))) + "px";
setTimeout("showHideLogin(" + (cont + 1) + ")", (fxDissolveSpeed * gpt_attesaFotogrammaSuccessivo));
}
else
{
loginStatus = false;
loginMoving = false;
}
}
}
}
/* initialize login */
function initializeLogin()
{
if (document.getElementById("boxAreaRiservata"))
{
loginDiv = document.getElementById("boxAreaRiservata");
loginHeight = gpt_getStyle(loginDiv, "height");
loginHeight = parseFloat(parseFloat(loginHeight) / loginMovementSteps);
loginDiv.style.position = "absolute";
loginDiv.style.overflow = "hidden";
loginDiv.style.height = "0px";
}
}
/* get style */
function gpt_getStyle(el, style) 
{
if (!document.getElementById)
{
return; 
}
var value = el.style[gpt_toCamelCase(style)];
if (!value)
{
if (document.defaultView)
{
value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
}
else if (el.currentStyle)
{
value = el.currentStyle[gpt_toCamelCase(style)];
}
}
return value;
}		
/* to camel case */
function gpt_toCamelCase( sInput )
{
var oStringList = sInput.split('-');
if (oStringList.length == 1)  
return oStringList[0];
var ret = sInput.indexOf("-") == 0 ?
oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
for (var i = 1, len = oStringList.length; i < len; i++) {
var s = oStringList[i];
ret += s.charAt(0).toUpperCase() + s.substring(1)
}
return ret;
}

