
// Questa funzione controlla quale versione di browser sia attiva
// esempio nav = new verificaBrowser();

function verificaBrowser(){ 
    this.ver=navigator.appVersion; 
    this.dom=document.getElementById?1:0; 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
    this.ie4=(document.all && !this.dom)?1:0;
    this.ns5=(this.dom && parseInt(this.ver) >= 5)?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.nav=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
    return this;
} 

nav = new verificaBrowser();
var loop, scrolltimer;
var mouseX, mouseY;

// Questa funzione fornisce un costruttore ad un oggetto (solitamente layer)
// i parametri sono:
// - obj 	= l'id dell'oogetto
// - base 	= serve a specificare la gerarchia
// - nome	= nome della variabile usata come puntatore all'oggetto
//
// esempio L21 = new CostruttoreOggetto('Layer21','','L21');
//dove Layer21 è definito nel BODY come
//<div id="Layer21" style="position:relative; left:0px; top:0px; width:160px; 
// height:125px; z-index:11; visibility: inherit">   
//	  <img src="img/ElencoPresenti.gif" width="160" height="125"> 
//</div>
//
//
 

function Layer(obj,base, name){ 
    base=(!base) ? '':'document.'+base+'.' ;
    
    if (nav.dom)
    	this.el = document.getElementById(obj);
    else
    	{
    	if(nav.ie4)
    		this.el = document.all[obj];
    	else
    		{
    		if(nav.ns4)
    			this.el = eval(base+'document.'+obj);
    		else
    			this.el = 0;
    		} 
    	}
    
    
    if(nav.dom)
    	this.css = document.getElementById(obj).style;
    else
    	{
    	if(nav.ie4)
    		this.css = document.all[obj].style;
    	else
    		{
    		if(nav.ns4)
    			this.css = eval(base+'document.'+obj);
    		else
    			this.css = 0;
    		} 
    	}
    
    
    if (nav.ns4)
    	this.scrollHeight = this.css.document.height
    else
    	this.scrollHeight = this.el.offsetHeight;
    
    
    if(nav.ns4)
    	this.clipHeight = this.css.clip.height
    else
    	this.clipHeight = this.el.offsetHeight;
        
    this.x;
    
    this.y; 
    
    this.name = "" + name;    
    
    this.obj = obj + "Object";
    
    eval(this.obj + "=this");
    
    return this;   
} 

function showlayer(objlayer)
	{
	objlayer.css.visibility='visible';
	}

function hidelayer(objlayer)
	{
	objlayer.css.visibility='hidden';
	}

function setLayerPos(objlayer, x, y)
{
	objlayer.css.left=x;
	objlayer.css.top=y;
}

function getLayerXPos(objlayer)
{
	return objlayer.css.left;
}

function getLayerYPos(objlayer)
{
	objlayer.y=objlayer.css.top;
	y1=parseInt(objlayer.y);
	return y1;
}

function findPosX(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;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function ScrollUp(objlayer, speed, height)
	{
	objlayerStr = "" + objlayer.name;	
	loop=true;
	scrolltimer=null;
	if (loop==true) 
	{
		objlayer.y=objlayer.css.top;
		y1=parseInt(objlayer.y);
		if (y1<height)
			{
//	alert("sup");
			y2 = y1 + speed;
			objlayer.css.top=y2;
			}
		//objlayer.css.left=0;	
		scrolltimer = setTimeout("ScrollUp("+ objlayerStr + ", "+ speed +  ", " + height +")", 50);
		}
	}
		
function ScrollDown(objlayer, speed, height)
	{
	//alert("sdown");
	objlayerStr = "" + objlayer.name;	
	loop=true;
	scrolltimer=null;
	if (loop==true)
	{
		objlayer.y = objlayer.css.top;
		y1 = parseInt(objlayer.y);
		if (y1 > (-1 * height) )
			{
			y2 = y1 - speed;
			objlayer.css.top = y2;
			}
		//objlayer.css.left=0;
		//alert("ScrollDown("+ objlayerStr + ", "+ speed + ", " + height+ ")");
		scrolltimer = setTimeout("ScrollDown("+ objlayerStr + ", "+ speed + ", " + height + ")", 50);
		}
	}

function ScrollRight(objlayer, speed, xorig, width)
	{
	objlayerStr = "" + objlayer.name;	
	loop=true;
	scrolltimer=null;
	if (loop==true) 
	{
		objlayer.y=objlayer.css.left;
		y1=parseInt(objlayer.y);
		delta=y1-xorig;
		if (delta<width)
			{
			y2 = y1 + speed;
			objlayer.css.left=y2;
			}
		//objlayer.css.left=0;	
		scrolltimer = setTimeout("ScrollRight("+ objlayerStr + ", "+ speed + ", "+ xorig + ", " + width + ")", 50);
		}
	}
		
function ScrollLeft(objlayer, speed, xorig, width)
	{
	//alert("sdown");
	objlayerStr = "" + objlayer.name;	
	loop=true;
	scrolltimer=null;
	if (loop==true)
	{
		objlayer.y = objlayer.css.left;
		y1 = parseInt(objlayer.y);
		delta=y1-xorig;
		if (delta < width )
			{
			y2 = y1 - speed;
			objlayer.css.left = y2;
			}
		//objlayer.css.left=0;
		//alert("ScrollDown("+ objlayerStr + ", "+ speed + ", " + height+ ")");
		scrolltimer = setTimeout("ScrollLeft("+ objlayerStr + ", "+ speed + ", "+ xorig + ", " + width + ")", 50);
		}
	}

function ScrollRightUntil(objlayer, speed, width)
	{
	objlayerStr = "" + objlayer.name;	
	loop=true;
	scrolltimer=null;
	if (loop==true) 
	{
		objlayer.y=objlayer.css.left;
		y1=parseInt(objlayer.y);
		if (y1<width)
			{
			y2 = y1 + speed;
			objlayer.css.left=y2;
			}
		//objlayer.css.left=0;	
		scrolltimer = setTimeout("ScrollRightUntil("+ objlayerStr + ", "+ speed + ", " + width + ")", 50);
		}
	}
		
function ScrollLeftUntil(objlayer, speed, width)
	{
	//alert("sdown");
	objlayerStr = "" + objlayer.name;	
	loop=true;
	scrolltimer=null;
	if (loop==true)
	{
		objlayer.y = objlayer.css.left;
		y1 = parseInt(objlayer.y);
		if (y1 > (-1 * width) )
			{
			y2 = y1 - speed;
			objlayer.css.left = y2;
			}
		//objlayer.css.left=0;
		//alert("ScrollDown("+ objlayerStr + ", "+ speed + ", " + height+ ")");
		scrolltimer = setTimeout("ScrollLeftUntil("+ objlayerStr + ", "+ speed + ", " + width + ")", 50);
		}
	}


function stopScroll() 
{
	loop = false;
	clearTimeout(scrolltimer);
}	


/*
function click()
{
	if(((event.button==1) && (event.altKey)) || (event.button==4) || (event.button==2)){
		// funzione	
	}
}

document.onmousedown=click
*/