// JavaScript Document
function eventBckRollHover(id){
	var sfEls = $(id).getElementsByTagName("A");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {	
			if (this.className.search("bckRollOver")>=0){
				if (this.style.backgroundImage.search("jpg")>=0){
					this.style.backgroundImage=this.style.backgroundImage.replace('.jpg','_a.jpg');
				}else{
					this.style.backgroundImage=this.style.backgroundImage.replace('.gif','_a.gif');
				}
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className.search("bckRollOver")>=0){
				if (this.style.backgroundImage.search("jpg")>=0){
					this.style.backgroundImage=this.style.backgroundImage.replace('_a.jpg','.jpg');
				}else{
					this.style.backgroundImage=this.style.backgroundImage.replace('_a.gif','.gif');
				}
			}
		}
	}
}

function eventRollHover(id,tag){
	var sfEls = $(id).getElementsByTagName(tag);
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {	
			if (this.className.search("rollOver")>=0){
				if (this.src.search("jpg")>=0){
					this.src=this.src.replace('.jpg','_a.jpg');
				}else{
					this.src=this.src.replace('.gif','_a.gif');
				}
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className.search("rollOver")>=0){
				if (this.src.search("jpg")>=0){
					this.src=this.src.replace('_a.jpg','.jpg');
				}else{
					this.src=this.src.replace('_a.gif','.gif');
				}
			}
		}
	}
}

function eventARollHover(id){
	var sfEls = $(id).getElementsByTagName("A");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {	
			if (this.className.search("aRollOver")>=0){
				var sfElsImg = this.getElementsByTagName("IMG");
				for (var j=0; j<sfElsImg.length; j++) {					
					if (sfElsImg[j].src.search("jpg")>=0){
						sfElsImg[j].src=sfElsImg[j].src.replace('.jpg','_a.jpg');
					}else{
						sfElsImg[j].src=sfElsImg[j].src.replace('.gif','_a.gif');
					}
				}
				var sfElsSpan = this.getElementsByTagName("SPAN");
				for (var j=0; j<sfElsSpan.length; j++) {
					sfElsSpan[j].style.color='#0074bb';
				}
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className.search("aRollOver")>=0){
				var sfElsImg = this.getElementsByTagName("IMG");
				for (var j=0; j<sfElsImg.length; j++) {					
					if (sfElsImg[j].src.search("jpg")>=0){
						sfElsImg[j].src=sfElsImg[j].src.replace('_a.jpg','.jpg');
					}else{
						sfElsImg[j].src=sfElsImg[j].src.replace('_a.gif','.gif');
					}
				}
				var sfElsSpan = this.getElementsByTagName("SPAN");
				for (var j=0; j<sfElsSpan.length; j++) {
					if (sfElsSpan[j].className=='rosso') sfElsSpan[j].style.color='#d30d04'; 
					else sfElsSpan[j].style.color='#525357';
				}
			}
		}
	}
}

function Right(str, n){
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}
	
var totalfaq=0;

function setToggle(id,image,bck) {
	
	var sfEls = document.getElementById(id).getElementsByTagName("DIV");
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id.substring(0,4)=="main") totalfaq++;
	}	
							
	for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
	}
	
	//window.addEvent('domready', function() {
		for (var i=1;i<=totalfaq;i++){
			 eval("slide"+i+".hide();");
		}
	//});
	
	for (var i=1;i<=totalfaq;i++){
		$('toggle'+i).addEvent('click',function(e){
			i=parseInt(Right(this.id,2));
			if (isNaN(i)) i=parseInt(Right(this.id,1));									
			e = new Event(e);
			eval("slide"+i+".toggle();");
			e.stop();
			if (image)
				if (Right($('img'+i).src,7)=='piu.gif'){ 
					$('img'+i).src=$('img'+i).src.replace('piu.gif','meno.gif');
					//$('section'+i).style.visibility='hidden';
					//$('main'+i).style.background='#f4eef8';
					if (bck) { $('toggle'+i).style.background='#f2f2f2'; $('toggle'+i).style.borderBottom='none'; }
				}else {
					$('img'+i).src=$('img'+i).src.replace('meno.gif','piu.gif');
					//$('section'+i).style.visibility='visible';
					if (bck) { $('toggle'+i).style.background='#e6f5fa'; $('toggle'+i).style.borderBottom='1px solid #e4e4e4'; }
				}
		});
	}
		
	for (var i=1;i<=totalfaq;i++){
		eval("slide"+i+".addEvent('complete', function() { i=Right(this.id,2); if (isNaN(i)) i=parseInt(Right(this.id,1)); });"); 
		//if (!slide"+i+".open) $('main"+i+"').style.background='#ffffff';
	}
}

function Apri(){
	for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
		if ($('img'+i)) $('img'+i).src=$('img'+i).src.replace('piu.gif','meno.gif');
		eval("slide"+i+".show();");
		//$('main'+i).style.background='#f4eef8';
	}
}

function Chiudi(){
	for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
		if ($('img'+i)) $('img'+i).src=$('img'+i).src.replace('meno.gif','piu.gif');
		eval("slide"+i+".hide();");
		//$('main'+i).style.background='#ffffff';
	}
}

function ApriScheda(i){
	//for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
		if ($('img'+i)) $('img'+i).src=$('img'+i).src.replace('piu.gif','meno.gif');
		eval("slide"+i+".show();");
		//$('main'+i).style.background='#f4eef8';
	//}
}

function Resize() {	
	if (window.getWidth() > 994) {		
		if ($('BaseMenu')) $('BaseMenu').style.backgroundPosition="center top";
		if ($('BaseMenu')) $('BaseMenu').style.width="100%";
	}else{
		if ($('BaseMenu')) $('BaseMenu').style.backgroundPosition="-53px 0px";
		if ($('BaseMenu')) $('BaseMenu').style.width="994px";
	}
	//top = 874
	var altezzaBck = 1976;
	var top = window.getHeight();	
	if (top < altezzaBck){		
		if (altezzaBck - top > top) {
			document.body.style.backgroundPosition="center -"+top+"px";	
		} else {	
			top = altezzaBck - top;
			document.body.style.backgroundPosition="center -"+top+"px";	
		}
	}
}

/*
window.addEvent('domready', function() {
	Resize();
});
window.addEvent('resize', function() {
	Resize();
});
*/
/*
window.addEvent('resize', Resize());
window.addEvent('domready', Resize());
*/

function dettImg(){	
	var el = $('containerbig');		
	var duration=0;
	var transition = Fx.Transitions.Sine.easeOut;
	var myEffect = new Fx.Morph(el, {duration: duration, transition: transition});
	var sfEls = $('advlistscroll').getElementsByTagName("A");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {	
			$('big').src=this.href;
			myEffect.start({
				'opacity': [0, 1],
				'display': 'block'
			});	
		}
		sfEls[i].onmouseout=function() {
			myEffect.start({
				'opacity': [1, 0],
				'display': 'none'
			});	
		}
	}	
}


function cartoline(href){	
	var el = $('containercartolina');		
	var duration=800;
	var transition = Fx.Transitions.Sine.easeOut;
	var myEffect = new Fx.Morph(el, {duration: duration, transition: transition});
	$('imgcartolina').src=href;
	myEffect.start({
		'opacity': [0, 1]
	});	
	$('cartolina').value=href;
}


function photogallery(href){
	$('show').style.display='none';	
	var el = $('containerfirst');		
	var duration=800;
	var transition = Fx.Transitions.Sine.easeOut;
	var myEffect = new Fx.Morph(el, {duration: duration, transition: transition});
	$('first').src=href;
	myEffect.start({
		'opacity': [0, 1],
		'display': 'block'
	});	
}
