
	function openSpotlightWindow(arg, opt) {
		
		var loader = "";
		
		switch(arg) {
		
			case 'newsletter':
				loader = new cx.utils.ContentLoader(
					'WCX_Module_Newsletter',
					'getNewsletterFormHtml',
					[],
					[opt]
				);
				break;
				
			case 'orderPublication':
				loader = new cx.utils.ContentLoader(
					'WCX_Module_Publications',
					'getOrderFormHtml',
					[],
					[opt]
				);
				break;
								
			case 'showPublicationYoutube':
				loader = new cx.utils.ContentLoader(
					'WCX_Module_Publications',
					'getYoutubeHtml',
					[],
					[opt]
				);
				
				var usrConfig = {
					windowStyle: {
						backgroundColor: "#aaa",
						alpha: 0.2
					},
					bodyStyle: {
						margin: "0px",
						marginTop: "21px",
						backgroundColor: "#000"
					}
				};
				
				new cx.controls.SpotlightWindow(loader, usrConfig);
				
				return;
				
			case 'bookEvent':
				loader = new cx.utils.ContentLoader(
					'WCX_Module_Events',
					'getBookingFormHtml',
					[],
					[opt]
				);
				break;
								
			case 'showGallery':
				loader = new cx.utils.ContentLoader(
					'WCX_Module_Gallery',
					'getCollectionHtml',
					[],
					[opt]
				);
				break;
			
			case 'handoutLogin':
				loader = new cx.utils.ContentLoader(
					'WCX_Module_Events',
					'getHandoutLoginFormHtml',
					[],
					[opt]
				);
				break;
		}
				
		new cx.controls.SpotlightWindow(loader);
	}

	function switchTo(url) {
		
		var el = $('c_main');
				
		new Effect.Morph('c_main', {
			style: {
				height: '0px'
			},
			duration: 0.8,
			afterFinish: function(){
				location.href = url;
		}});
	}
	
	function growContent() {
		
		var el = $('c_main');
		var height = getInnerWindowHeight();
		
		new Effect.Morph('c_main', {
			style: {
				height: (height > 710) ? '758px' : '635px'
			},
			duration: 0.8,
			afterFinish: function(){
		}});
	}

	Event.observe(window, "load", function() {

	    window.setInterval(main_resize, 10);
	    Event.observe(window, "resize", main_resize);

	    main_resize();
	    $('c_main').show();

	    if ($('c_main').getHeight() == 0) growContent();

	    Effect.Appear('top_content_inner', {
	        duration: 0.5,
	        afterFinish: function() {
	            Effect.Appear('bottom_content_inner', {
	                duration: 0.6,
	                delay: 0.1
	            });
	        }
	    });
		
		$('w_groupMenu_trigger').observe('mouseover', _showSitesMenu);
		$('w_groupMenu_container').observe('mouseout', _hideSitesMenu);
	    
	    try {
	    	
	    	$('searchInput').observe('focus', function(evt) {
	    		var el = evt.element();
	    		Form.Element.activate(el);
	    		el.setStyle({
	    			border: '1px solid #ddd'
	    		});
	    	});
	    	
	    	$('searchInput').observe('blur', function(evt) {
	    		evt.element().setStyle({
	    			border: ''
	    		});
	    		
	    		if (Form.Element.getValue(evt.element()) == "") {
	    			evt.element().value = "SUCHEN";
	    		}
	    	});
	    	
	    	$('searchInput').observe('keydown', function(evt) {
	    		if (evt.keyCode == Event.KEY_RETURN) {
	    			var val = Form.Element.getValue(evt.element());
	    			if (val != "SUCHEN" && val.length > 3) {
						__performSearch(Form.Element.getValue(evt.element()));
	    			}
	    			else {
	    				
						if (location.href.split("/")[3] == "it") {
	    					alert("Effettuare almeno tre digiti nel campo di ricerca.");
						}
						else {
							alert("Bitte geben Sie mindestens 3 Zeichen in das Suchfeld ein.");
						}
	    			}
	    		}
	    	});
	    }
	    catch(e) {}
	});
	
	function __performSearch(arg) {
		 
		var idSite = $("searchInput").className.split('-').shift().replace(/s/, "");
		var idLang = $("searchInput").className.split('-').pop().replace(/l/, "");
		
		loader = new cx.utils.ContentLoader(
			'WGT_Search',
			'find',
			[],
			[arg, idSite, idLang]
		);
		
		new cx.controls.SpotlightWindow(loader, {
			windowStyle: {
				width: "600px",
				height: "520px"
			},
			bodyStyle: {
				margin: "3px"
			}
		});
	}
	
	function main_resize() {
		
		var innerHeight = getInnerWindowHeight();
		var innerWidth = getInnerWindowWidth();
				
		var marginTop = ((innerHeight - $('c_main').getHeight()) / 2);
		if (marginTop < 0) {
			marginTop = 0;
			document.body.style.backgroundPosition = "center -32px";
		}
		else {
			document.body.style.backgroundPosition = "center";
		}
		
		$('c_main').style.top = Math.round(marginTop) + 'px';
		
		var marginLeft = ((innerWidth - $('c_main').getWidth()) / 2);
		if (marginLeft < 42) marginLeft = 42;
		$('c_main').style.left = Math.round(marginLeft - 42) + 'px';
		


    }
	
	function getInnerWindowHeight() {
		
		var y;
		if (self.innerHeight) 
		{
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
			y = document.documentElement.clientHeight;
		}
		else if (document.body) 
		{
			y = document.body.clientHeight;
		}
		
		return(y);
	}

	function getInnerWindowWidth() {
		
		var x;
		if (self.innerWidth) 
		{
			x = self.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth)
		{
			x = document.documentElement.clientWidth;
		}
		else if (document.body) 
		{
			x = document.body.clientWidth;
		}
		
		return(x);
	}
	
	function _showSitesMenu() {
		$('w_groupMenu_container').show(); 
	}

	function _hideSitesMenu() {
		$('w_groupMenu_container').hide();
	}
	