// ====================================================================================
// ============ Altre funzioni specifiche di pubbli negolo ============================

function OpenPnlImg(foto) {
    page = "/Sito/PopImgZoom.aspx?foto=" + foto;
    info = "width=640,height=500,menubar=no,scrollbars=yes,resizable=yes";
    window.open(page, "", info);
}

// ==================================================================================== 
// ======================== cangiamenti del menu laterale dx ==========================
// ==================================================================================== 

// settaggio variabili di controllo
var stato_menu = "chiudi";

function start_menu(){
	if(stato_menu == "chiudi"){
		
		stato_menu = "apri"
		
		document.getElementById("menu_control").innerHTML = "show menu";
		document.getElementById("menu_control").style.background = "url(img/skip.png) no-repeat right bottom";
		
		var hideMenu = new Fx.Style('menu', 'height', {
		duration: 300,
		transition: Fx.Transitions.Quart.easeInOut
		});
		
		hideMenu.start(190,0);
		
	}
	else{
		
		stato_menu = "chiudi"
		
		document.getElementById("menu_control").innerHTML = "hide menu";
		document.getElementById("menu_control").style.background = "url(img/skip.png) no-repeat right top";
		
		var hideMenu = new Fx.Style('menu', 'height', {
		duration: 300,
		transition: Fx.Transitions.Quart.easeInOut
		});
		
		hideMenu.start(0,190);

	}
}

// ==================================================================================== 
// ================ rende "fixed" il menu laterale dx con un hack =====================
// ==================================================================================== 

// var globali che uso per la gestione dello scroll 
var the_timeout;
var the_timepassed = 0;


// parte il timer all'onscroll
window.onscroll = function(){
	// per non creare troppo timer sego a ogni onscroll quello lanciato in precedenza 
	clearTimeout(the_timeout);
	// e azzero il tempo passato
	the_timepassed = 0;
	upDate();
} 


// timer - se dall'ultimo onscroll è passato tot tempo il menu comincia a muoversi
function upDate()
{
	// opero sulla variabile globale		
	the_timepassed = parseInt(the_timepassed) + 10;
	// document.title = the_timepassed;
	// TEMPO Dopo il quale parte l'effetto.
	if(the_timepassed < 80){
		the_timeout = setTimeout("upDate();", 10)
	}
	else{
		makeItScroll();
	}
	
	
}

// funzione che implementa il movimento del menu dx
function makeItScroll(){
	var menu = document.getElementById("menu");
	var hpage = $('TempoTrascorso').getPosition().y + 10; // approssimativamente

	if ((hpage > 1200) && (menu.style.position == "")) {
		menu.style.position = "absolute";
		menu.style.top = "130px";
	}
	
	if (menu.style.position == "absolute") {
		var follow = new Fx.Style('menu', 'top', {
			duration: 400,
			transition: Fx.Transitions.Quart.easeInOut
		});

		var dtop = window.getScrollTop();
		var hwin = window.getHeight();
		var hmenu = $('menu').getSize().size.y;		
		var maxypos = $('FootTable').getPosition().y - hmenu - 10;
				
		var newypos = dtop + 10; 
		if (newypos < 130) { newypos = 130; }

		if (dtop > maxypos) { newypos = maxypos; }

		// Nel caso la viewport del browser sia troppo bassa blocco
		// lo scrolling
		if (hwin < 650) { newypos = 130; }
		
		// alert (dtop + ' ' + maxypos + ' ' + newypos);

		follow.start(menu.style.top, newypos);
		
		// alert(document.body.clientWidth); funzione js
		// alert(window.getWidth()); funzione mootools	

		// var footer = document.getElementById("FootTable");
		// alert ($(footer).getPosition().x);
		// alert ($('FootTable').getPosition().x);
	}
}

