function BrowserDetector() // v2.0 by marco
{
	var agent = navigator.userAgent.toLowerCase();
		
	//definizione delle variabili di detection del browser
	this.ie4  = (document.all && !window.opera ? true : false);
	this.ie5  = (document.all && !document.fireEvent && !window.opera ? true : false);
	this.mac5 = (document.all && document.getElementById && !document.mimeType && !window.opera);
	this.ie55 = (document.all && document.fireEvent && !document.createComment ? true : false);
	this.ie6  = (document.all && document.fireEvent && document.createComment && (typeof(window.XMLHttpRequest) == "undefined") ? true : false);
	this.ie7  = (document.all && document.fireEvent && document.createComment && (typeof(window.XMLHttpRequest) == "object") ? true : false);
	this.ie   = this.ie4 || this.ie5 || this.ie55 || this.ie6;
	
	this.op  = (agent.indexOf("opera") != -1);
	this.op2 = (agent.indexOf("opera 2") != -1 || agent.indexOf("opera/2") != -1);
    this.op3 = (agent.indexOf("opera 3") != -1 || agent.indexOf("opera/3") != -1);
    this.op4 = (agent.indexOf("opera 4") != -1 || agent.indexOf("opera/4") != -1);
	this.op6 = (agent.indexOf("opera 6") != -1 || agent.indexOf("opera/6") != -1); 
	this.op5 = (agent.indexOf("opera 5") != -1 || agent.indexOf("opera/5") != -1);
	this.op7 = (agent.indexOf("opera 7") != -1 || agent.indexOf("opera/7") != -1);
    this.op8 = (agent.indexOf("opera 8") != -1 || agent.indexOf("opera/8") != -1);
    this.op9 = (agent.indexOf("opera 9") != -1 || agent.indexOf("opera/9") != -1);
	this.op5up = (this.op && !this.op2 && !this.op3 && !this.op4);
    this.op6up = (this.op && !this.op2 && !this.op3 && !this.op4 && !this.op5); 
    this.op7up = (this.op && !this.op2 && !this.op3 && !this.op4 && !this.op5 && !this.op6); 
    this.op8up = (this.op && !this.op2 && !this.op3 && !this.op4 && !this.op5 && !this.op6 && !this.op7); 
	this.op9up = (this.op && !this.op2 && !this.op3 && !this.op4 && !this.op5 && !this.op6 && !this.op7 &&!this.op8);
	
	this.ns4  = (document.layers ? true : false);
	this.ns6  = (!document.all && !window.opera && document.getElementById ? true : false);
	this.ns   = this.ns6 || this.ns4;
}
BrowserDetector.prototype = new BrowserDetector;

function DHTMenu()	//gestisce un menu dinamico a cascata fatto con ul / li
{
	var showClass = "show";			//classe che visualizza il menu nascosto
	var linkClass = "true";			//classe da applicare al link che è stato aperto
	var pathList = new Array();		//contiene l'elenco dei path abilitati ad utilizzare il menu dhtml
	var cssPath = new Array();		//contiene i path ai css da aggiungere
				
	function menu()		//questa funzione viene applicata all'evento onclick del link sensibile
	{
		this.open = !this.open;
		
		if(this.open == true)
		{
			this.parentNode.memoClass = this.parentNode.className;
			this.memoClass = this.className
			this.parentNode.className += " " + showClass;
			this.className += " " + linkClass;
		}
		else
		{
			this.parentNode.className = this.parentNode.memoClass;
			this.className = this.memoClass;
		}
	}
	
	this.init = function()
	{
		var path = location.pathname;
		var sectionEnabled = -1;
		var cnt = 0;
		
		while (cnt < pathList.length && sectionEnabled == -1)
		{
			var tmpEx = new RegExp(pathList[cnt].path,"i");
			if ( tmpEx.test(path) ) sectionEnabled = cnt;
			cnt++;
		}
		
		if (sectionEnabled > -1)
		{
			var labels = pathList[sectionEnabled].label.split(",");
			for(q=0; q < labels.length; q++)
			{
				document.write('<link href="../../_js/' + cssPath[labels[q]] + '" rel="stylesheet" type="text/css" />');
			}
		}
	}
	
	this.enablePath = function(path, label)
	{
		var pathInfo = new Object();
		
		path = path.replace("\*", ".*");
		
		pathInfo.path = "^" + path + "$";
		pathInfo.label = label;
		
		pathList[pathList.length] =  pathInfo;
	}
	
	this.setCssPath = function(css, label)
	{
		cssPath[label] = css;
	}
	
	this.setShowClass = function(name)		//imposta la classe di visualizzazione dell'elemento nascosto se diversa dal default
	{
		showClass = name
	}
	
	this.setLinkClass = function(name)		//imposta la classe del link cliccato se diversa dal default
	{
		linkClass = name;	
	}
	
	this.enable = function (id, title)				//abilita i link alla visualizzazione dell'elemento nascosto
	{
		var sensibleLinkFilter = new AttributeEqualsFilter("href", "javascript:menu()");	//filtra gli elementi con l'attributo specificato
		var sensibleLinks = document.dom.getChildElements ("a", document.getElementById(id), true, sensibleLinkFilter);	//estrae gli elementi 'a' dal contenitore usando il filltro 
		for (q=0; q < sensibleLinks.length; q++)	//modifica gli elementi 'a' per renderli attivi 
		{
			sensibleLinks[q].href = "javascript:foo()";
			sensibleLinks[q].onclick = menu;
			sensibleLinks[q].open = false;
			if (title != null) sensibleLinks[q].title = title;
		}
	}
}
DHTMenu.prototype = new DHTMenu;

function PageScroller()
{
	var pageHeight;
	var browserHeight;
	var scrollPosition;
	var stepSize;
	var position = 0;
	var enabled;
	
	var fx = new Fx.Scroll( window, 
	{
		wait: false,
		duration: 1000,
		transition: Fx.Transitions.Quad.easeOut
	});
	
	this.down = function()
	{
		this.calc();
		if (enabled && position < pageHeight)
		{
			position += stepSize;
			fx.scrollTo(0, position);
		}
	}
	
	this.up = function()
	{
		this.calc();
		if (enabled && position >= 0)
		{
			position -= stepSize;
			fx.scrollTo(0, position)
		}
	}
	
	this.calc = function()
	{
		pageHeight = 	window.getScrollHeight(); //$('bkg').getSize().scrollSize.y;
		browserHeight = window.getHeight();
		position = window.getScrollTop();
		stepSize = Math.round(browserHeight / 10 * 9);
		enabled = (pageHeight > browserHeight ? true : false);
		//alert(pageHeight + " "  + browserHeight )
	}
}
PageScroller.prototype = new PageScroller;

/*** mootools extensions ***/


var TipsWrapper = Tips.extend(
{
	build: function(el)
	{
		el.$tmp.myTitle = (el.href && el.getTag() == 'a') ? el.href.replace('http://', '') : (el.rel || false);
		
		var frase = " per salvarlo fare click con il tasto destro del mouse e scegliere 'Salva oggetto con nome...'<br/>";
		if (el.href.match('.pdf$')) el.setProperty('title', "Documento PDF :: " + el.title + frase);
		else if (el.href.match('.doc$')) el.setProperty('title', "Documento Word :: " + el.title + frase);
		else if (el.href.match('.rtf$')) el.setProperty('title', "Documento Word :: " + el.title + frase);
		else if (el.href.match('.xls$')) el.setProperty('title', "Documento Excel :: " + el.title + frase);
		else if (el.href.match('.zip$')) el.setProperty('title', "File Compresso :: " + el.title + frase);
		
		if( el.target == "_blank" )
		{
			var titolo = (el.title == '' ? "" : el.title + "<br/>");
			el.setProperty('title', 'Link esterno :: ' + titolo);
			el.title += '<i>si apre in una nuova finestra</i>';
		}
		
		if (el.title)
		 {
			var dual = el.title.split('::');
			if (dual.length > 1){
				el.$tmp.myTitle = dual[0].trim();
				el.$tmp.myText = dual[1].trim().replace(/\|/gi, "<br/>");
			} else {
				el.$tmp.myText = el.title;
			}
			el.removeAttribute('title');
		} else {
			el.$tmp.myText = false;
		}
		if (el.$tmp.myTitle && el.$tmp.myTitle.length > this.options.maxTitleChars) el.$tmp.myTitle = el.$tmp.myTitle.substr(0, this.options.maxTitleChars - 1) + "&hellip;";
		el.addEvent('mouseenter', function(event){
			this.start(el);
			if (!this.options.fixed) this.locate(event);
			else this.position(el);
		}.bind(this));
		if (!this.options.fixed) el.addEvent('mousemove', this.locate.bindWithEvent(this));
		var end = this.end.bind(this);
		el.addEvent('mouseleave', end);
		el.addEvent('trash', end);
	}	
});


