window.addEvent('domready', function(){
	var sliderNews=function(){
		var container=$('newsSpalla');
		if(container){
			var height=0
			var count=0;
			var periodical=null;
			var allBox=container.getElements('.box');
			
			allBox.each(function(item){
				if(item.getSize().y>height)
					height=item.getSize().y;
			});
			allBox.setStyle('height',height);
			var slider=new Element('div',{
				id: 'slider',
				styles: { 
					'position' : 'relative',
					'top': -1
				}
			});
			var boxSlider=new Element('div',{
				id: 'boxSlider',
				styles: { 
					'position' : 'relative',
					'height' : height,
					'overflow' : 'hidden'
				}
			});
			
			boxSlider.inject(container);
			boxSlider.adopt(slider);			
			slider.adopt(allBox);
			slider.set('tween', {duration: 1000, transition: Fx.Transitions.Bounce.easeOut });
			
			var slideNow=function(){
				count++;
				count=count%4;
				slider.tween('top', height*count*-1);
				if(!periodical) periodical=slideNow.periodical(4000);
			};
			slideNow.delay(3000);
			
			container.addEvents({
				 mouseenter: function(){
			        clearInterval(periodical);
			    },
			    mouseleave: function(){
			        periodical=slideNow.periodical(4000);
			    }
			});
		}		
	}.apply();
	
	var gallery=function(){
		var gallery=$('gallery');
		if(gallery ){
			var allPhoto=gallery.getElements('a.img');
			allPhoto.each(function(item){
				item.addEvent('click',function(event){
					event.stop();
					item.setStyle('opacity','0.4');
					var windowsSize=window.getSize();
					var windowsScrollSize=getScrollSize();
					var windowsScroll=window.getScroll();
					var coordinate=item.getCoordinates();
					
					var indexPhoto=allPhoto.indexOf(item);
										
					var lock=false;
					var mask=$('mask');
					if(!mask){
						var mask=new Element('div',{ 
							id: 'mask',
							styles: {
								'background-color': '#000',
								'opacity': 0.4,
								'z-index' : 8,
								'overflow' : 'hidden',
								'position' : 'absolute',
								'top' : 0,
								'left' : 0,
								'width' : windowsScrollSize.x,
								'height': windowsScrollSize.y
							},
							events: {
								'click': function(){
									mask.setStyle('display','none');
									var imgAttuale=imgFocus.getElement('img');
									if(imgAttuale) imgAttuale.destroy();
									imgFocus.setStyle('display','none');
								}
							}
						});
						mask.inject(document.getElement('body'),'bottom')	
					}
					
					var imgFocus=$('imgFocus');					
					if(!imgFocus){
						var imgFocus=new Element('div',{ id: 'imgFocus'});
						imgFocus.inject(document.getElement('body'),'bottom');
						imgFocus.set('morph', {
				    		duration: 'short', 
				    		transition: 'linear',
				    		onComplete: function(){
				    		}
			    		});	
			    		
			    		if(allPhoto.length>1){
				    		var indietroFocus=new Element('div',{ 
								'class' : 'freccia indietro',
								events: {
									'click': function(){
										if(lock==false){
											lock=true;
											myImage.setStyle('opacity',0.4);
											indexPhoto=(indexPhoto-1)%(allPhoto.length);
											if(indexPhoto<0) indexPhoto=allPhoto.length-1;
											var myImageLoad = Asset.image( allPhoto[indexPhoto], {
											    onLoad: function(){
											    	lock=false;
											    	var imgAttuale=imgFocus.getElement('img');
													if(imgAttuale){
														imgAttuale.set('src',myImageLoad.get('src'));
											    		imgAttuale.setStyle('opacity',1);	
													}
											    }
											});
										}
									}
								}
				    		});
				    		indietroFocus.inject(imgFocus);
				    		
				    		
				    		
				    		var avantiFocus=new Element('div',{
								'class' : 'freccia avanti',
								events: {
									'click': function(){
										if(lock==false){
											lock=true;
											myImage.setStyle('opacity',0.4);
											indexPhoto=(indexPhoto+1)%(allPhoto.length);
											var myImageLoad = Asset.image( allPhoto[indexPhoto], {
											    onLoad: function(){
											    	lock=false;
											    	var imgAttuale=imgFocus.getElement('img');
													if(imgAttuale){
														imgAttuale.set('src',myImageLoad.get('src'));
											    		imgAttuale.setStyle('opacity',1);	
													}
											    }
											});
										}
									}
								}
				    		});
				    		avantiFocus.inject(imgFocus);
			    		}
			    		
			    		var closeFocus=new Element('div',{
							'class' : 'close',
							events: {
								'click': function(){
									mask.setStyle('display','none');
									var imgAttuale=imgFocus.getElement('img');
									if(imgAttuale) imgAttuale.destroy();
									imgFocus.setStyle('display','none');
								}
							}
			    		});
			    		closeFocus.inject(imgFocus);
			    		
					}
					var imgAttuale=imgFocus.getElement('img');
					if(imgAttuale) imgAttuale.destroy();
					imgFocus.setStyle('display','none');

					var myImage = Asset.image( item.get('href'), {
					    id: 'myImage',
					    title: 'myImage',
					    styles: {
							'width' : '100%',
							'height': '100%'
						},
					    onLoad: function(){
					    	var imgWidth=myImage.get('width');
					    	var imgHeight=myImage.get('height');
					    	item.setStyle('opacity',1);
					    	mask.setStyle('display','block');
					    	myImage.inject(imgFocus);					    	
					    	imgFocus.setStyles({
					    		'display': 'block',
					    		'width':coordinate.width,
					    		'height':coordinate.height,
					    		'top':coordinate.top,
					    		'left':coordinate.left
					    	});
					    	imgFocus.morph({
					    		height: imgHeight,
					    		width: imgWidth,
					    		top: windowsSize.y/2+windowsScroll.y-imgHeight/2-10,
					    		left: windowsSize.x/2+windowsScroll.x-imgWidth/2-10
					    	});
					    }
					});

				});
			});
		}
	}.apply();
});

// MooTools: the javascript framework.
// Load this file's selection again by visiting: http://mootools.net/more/417ab68a672f38ea1c04efab47af2ff7 
// Or build this file again with packager using: packager build More/Assets
/*
---
copyrights:
  - [MooTools](http://mootools.net)

licenses:
  - [MIT License](http://mootools.net/license.txt)
...
*/
MooTools.More={version:"1.3.2.1",build:"e586bcd2496e9b22acfde32e12f84d49ce09e59d"};var Asset={javascript:function(f,c){if(!c){c={};}var a=new Element("script",{src:f,type:"text/javascript"}),g=c.document||document,b=0,d=c.onload||c.onLoad;
var e=d?function(){if(++b==1){d.call(this);}}:function(){};delete c.onload;delete c.onLoad;delete c.document;return a.addEvents({load:e,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){e.call(this);
}}}).set(c).inject(g.head);},css:function(d,a){if(!a){a={};}var b=new Element("link",{rel:"stylesheet",media:"screen",type:"text/css",href:d});var c=a.onload||a.onLoad,e=a.document||document;
delete a.onload;delete a.onLoad;delete a.document;if(c){b.addEvent("load",c);}return b.set(a).inject(e.head);},image:function(c,b){if(!b){b={};}var d=new Image(),a=document.id(d)||new Element("img");
["load","abort","error"].each(function(e){var g="on"+e,f="on"+e.capitalize(),h=b[g]||b[f]||function(){};delete b[f];delete b[g];d[g]=function(){if(!d){return;
}if(!a.parentNode){a.width=d.width;a.height=d.height;}d=d.onload=d.onabort=d.onerror=null;h.delay(1,a,a);a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);
}return a.set(b);},images:function(c,b){c=Array.from(c);var d=function(){},a=0;b=Object.merge({onComplete:d,onProgress:d,onError:d,properties:{}},b);return new Elements(c.map(function(f,e){return Asset.image(f,Object.append(b.properties,{onload:function(){a++;
b.onProgress.call(this,a,e,f);if(a==c.length){b.onComplete();}},onerror:function(){a++;b.onError.call(this,a,e,f);if(a==c.length){b.onComplete();}}}));
}));}};
