var altezzina= 194;
var main;
var head;
var colonnaSx;
var container;
var colonnaDx;
var footer;
var heightTotale;

function newAltezza() {
	var mymain=  document.getElementById('main');

	mymain.style.height = mymain.offsetHeight + altezzina + 'px';
	altezzina=-altezzina;	
	clearTimeout();
}
function toggleNewsletter()
{
	if(altezzina < 0)
	{
		
		Effect.toggle('newsletter','slide'); 	
		setTimeout("newAltezza()",900);	
	}
	else
	{
		
		newAltezza();
		Effect.toggle('newsletter','slide'); 	
	}
	return false;
	
}
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';
}

function mainHeight(){
	headHeight();
	colonnaSxHeight();
	containerHeight();
//	colonnaDxHeight();
	footerHeight();
	main = document.getElementById('main');
//	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;
	//+120 x via di google
	main.style.height = heightTotale + 10 + 'px';
/*
	alert('head: ' + head.style.height);
	alert('colonna sinistra: ' + colonnaSx.style.height);
	alert('main: ' + main.style.height);
*/
}



//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++;
		}
	}
}

//	Switch immagini
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 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", "")
			}
		}
	}
}

/*
<!--[if gte IE 5.5000]>
 	<script type="text/javascript" src="pngfix.js"></script>
<![endif]-->
*/

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;
		}
	}
}

function goToLocation(elem){
	if(elem.firstChild)
	window.location.href= elem.firstChild.href;
}

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();
	
	var loading_page = document.getElementById('page_loading');
	loading_page.style.display = 'none';
	main.style.visibility="visible";

}