function getPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	curleft += obj.x;
	return curleft;
}


var framerate = 50; // frames/second
var duration = 1/2; // seconds
var id;
var startPos;
var endPos;
var currentStep = 0;
var steps = Math.ceil(framerate * duration);
var lastCall = 0;

function initMove(pos){
	if(lastCall == pos) return false;
	startPos = Number(document.getElementById('p').style.marginLeft.replace("px",""));
	if (pos == startPos) return false;
	
	window.clearTimeout(id);
	currentStep = 0;
	endPos = pos;
	lastCall = pos;
	move();
}

function eq(){
	val = (endPos-startPos)/steps/steps*currentStep*currentStep + startPos;
	return val;
}

function move(){
	currentStep++;
	spos = Math.ceil(eq());	
	if(currentStep<steps && Math.abs(spos-endPos)>2){		
		document.getElementById('p').style.marginLeft = spos+"px";
		//document.getElementById('scuro').style.background = "url(/esempioMenu/img/Banner_Scuro.jpg) -"+spos+"px";
		id = setTimeout("move()", Math.ceil(1000 / framerate));
	}else{
		document.getElementById('p').style.marginLeft = endPos+"px";
		//document.getElementById('scuro').style.background = "url(/esempioMenu/img/Banner_Scuro.jpg) -"+endPos+"px";
	}
	

}

function mytime() {
	var x=new Date();
	h=x.getHours();
	m=x.getMinutes();
	s=x.getSeconds();
	if(s<=9) s="0"+s;
	if(m<=9) m="0"+m;
	if(h<=9) h="0"+h;
	time=h+":"+m+":"+s;
	document.rclock.rtime.value=time;
	setTimeout("mytime()",1000); 
}

function viewMex(mex){
	dTop = document.body.scrollTop+200;
	document.getElementById('loader').innerHTML = "<img src=\"admin/img/progress.gif\" style=\"vertical-align: -13px\">&nbsp;&nbsp;"+mex;
	document.getElementById('loader').style.top = dTop+"px";
	document.getElementById('loader').style.display = "block";
}

function hideMex(cont,dbg){
	if(dbg){
		document.getElementById('loader').innerHTML = cont;
	}else{
		document.getElementById('loader').style.display = "none";
		document.getElementById('loader').innerHTML = "";
	}	
}

function setPage(cmd){
	viewMex("Caricamento in corso...");
	ajaxGetRand("?cmd="+cmd,myHandler);
	function myHandler(aa){
		document.getElementById('asd').innerHTML = aa;
		hideMex(aa,0);
	}
}

function viewFoto(img){
	imgHtml = "<img src='"+img+"'>";
	divHtml = "<div class='ff'><a href='javascript://'><b>CHIUDI X</b></a></div>";
	dTop = document.body.scrollTop + 70;
	x = getPosX(document.getElementById('add'))-4;
	document.getElementById('fotoG').style.top = dTop+"px";
	document.getElementById('fotoG').style.left = x+"px";
	document.getElementById('fotoG').innerHTML = imgHtml+divHtml;
	document.getElementById('fotoG').style.display = "block";
}

function openBio(id){
	viewMex("Caricamento in corso...");
	ajaxGetRand("?cmd=viewBio&id="+id,myHandler);
	function myHandler(aa){
		divHtml = "<div class='ff'><a href='javascript://'><b>CHIUDI X</b></a></div>";
		dTop = document.body.scrollTop + 70;
		x = getPosX(document.getElementById('add'))-4;
		document.getElementById('bio').style.top = dTop+"px";
		document.getElementById('bio').style.left = x+"px";
		document.getElementById('bio').innerHTML = divHtml+""+aa;
		document.getElementById('bio').style.display = "block";
		hideMex(aa,0);
	}	
}

function selCal(anno,mese){
        viewMex("Caricamento in corso...");
        ajaxGetRand('?cmd=selCal&mese='+mese+'&anno='+anno,myHandler);
        function myHandler(aa){
                win = document.getElementById("calendar");
                win.innerHTML = aa;
                hideMex(aa,0);
        }
}
