/*
 * GESTIONE HEADER FLASH
 */
function mainFlash(action) {
	
	var movie       = $('movie').getProperty('title');
	var xmlPath     = $('xmlPath').getProperty('title');
	var autoBooking = $('autoBooking').getProperty('title');
	var overBanner  = $('overBanner').getProperty('title');
	var scale       = $('scale').getProperty('title');
	var wmode       = $('wmode').getProperty('title');
	
	var flashHash = new Hash ({ 'movie': movie
							  , 'oldMovie': movie
							  , 'wait': "/skin/website/swf/wait.swf"
							  , 'xmlPath': xmlPath
							  , 'autoBooking': autoBooking
							  , 'overBanner': overBanner
							  , 'scale': scale
							  , 'wmode': wmode
							  });
	var flashvars = {
					  xmlPath     : flashHash.get('xmlPath')
					, autoBooking : flashHash.get('autoBooking')
					, overBanner  : flashHash.get('overBanner')
					};
	var params = {
					scale : flashHash.get('scale')
				  , wmode : flashHash.get('wmode')
				  };
	var attributes = {};

	function startFlash() {
		if (action == 'close') {
			swfobject.embedSWF(flashHash.get('wait'), "flash", "1000", "341", "9.0.0", "/skin/website/swf/expressInstall.swf", flashvars, params, attributes);
		} else {
			swfobject.embedSWF(flashHash.get('movie'), "flash", "1000", "341", "9.0.0", "/skin/website/swf/expressInstall.swf", flashvars, params, attributes);
	
		}
	};

	startFlash.delay(600);
}

function funFullscreen(){
	
	splashWidth = screen.availWidth;
	splashHeight = screen.availHeight;

	if(splashWidth > 2 * splashHeight){ // Dopppio monitor
		splashWidth = splashWidth / 2; 
	}

	window.resizeTo(splashWidth,splashHeight);
	window.moveTo(0,0);
}

function popupFullScreen(url)
{
	params  = 'width='+screen.availWidth;
	params += ', height='+screen.availHeight;
	params += ', top=0, left=0'
	params += ', fullWindow'
	params += ', fullscreen';
	
	newwin=window.open(url,'popupFS', params);
	if (window.focus) {newwin.focus()}
	return false;
}


function popupNewWindow(url)
{	
	params  = 'width=960'
	params += ', height=600'
	params += ', top=100, left=100'
	params += ', toolbar=1'
	params += ', location=1'
	params += ', directories=1'
	params += ', status=1'
	params += ', menubar=1'
	params += ', scrollbars=1'
	params += ', resizable=1'
	params += ', fullscreen=0'
	;
	newwin=window.open(url,'newwin', params);
	if (window.focus) {newwin.focus()}
	return false;
}

window.addEvent('domready', function() {
	/* GESTIONE STAGE */
	if ($('iStage')) {
		var stage = $('iStage');
		stage.setStyle('top', '-40px');
		var morph = new Fx.Morph('iStage');
		var pos = 'close';
		
		$$('a.openClose').addEvent('click', function(e) {
			if (pos == 'close') {
				e.stop();
				morph.start({
					top: '0'
				});
				$$('a.openClose img').set('src', '/skinAdmin/entigo/widgets/ico-stage2.gif');
				pos = 'open';
			} else {
				e.stop();
				morph.start({
					top: '-40px'
				});
				$$('a.openClose img').set('src', '/skinAdmin/entigo/widgets/ico-stage.gif');
				pos = 'close';
			}
		});
	}
	
	/*
	 * GESTIONE HEADER FLASH
	 */	
	if ($('flash') && $('movie')) {
		mainFlash("open");
	}
	
	/* GESTIONE LUNGHEZZA IMG in IE */
	if (Browser.Engine.trident) {
		$$('ul.menuI img').each(function(img) {
			var imgWidth = img.width;
			img.setStyle('width', imgWidth + 'px');	
			img.setProperty('width', imgWidth);
		});
		$$('h1 img').each(function(img) {
			var imgWidth = img.width;
			img.setStyle('width', imgWidth + 'px');
			img.setProperty('width', imgWidth);
		});
	}
	
	/* GESTIONE MENU I */
	if (Browser.Engine.trident) {
		/*$$('ul.menuI div').each(function(img) {  
			var src = img.getStyle('filter');  
			var extension = src.substring(src.lastIndexOf('.'),src.length)
			extension = extension.substr(0,4)
			img.addEvent('mouseenter', function() { img.setStyle('filter',src.replace(extension,'2' + extension)); });  
			img.addEvent('mouseleave', function() { img.setStyle('filter',src); });  
		});*/
		$$('ul.menuI img').each(function(img) {  
			var src = img.get('src');  
			var extension = src.substring(src.lastIndexOf('.'),src.length)  
			img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'2' + extension)); });  
			img.addEvent('mouseleave', function() { img.setProperty('src',src); });  
		});
	} else {
		$$('ul.menuI img').each(function(img) {  
			var src = img.get('src');  
			var extension = src.substring(src.lastIndexOf('.'),src.length)  
			img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'2' + extension)); });  
			img.addEvent('mouseleave', function() { img.setProperty('src',src); });  
		});
	};
	
	var bodyClass    = document.body.className;	
	var scrollHeight = getScrollHeight();
	var header       = $('header').getHeight();
	var contenuti    = $('contenuti').getHeight();
	var flash        = 341 ; //$('flash').getHeight();
	var pippo        = (scrollHeight - (header + contenuti + flash));
	var goTo         = $('contenuti').getTop();
	if ($('colMenu')) {
		var isB4     = $('colMenu').className;
	} else {
		var isB4     = false;
	}


	$$('a.blank').addEvent('click', function(e){
		e.stop();
		var url = this.getProperty('href');
		popupNewWindow(url);
		return false;
	});

	/* GESTIONE MENU 'SECONDARIO' */
	if ($('menuSecondario')) {
		$$('li.toMove').each(function(el) {
			var innerUl   = el.lastChild;
			var oldAnchor = el.getFirst();
			var newLabel  = (el.get('title') ? el.get('title') : oldAnchor.get('title'));
			var newLi = new Element('li', {
				  'class': 'newLi'
			}).inject(innerUl, 'top');
			
			oldAnchor.clone()
					 .set('html', newLabel)
					 .set('class', 'clone')
					 .inject(newLi)
					 ;
			
			if (oldAnchor.get('class') == 'original1') {
				oldAnchor.set('class', 'opener first');
			} else if (oldAnchor.get('class') == 'original1 open') {
				oldAnchor.set('class', 'opener first open');
			} else {
				oldAnchor.set('class', 'opener');
			}
			

		});
		
		$$('li.fGallery').each(function(el) {
			var thisLink = el.getFirst();
			el.inject($('menuSecondario'), 'top');
			thisLink.set('text', 'Photogallery');
		});
		$$('ul.collapse').each( function(e) {
			e.morph({opacity: 0});
			e.setStyle('display', 'none');
		});

		
		if ($$('li.open').length > 1) {
			$$('li.open').each(function(el) {
					var innerUl = el.lastChild;
					/*var innerLi = innerUl.getChildren();
					var innerA  = innerLi.getFirst();*/
					innerUl.setStyle('display', 'block');
					/*innerLi.setStyle('margin', '0');
					innerA.setStyles({
						borderTop:'solid 1px #f1f1f0',
						borderBottom:'solid 2px #f1f1f0',
						backgroundColor:'#f1f1f0'
					});*/
					innerUl.morph({opacity: 1, duration: 2000, transition: Fx.Transitions.linear});
					//$$('li.newLi').setStyle('display', 'none');
			});
		}
		
		$$('.opener').each(function(e){
			if (e.getProperty('rel') == 'open') {
				e.setStyles({
					backgroundColor: '#e4e3e1',
					borderTop:'solid 1px #c5c2bd',
					borderBottom:'solid 1px #e4e3e1',
					color:'#4d433a',
					textDecoration:'none'
				});
			}
		});
		$$('a.current').each(function(e){
			e.setStyles({
				backgroundColor: '#e4e3e1',
				borderTop:'solid 1px #c5c2bd',
				borderBottom:'solid 1px #e4e3e1',
				color:'#000000',
				textDecoration:'none',
				fontWeight:'bold'
			});
		});
		$$('.clone').each(function(e){
			if (e.getProperty('rel') == 'open current') {
				e.setStyles({
					backgroundColor: '#e4e3e1',
					borderTop:'solid 1px #c5c2bd',
					borderBottom:'solid 1px #e4e3e1',
					color:'#4d433a',
					textDecoration:'none'
				});
			}
		});
		$$('.opener').addEvent('click', function(e){
			e.stop();
			var isUl = this.getNext();
			var isLi = isUl.getChildren();
			var isA  = isLi.getFirst();
			if (isUl.get('tag') == 'ul') {
				isUl.morph({opacity: 0});

				// apro/chiudo il livello figlio
				if (isUl.getStyle('display') == 'none') {
					this.setStyles({
						backgroundColor: '#e4e3e1',
						borderTop:'solid 1px #c5c2bd',
						borderBottom:'solid 1px #e4e3e1',
						color:'#4d433a',
						textDecoration:'none'
					});
					isUl.setStyle('display', 'block');
					isLi.setStyle('margin', '0');
					isA.setStyles({
						borderTop:'solid 1px #f1f1f0',
						borderBottom:'solid 2px #f1f1f0',
						backgroundColor:'#f1f1f0'
					});
					isUl.morph({opacity: 1, duration: 2000, transition: Fx.Transitions.linear});
				} else {
					if (this.get('class') == 'opener first') {
						this.setStyles({
							backgroundColor: '#ffffff',
							borderTop:'solid 1px #fff',
							borderBottom:'solid 1px #fff',
							color:'#a6a19b',
							textDecoration:'none'
						});
					} else {
						this.setStyles({
							backgroundColor: '#f1f1f0',
							borderTop:'solid 1px #f1f1f0',
							borderBottom:'solid 1px #f1f1f0',
							color:'#a6a19b',
							textDecoration:'none'
						});
					}
					isUl.morph({opacity: 0, duration: 100, transition: Fx.Transitions.linear});
					isUl.setStyle('display', 'none');
					/*
					$$('ul.collapse').each( function(e) {
						e.morph({opacity: 0});
						e.setStyle('display', 'none');
					});
					*/
				}
			}
			return false;
		});
		$$('.icoEye a').addEvent('click', function(e){
			e.stop();
			var url = this.getProperty('href');
			popupFullScreen(url);
			return false;
		});
		$$('.popUp a').addEvent('click', function(e){
			e.stop();
			var url = this.getProperty('href');
			popupFullScreen(url);
			return false;
		});
		$$('.newWin a').addEvent('click', function(e){
			e.stop();
			var url = this.getProperty('href');
			popupNewWindow(url);
			return false;
		});
		$$('a.bBlog').addEvent('click', function(e){
			e.stop();
			var url = this.getProperty('href');
			popupNewWindow(url);
			return false;
		});
		/*
		$$('.bBlog a').addEvent('click', function(e){
			e.stop();
			//var url = this.getProperty('href');
			//popupFullScreen(url);
			return false;
		});
		*/
	}
	
	/* HOME PAGE BOSCOLO */
	if (bodyClass == 'home') {
		if (Browser.Engine.trident) { // for IE

			/* movimenti menu II */			
			var hotels = {
				'true': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-boscolohotels.png\', sizingMethod=\'scale\')',
				'false': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-boscolohotels2.png\', sizingMethod=\'scale\')'
			};
			var b4 = {
				'true': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-b4hotels.png\', sizingMethod=\'scale\')',
				'false': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-b4hotels2.png\', sizingMethod=\'scale\')'
			};
			
		} else {
			
			var hotels = {
				'true': '/skin/website/widgets/bt-boscolohotels.png',
				'false': '/skin/website/widgets/bt-boscolohotels2.png'
			};
			var b4 = {
				'true': '/skin/website/widgets/bt-b4hotels.png',
				'false': '/skin/website/widgets/bt-b4hotels2.png'
			};
			
		}
		
		var ombra = {
			'true': 'block',
			'false': 'none'
		};	

		var menuHs = new Fx.Slide('moveHotels').hide();
		var menuB4 = new Fx.Slide('moveB4').hide();

		$('btMoveHotels').addEvent('click', function(e){
			e.stop();
			menuHs.toggle();
			menuHs.toggle().addEvent('onComplete', function(e){
				//var myFx = new Fx.Scroll(window).toBottom();
				if (!menuB4.open && !menuHs.open) {
					window.scrollTo(0, 0);
				} else {
					window.scrollTo(0, goTo);
				}
			});
			menuB4.slideOut();
			
			if (Browser.Engine.trident) {
				if (!menuHs.open && menuB4.open) {
					$('idMoveHotels').setStyle('filter', hotels[menuHs.open]);
					$('idMoveB4').setStyle('filter', b4[menuB4.open]);
				} else {
					$('idMoveHotels').setStyle('filter', hotels[menuHs.open]);
				}
			} else {
				if (!menuHs.open && menuB4.open) {
					$('idMoveHotels').set('src', hotels[menuHs.open]);
					$('idMoveB4').set('src', b4[menuB4.open]);
				} else {
					$('idMoveHotels').set('src', hotels[menuHs.open]);
				}
			}
		});
	
	
		$('btMoveB4').addEvent('click', function(e){
			e.stop();
			menuB4.toggle();
			menuB4.toggle().addEvent('onComplete', function(e){
				//var myFx = new Fx.Scroll(window).toBottom();
				window.scrollTo(0, goTo);
				if (!menuB4.open && !menuHs.open) {
					window.scrollTo(0, 0);
				} else {
					window.scrollTo(0, goTo);
				}
			});
			menuHs.slideOut();
			
			if (Browser.Engine.trident) {
				if (!menuB4.open && menuHs.open) {
					$('idMoveB4').setStyle('filter', b4[menuB4.open]);
					$('idMoveHotels').setStyle('filter', hotels[menuHs.open]);
				} else {
					$('idMoveB4').setStyle('filter', b4[menuB4.open]);
				}
			} else {
				if (!menuB4.open && menuHs.open) {
					$('idMoveB4').set('src', b4[menuB4.open]);
					$('idMoveHotels').set('src', hotels[menuHs.open]);
				} else {
					$('idMoveB4').set('src', b4[menuB4.open]);
				}
			}
		});
		/*menuB4.addEvent('complete', function() {
			//$('vertical_status').set('html', status[myVerticalSlide.open]);
			//alert(b4[menuB4.open]);
		});*/

		
		/* movimenti degli sfondi */
		
		if (Browser.Engine.trident) {
			var fullHeight = contenuti + header + flash + pippo;
		} else {
			var fullHeight = contenuti + header + flash; // better for Safari
		}
		
		var left2Center = (getWidth() - 1000) / 2;
		
		$('pagina').setStyle('position', 'absolute');
		$('pagina').setStyle('left', left2Center);
		$('pagina').setStyle('margin', '0');
		
	} else if (bodyClass != 'interna fullwidth') { // ALTRE PAGINE
		
		if (Browser.Engine.trident) { // for IE
			
			/* movimenti menu II */	
			if (isB4 == "colMenu b4") {
				var hotelsInt = {
					'true': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-boscolohotelsIntB4.png\', sizingMethod=\'scale\')',
					'false': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-boscolohotelsIntB42.png\', sizingMethod=\'scale\')'
				};
				var b4Int = {
					'true': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-b4hotelsIntB4.png\', sizingMethod=\'scale\')',
					'false': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-b4hotelsIntB42.png\', sizingMethod=\'scale\')'
				};

			} else {
				var hotelsInt = {
					'true': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-boscolohotelsInt.png\', sizingMethod=\'scale\')',
					'false': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-boscolohotelsInt2.png\', sizingMethod=\'scale\')'
				};
				var b4Int = {
					'true': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-b4hotelsInt.png\', sizingMethod=\'scale\')',
					'false': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/skin/website/widgets/bt-b4hotelsInt2.png\', sizingMethod=\'scale\')'
				};
			}
			
		} else {
			if (isB4 == "colMenu b4") {
				var hotelsInt = {
					'true': '/skin/website/widgets/bt-boscolohotelsIntB4.png',
					'false': '/skin/website/widgets/bt-boscolohotelsIntB42.png'
				};
				var b4Int = {
					'true': '/skin/website/widgets/bt-b4hotelsIntB4.png',
					'false': '/skin/website/widgets/bt-b4hotelsIntB42.png'
				};
			} else {
				var hotelsInt = {
					'true': '/skin/website/widgets/bt-boscolohotelsInt.png',
					'false': '/skin/website/widgets/bt-boscolohotelsInt2.png'
				};
				var b4Int = {
					'true': '/skin/website/widgets/bt-b4hotelsInt.png',
					'false': '/skin/website/widgets/bt-b4hotelsInt2.png'
				};
			}
			
		}
		
		var ombra = {
			'true': 'block',
			'false': 'none'
		};

		var menuHsInt = new Fx.Slide('moveHotelsInt').hide();
		var menuB4Int = new Fx.Slide('moveB4Int').hide();
		
		$('btMoveHotelsInt').addEvent('click', function(e){
			e.stop();
			menuHsInt.toggle();
			menuHsInt.toggle().addEvent('onComplete', function(e){
				//var myFx = new Fx.Scroll(window).toBottom();
				if (!menuB4Int.open && !menuHsInt.open) {
					window.scrollTo(0, 0);
				} else {
					window.scrollTo(0, goTo);
				}
			});
			menuB4Int.slideOut();
			
			if (Browser.Engine.trident) {
				if (!menuHsInt.open && menuB4Int.open) {
					$('idMoveHotelsInt').setStyle('filter', hotelsInt[menuHsInt.open]);
					$('idMoveB4Int').setStyle('filter', b4Int[menuB4Int.open]);
				} else {
					$('idMoveHotelsInt').setStyle('filter', hotelsInt[menuHsInt.open]);
				}
			} else {
				if (!menuHsInt.open && menuB4Int.open) {
					$('idMoveHotelsInt').set('src', hotelsInt[menuHsInt.open]);
					$('idMoveB4Int').set('src', b4Int[menuB4Int.open]);
				} else {
					$('idMoveHotelsInt').set('src', hotelsInt[menuHsInt.open]);
				}
			}
		});
	
		$('btMoveB4Int').addEvent('click', function(e){
			e.stop();
			menuB4Int.toggle();
			menuB4Int.toggle().addEvent('onComplete', function(e){
				//var myFx = new Fx.Scroll(window).toBottom();
				if (!menuB4Int.open && !menuHsInt.open) {
					window.scrollTo(0, 0);
				} else {
					window.scrollTo(0, goTo);
				}
			});
			menuHsInt.slideOut();
			
			if (Browser.Engine.trident) {
				if (!menuB4Int.open && menuHsInt.open) {
					$('idMoveB4Int').setStyle('filter', b4Int[menuB4Int.open]);
					$('idMoveHotelsInt').setStyle('filter', hotelsInt[menuHsInt.open]);
				} else {
					$('idMoveB4Int').setStyle('filter', b4Int[menuB4Int.open]);
				}
			} else {
				if (!menuB4Int.open && menuHsInt.open) {
					$('idMoveB4Int').set('src', b4Int[menuB4Int.open]);
					$('idMoveHotelsInt').set('src', hotelsInt[menuHsInt.open]);
				} else {
					$('idMoveB4Int').set('src', b4Int[menuB4Int.open]);
				}
			}
		});
		
		/* movimenti degli sfondi */
		
		/*if (Browser.Engine.trident) { // for IE
			var fullHeight = (contenuti + header + flash + pippo);
		} else {*/
			var fullHeight = (contenuti + header + flash);
		//}
		
		//var left2Center = $('pagina').getLeft();
		var left2Center = (getWidth() - 1000) / 2;
		
		$('pagina').setStyle('position', 'absolute');
		$('pagina').setStyle('left', left2Center);
		$('pagina').setStyle('margin', '0');
		if ($('bgSx')) {$('bgSx').setStyle('height', fullHeight)};
		if ($('bgDx')) {$('bgDx').setStyle('height', fullHeight)};
		if ($('bgCx')) {
			$('bgCx').setStyle('height', fullHeight);
			$('bgCx').setStyle('left', left2Center);
		};
	}
	
	FLIR.init({ path: '/facelift/' });
	$$('h1.flir').each(function(el) {
		//FLIR.replace(el , new FLIRStyle({ cFont:'arial' }));
		FLIR.replace(el);
	});
	//Avvio la sostituzione render text per il menù dinamico 
	$$('h2.flir').each(function(el) {
		FLIR.replace(el , new FLIRStyle({ mode:'wrap' }));
	});
	
	
	/*
	 * gestione FORM MICE
	 */
	/*if ($('formMice')) {*/
		var boxBlockA = $$('div.num_box_a').getProperty('title');
		var boxBlockB = $$('div.num_box_b').getProperty('title');
		
		$$('a.clona').addEvent('click', function(e){
			e.stop();			
			var rel = this.getProperty('rel');			
			if (rel == 'a') {
				if ( boxBlockA < 6 ) {
					boxBlockA++;
					$('a_clo_'+boxBlockA).setStyle('display', 'block');
					$('a_clo_'+boxBlockA+'_open').setProperty('value', 'T');
				}
			}			
			if (rel == 'b') {
				if ( boxBlockB < 6 ) {
					boxBlockB++;
					$('b_clo_'+boxBlockB).setStyle('display', 'block');
					$('b_clo_'+boxBlockB+'_open').setProperty('value', 'T');
				}
			}
			return false;

		});

	/*
	 * Gestione VIRTUALTOUR
	 */
	$$('a.virtualStart').addEvent('click', function(e){
		e.stop();
		
		/*
		 * GESTIONE HEADER FLASH
		 */	
		if ($('flash')) {
			mainFlash("close");
		}

		//var div          = virtualContainer; //$$('div.virtualContainer');	
		var div          = $$('div.virtualContainer');	
		var overlay      = $$('div.virtualOverlay');	
		var scroll       = window.getScrollSize();
		var totWidth     = getWidth();
		var totHeight    = getHeight();
		//var iframe       = virtualIframe; //$$('iframe.virtualIframe');
		var iframe       = $$('iframe.virtualIframe');
		var iframeWidth  = iframe.getProperty('width');
		var iframeHeight = iframe.getProperty('height');
		var iframeTop    = ((totHeight-iframeHeight)/2).round();
		var iframeLeft   = ((totWidth-iframeWidth)/2).round();

		// from lightbox
		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;
		}
		var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		// from lightbox END

		window.scrollTo(0, 0);
		
		div.setStyle('display', 'block');
		div.setStyle('position', 'absolute');
		div.setStyle('width', '100%');
		overlay.setStyle('display', 'block');
		overlay.setStyle('position', 'absolute');
		overlay.setStyle('width', '100%');
		
		if (Browser.Engine.trident) {
			div.setStyle('height', scroll.y);
			overlay.setStyle('height', scroll.y);
		} else {
			div.setStyle('height', arrayPageSize[1]);
			overlay.setStyle('height', arrayPageSize[1]);
		}
		div.setStyle('top', '0');
		div.setStyle('left', '0');
		div.setStyle('zIndex', '100');
		overlay.setStyle('top', '0');
		overlay.setStyle('left', '0');
		overlay.setStyle('zIndex', '100');
		iframe.setStyle('position', 'absolute');
		iframe.setStyle('top', iframeTop+'px');
		iframe.setStyle('left', iframeLeft+'px');
	});
	
	
	// gestione chiusura overflow
	$$('div.virtualContainer').addEvent('click', function(e){
		closeVirtualTour();
	});
	$$('div.virtualOverlay').addEvent('click', function(e){
		closeVirtualTour();
	});
	
	function closeVirtualTour() {
		$$('div.virtualOverlay').setStyle('display', 'none');
		$$('div.virtualContainer').setStyle('display', 'none');

		/*
		 * GESTIONE HEADER FLASH
		 */	
		if ($('flash')) {
			mainFlash("open");
		}
	}
	
	$$('a.popup_pdf').addEvent('click', function(e){
		e.stop();
		
		var url = this.getProperty('href');
		
		//popupFullScreen(url);
		popupNewWindow(url)
		
		return false;
	});
	
});

window.addEvent('scroll', function() {
								   
	var bodyClass    = document.body.className;
	var scrollHeight = getScrollHeight();
	var header       = $('header').getHeight();
	var contenuti    = $('contenuti').getHeight();
	var flash        = 341; //$('flash').getHeight();
	
	var fullHeight = (contenuti + header + flash);
	var left2Center = (getWidth() - 1000) / 2;
	
	if (bodyClass == 'home') {		
		
		$('pagina').setStyle('position', 'absolute');
		$('pagina').setStyle('left', left2Center);
		$('pagina').setStyle('margin', '0');
	
	} else {
		

		$('pagina').setStyle('position', 'absolute');
		$('pagina').setStyle('left', left2Center);
		$('pagina').setStyle('margin', '0');
		if (Browser.Engine.trident) {
			if ($('bgSx')) {
				if (window.getHeight() > fullHeight) {
					$('bgSx').setStyle('height', window.getHeight())
				} else {
					$('bgSx').setStyle('height', fullHeight)
				}
			};
		} else {
			if ($('bgSx')) {$('bgSx').setStyle('height', fullHeight)};
		}
		if ($('bgDx')) {$('bgDx').setStyle('height', fullHeight)};
		if ($('bgCx')) {
			$('bgCx').setStyle('height', fullHeight);		
			$('bgCx').setStyle('left', left2Center);
		};
	}
			
});

window.addEvent('resize',function(e){
	if (Browser.Engine.trident) { // for IE
		var bodyClass    = document.body.className;	
	} else {
		var bodyClass    = $$('body')[0].getProperty('class');
	}
	//var bodyClass    = document.body.className;
	//var bodyClass    = $$('body')[0].getProperty('class');
	var scrollHeight = getScrollHeight();
	var header       = $('header').getHeight();
	var contenuti    = $('contenuti').getHeight();
	var flash        = 341; //$('flash').getHeight();

	var fullHeight = (contenuti + header + flash);
	var left2Center = (getWidth() - 1000) / 2;
	
	if (bodyClass == 'home') {		
		
		$('pagina').setStyle('position', 'absolute');
		$('pagina').setStyle('left', left2Center);
		$('pagina').setStyle('margin', '0');
	
	} else {

		$('pagina').setStyle('position', 'absolute');
		$('pagina').setStyle('left', left2Center);
		$('pagina').setStyle('margin', '0');
		if (Browser.Engine.trident) {
			if ($('bgSx')) {
				if (window.getHeight() > fullHeight) {
					$('bgSx').setStyle('height', window.getHeight())
				} else {
					$('bgSx').setStyle('height', fullHeight)
				}
			};
		} else {
			if ($('bgSx')) {$('bgSx').setStyle('height', fullHeight)};
		}
		if ($('bgDx')) {$('bgDx').setStyle('height', fullHeight)};
		if ($('bgCx')) {
			$('bgCx').setStyle('height', fullHeight);		
			$('bgCx').setStyle('left', left2Center);
		};
	}
});
