// JavaScript Document
var total = 100;
var number = eval(location.search.substr(1));
if (!number){ number = 1; }
var prec = number - 1;
var succ = prec + 2;
var size = 0;
var dimbarra;
var asse_x = 0;
var asse_y = 0;
var info = new Array(91);
info[0] = "";
info[1] = "";
info[2] = "";
info[3] = "";
info[4] = "";
info[5] = "";
info[6] = "";
info[7] = "";
info[8] = "";
info[9] = "";
info[10] = "";
info[11] = "";
info[12] = "";
info[13] = "";
info[14] = "";
info[15] = "";
info[16] = "";
info[17] = "";
info[18] = "";
info[19] = "";
info[20] = "";
info[21] = "";
info[22] = "";
info[23] = "";
info[24] = "";
info[25] = "";
info[26] = "";
info[27] = "";
info[28] = "";
info[29] = "";
info[30] = "";
info[31] = "";
info[32] = "";
info[33] = "";
info[34] = "";
info[35] = "";
info[36] = "";
info[37] = "";
info[38] = "";
info[39] = "";
info[40] = "";
info[41] = "";
info[42] = "";
info[43] = "";
info[44] = "";
info[45] = "";
info[46] = "";
info[47] = "";
info[48] = "";
info[49] = "";
info[50] = "";
info[51] = "";
info[52] = "";
info[53] = "";
info[54] = "";
info[55] = "";
info[56] = "";
info[57] = "";
info[58] = "";
info[59] = "";
info[60] = "";
info[61] = "";
info[62] = "";
info[63] = "";
info[64] = "";
info[65] = "";
info[66] = "";
info[67] = "";
info[68] = "";
info[69] = "";
info[70] = "";
info[71] = "";
info[72] = "";
info[73] = "";
info[74] = "";
info[75] = "";
info[76] = "";
info[77] = "";
info[78] = "";
info[79] = "";
info[80] = "";
info[81] = "";
info[82] = "";
info[83] = "";
info[84] = "";
info[85] = "";
info[86] = "";
info[87] = "";
info[88] = "";
info[89] = "";
info[90] = "";
info[91] = "";
info[92] = "Versilia";
info[93] = "Parco delle Alpi Apuane";
info[94] = "Veduta aerea di Lucca";
info[95] = "Le mura di Lucca";
info[96] = "Villa Grabau";
info[97] = "Villa Reale";
info[98] = "Barga";
info[99] = "Ponte del Diavolo";
info[100] = "Piazza dell'Anfiteatro, Lucca";

function getPageCoords (element) { // thanks to 'Martin Honnen' for this function 
	var coords = {x: 0, y: 0}; 
	while (element) { 
		coords.x += element.offsetLeft; 
		coords.y += element.offsetTop; 
		element = element.offsetParent; 
	} 
	return coords; 
}
function getMousePosition(e) {
        var IE = document.all?true:false;
        if ( IE ) { // grab the x-y pos.s if browser is IE
                tempX = event.clientX + document.body.scrollLeft;
                tempY = event.clientY + document.body.scrollTop;
        } else {  // grab the x-y pos.s if browser is NS
                tempX = e.pageX;
                tempY = e.pageY;
        }
        asse_x = tempX;
        asse_y = tempY;
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function f_scrollTop() {
        return f_filterResults (
                window.pageYOffset ? window.pageYOffset : 0,
                document.documentElement ? document.documentElement.scrollTop : 0,
                document.body ? document.body.scrollTop : 0
        );
}

function calcolaid(num){
	if((number + num) < 1){
		return (100 + number + num);
	}
	else if((number + num) > 100){
		return (number + num - 100);
	}
	else {
		return (number + num);
	}
}
function previous(num){
  if (document.images){
	  	number = calcolaid(-num);
     	aggiornaImages();
   }
}
function next(num){
  if (document.images){
	  	number = calcolaid(num);
	 }
     aggiornaImages();
}
function visualizza(num){
	if (document.images){
	  	number = num;
	}
     aggiornaImages();
}
function controllatasto(){
var tasto = window.event.keyCode;
if(tasto == 37){
	previous(1);
}
else if(tasto == 39){
	next(1);
}
}
function loaded(i){
	document.getElementById("load" + i).style.visibility = "hidden";
	document.getElementById("slide" + i).style.visibility = "visible";
}
function aggiornaImages(){

document.images.slides.style.visibility = "hidden";
document.getElementById("loadbig").style.visibility = "visible";
document.images.slides.src  = "photos/big/big-" + number + ".jpg";
//if (document.getElementById("text2")){
//document.getElementById("text2").innerHTML(info[number-1]);
//document.getElementById("text2").style.visibility = "visible";
//document.getElementById("text2").style.zIndex = 1;
//}
}

var velocita = 0;
var mousex;
var bonus = 0;
if(navigator.appName == "Microsoft Internet Explorer"){
	bonus = 20;
}
function spostaBarra(){
	


if((f_scrollTop() + asse_y >=  getPageCoords(document.getElementById("thumbs")).y) && (f_scrollTop() + asse_y <= getPageCoords(document.getElementById("thumbs")).y) + document.getElementById("thumbs").offsetHeight){
mousex = asse_x;
dimbarra = document.documentElement.scrollWidth;
var fattore = 5;
var tasso = (mousex - (dimbarra/2));
velocita =  (- (tasso) / fattore);
	}
else {
	velocita = 0;
}

}



var h = -80;

function fermaBarra(){
	velocita = 0;
}
var i = 0;

function updateBar(){
	if((f_scrollTop() + asse_y >=  getPageCoords(document.getElementById("thumbs")).y)){
		var d;
		if(!document.getElementById("thumbs")){ d = 81; }
		else { d = document.getElementById("thumbs").offsetHeight; }
		if(h > -d + 10){
			h = h - 10;
			document.getElementById("menu").style.backgroundColor = "#222";
			document.getElementById("text").style.visibility = "hidden";
		}

	}
	else {
		if(h < -17){
			h = h + 5;
		}
		else {
			document.getElementById("menu").style.backgroundColor = "#ccc";
			document.getElementById("text").style.top = document.documentElement.scrollHeight -41 +"px";
			document.getElementById("text").style.zIndex ="1";
			document.getElementById("text").style.visibility = "visible";
			
		}
	}
	
	//posizionamento verticale
	if(document.getElementById("thumbs")){
	document.getElementById("thumbs").style.top = f_scrollTop() + document.documentElement.scrollHeight + h + "px";
	
	spostaBarra();
	//posizionamento orizzontale
	var valx = getPageCoords(document.getElementById("thumbs")).x;
	if(velocita > 0){
		if(!(eval((valx + velocita)) > -30)){
			document.getElementById("thumbs").style.left = eval((valx + velocita)) + "px";
		}
		else {
			document.getElementById("thumbs").style.left = "-30px";
		}
	}
	else if(velocita < 0){
		if(!(eval((valx + size + velocita)) < (dimbarra + 30))){
			document.getElementById("thumbs").style.left =  eval((valx + velocita)) + "px";
		}
		else {
			document.getElementById("thumbs").style.left = eval(dimbarra - size + 30) + "px";
		}
	}
	
	}

}
setInterval('updateBar()',100);
