//preload immagini
function preloadIMG(){	
	var images = document.getElementsByTagName('img');
	var immagini=new Array();	
	var cont = 0;
	
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++){
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
	
		//se hanno match preload... associo funzioni di preload
		if (relAttribute.toLowerCase().match('preload')){
			immagini[cont]=new Image();
			immagini[cont].src=image.src;
			cont++;
		}
	}
}

// Over delle immagini <img src=""..>
function attachSwitch(){	
	var images = document.getElementsByTagName('img');
	
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++){
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
		
		//se hanno match over... associo funzioni di swap img
		if (relAttribute.toLowerCase().match('over')){
			image.onmouseover = function(){
				if(this.className!="active"){
					this.src= this.src.replace('_off', '_on');	
				}
			};
			image.onmouseout = function(){
				if(this.className!="active"){
					this.src= this.src.replace('_on', '_off');	
				}
			};			
		}
		if(image.className == "active") image.src= image.src.replace('_off', '_on');
	}
}

// Over del menu
function startMenu() {
	var node;
	var displaymenu;
	
	displaymenu = document.getElementById("menu");
	for (i=0; i<displaymenu.childNodes.length; i++) {
		node = displaymenu.childNodes[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {this.className+=" over";}
			node.onmouseout=function() {this.className=this.className.replace("over", "")}
		}
	}
}


/************************************************************************************************************************/
//	CALCOLO DELL'ALTEZZA DEL MAIN (INIZIO FUNZIONI)
var head;
var container;
var colonnaSx;
var colonnaDx;
var footer;
//	Altezza dell'head
function headHeight(){
	
	head = document.getElementById('head');
	head.style.height  = head.offsetHeight + 'px';
}

function containerHeight(){
	
	container = document.getElementById('container');
	container.style.height  = container.offsetHeight + 'px';
}

function colonnaSxHeight(){
	
	colonnaSx = document.getElementById('colonnaSx');	
	colonnaSx.style.height  = colonnaSx.offsetHeight + 'px';
}

function colonnaDxHeight(){
	
	colonnaDx = document.getElementById('colonnaDx');
	colonnaDx.style.height  = colonnaDx.offsetHeight + 'px';
}

function footerHeight(){
	
	footer = document.getElementById('footer');
	footer.style.height  = footer.offsetHeight + 'px';
}

//	Richiamando le altre funzioni calcolo al volo l'altezza del main
function mainHeight(){
	var main;
	var heightTotale;
	
	main = document.getElementById('main');
	
	// richiamo le funzioni precedenti
	headHeight();
	colonnaSxHeight();
	containerHeight();
//	colonnaDxHeight();
	footerHeight();
	
//	questa quando il layout è a tre colonne	
//	heightTotale = Math.max(colonnaSx.offsetHeight,Math.max(colonnaDx.offsetHeight,container.offsetHeight)) + head.offsetHeight + footer.offsetHeight;

//	questa quando il layout è a due colonne
	heightTotale = Math.max(colonnaSx.offsetHeight,container.offsetHeight) + head.offsetHeight + footer.offsetHeight;
	main.style.height = heightTotale + 'px';
}

//	CALCOLO DELL'ALTEZZA DEL MAIN (FINE FUNZIONI)
/***************************************************************************************************************************/

//	Corregge la visualizzazione dei PNG in explorer
function correctPNG() {
	for(var i=0; i<document.images.length; i++){
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText ;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;     
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='crops');\"></span>";
			img.outerHTML = strNewHTML;
			i = i-1;
		}
	}
}





// Richiamo delle funzioni precedenti in un unica funzione
function allFunctions() {
	var loading = document.getElementById('page_loading');		
	var main = document.getElementById('main');
	//main.style.visibility="hidden";
	
	
	
	preloadIMG();
	attachSwitch();
//	startMenu();
	mainHeight();
	if(navigator.userAgent.match('MSIE')) correctPNG();
	
	loading.style.display="none";	
	//main.style.visibility="visible";		
	
}