// JavaScript Document
var timeout_real;
var delayPicDesc=0;
var timeoutImage;
var array_ban="";
var checked=false;


window.onload = onloade;

function onloade() 
{
	if($('id_ban'))
	{
		var id_ban = $('id_ban').value;
		timeoutImage = setTimeout("swapImageHomer("+id_ban+",1)", 7500);
	}
	
	if($('left') && $('right'))
	{
		if($('left').offsetHeight > $('right').offsetHeight)
		{
			$('right').style.height=($('left').offsetHeight-103)+'px';
		}
		else
		{
			if($('left').offsetHeight < $('right').offsetHeight)
			{
				$('left').style.height=($('right').offsetHeight-14)+'px';
			}
		}
		
	}
	
	if (document.all&&document.getElementById)
	{
		navRoot = document.getElementById("menuPrincipale");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function() {
					this.className+=" hover";
		  		}
				
		  		node.onmouseout=function() {
		  			this.className=this.className.replace(" hover", "");
		   		}
			}
		}
	}
}

function show_real_desc()
{
	if($('desc_real'))
	{
		if(timeout_real)
			clearTimeout(timeout_real);
		
		$('desc_real').style.height = "auto";
		
		if($('desc_real').style.display == "none")
			timeout_real=setTimeout("show_real_desc_next()",delayPicDesc); 
		else
			return;
	}
}
function show_real_desc_next()
{
	if($('desc_real'))
	{
		if($('desc_real').style.display == "none")
		{
			Effect.BlindDown('desc_real', {duration: 0.4});
			delayPicDesc=400;
		}
		else
			delayPicDesc=0;
	}
	else
		delayPicDesc=0;
}

function hide_real_desc()
{
	if($('desc_real'))
	{
		if(timeout_real)
			clearTimeout(timeout_real);
		
		timeout_real=setTimeout("hide_real_desc_next()",400);
	}
}
function hide_real_desc_next()
{
	if($('desc_real'))
	{
		Effect.BlindUp('desc_real', {duration: 0.4});
		delayPicDesc=400;
	}
	else
		delayPicDesc=0;
}





function resizeBox(width,height)
{
	var oldWidth = $('bigImage').offsetWidth;
	if(oldWidth=="")
		oldWidth=640;
	
	var oldHeight = $('bigImage').offsetHeight;
	if(oldHeight=="")
		oldHeight=480;
	
	
	
	
	var xScale = (width / oldWidth) * 100;
	var yScale = (height / oldHeight) * 100;
	
	var wDiff = (oldWidth - width)-2;
	var hDiff = (oldHeight - height)-2;
	
	var time = 0;
	
	
	if (hDiff != 0)
	{
		new Effect.Scale('bigImage', yScale, {scaleX: false, scaleContent: false, duration: 0.7});
		var delays=0.7;
		time = 0.7
	}
	else
		var delays=0;
	
	if (wDiff != 0)
	{
		time=time+0.7;
		new Effect.Scale('bigImage', xScale, {scaleY: false, scaleContent: false, duration: 0.7, delay: delays});
		new Effect.Scale('helpInfoPic', xScale, {scaleY: false, scaleContent: false, duration: 0.7, delay: delays});
	}
	
	return time
}


function finishSwapImage(text)
{
	$('bigImageHere').style.display = "block";
	$('loading_image').style.display = "none";
}


function lightbox2(section,id)
{
	var objBody = $$('body')[0];
	if($('mylightbox') == null || $('lightbox') == 'undefined')
	{
		objBody.appendChild(Builder.node('div',{id:'myoverlay'}));
		objBody.appendChild(Builder.node('div',{id:'mylightbox'}));
	}
	
	getCtn(section,id);
	
	
	var arrayPageScroll = document.viewport.getScrollOffsets();
	var lightboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	$('mylightbox').setStyle({ top: lightboxTop + 'px' });
	
	$('myoverlay').hide().observe('click', (function() { end(); }).bind($('myoverlay')));
	var arrayPageSize = getPageSize();
	$('myoverlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	new Effect.Appear($('myoverlay'), { duration: 0.7, from: 0.0, to: 0.8 });
	new Effect.Appear($('mylightbox'), { duration: 0.7, from: 0.0, to: 1 });
}

function end()
{
	new Effect.Fade($('mylightbox'), { duration: 0.7 });
	new Effect.Fade($('myoverlay'), { duration: 0.7 });
}

function getPageSize() {
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}


function swapImageHomer(nb,where)
{
	if(timeoutImage)
		clearTimeout(timeoutImage);
	
	if(where > (nb-1))
	{
		where=0;
	}
	
	next=where+1;
	if(next > (nb-1))
	{
		next=0;
	}
	
	prev=where-1;
	if(prev < 0)
	{
		prev=nb-1;
	}
	
	margin=where*655;
	$('bigImageHere').morph('margin-left:-'+margin+'px;');
	$('btn_prev_homer').innerHTML = "<a href='javascript:;' onclick='javascript:swapImageHomer("+nb+","+prev+"); javscript:return false;'>&laquo;</a>";
	$('btn_next_homer').innerHTML = "<a href='javascript:;' onclick='javascript:swapImageHomer("+nb+","+next+"); javscript:return false;'>&raquo;</a>";
	
	timeoutImage = setTimeout("swapImageHomer("+nb+","+next+")", 7500);
}


function trim (str, charlist)
{ 
    var whitespace, l = 0, i = 0;
    str += '';
    
    if (!charlist) {
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    }
    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }
    
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}