window.addEvent('domready',function(){

	$$('a').each(function(x){
		y = x.getAttribute('rev');
	
		if(navigator.appVersion.indexOf('MSIE') != -1){
			if(y != ""){
				$(y).setStyle('visibility','hidden');
			}
		}else{
			if(y != null){
				$(y).setStyle('visibility','hidden');
			}
		}
	})
})

var xxx = new Array();

$$('a').each(function(el){
	if(el.getAttribute('rel') == "designSlide"){
		
		
		// preload images
		a = new Image();
		lnk = el.getAttribute('href');
		
		a.src = lnk;
		xxx.push(a);
	
		el.addEvent('click',function(x){		
		// old container still existing? remove it
		if($('container2') != false){
			$('container2').remove();
		}
		
		//go
		bd = document.body;
		windowHeight = 0;
		windowWidth = 0;
		title = el.getAttribute('title');
		titleSplitPos = title.indexOf("::");
		titleHead = title.substring(0,titleSplitPos);
		lengthContent = title.length + titleSplitPos
		titleContent = title.substring(titleSplitPos+2,lengthContent);
		addContent = el.getAttribute('rev');
	
		if($(addContent) != false){
			addContentCont = $(addContent).innerHTML;
			$(addContent).setStyle('visibility','hidden');	
		}
	
		nav = navigator.appName;
		windowHeight = window.getScrollTop() + window.getHeight();
		var x = new Event(x).stop();
		var hrefSrc = el.getAttribute('href');
		var preloadPrev = new Image();
		preloadPrev.src = hrefSrc;
		var imgWidth = preloadPrev.width;
		var imgHeight = preloadPrev.height;	
		var altezzaiframe = 400
		//var space = imgHeight + 40;
		
		tipomenu = el.getAttribute('menu');
		
		
		

		
		
		if (tipomenu.substring(0,8) == 'chisiamo'){
			var space = 150; //250
		} else if (tipomenu.substring(0,8) == 'contatti') {
			var space = 80; //250
		} else if (tipomenu.substring(0,15) == 'esteso_contatti') {
			var space = 400; //250
			var altezzaiframe = 400
		} else if (tipomenu.substring(0,6) == 'colori') {
			var space = 200; //250
		} else if (tipomenu.substring(0,12) == 'steel_colori') {
			var space = 200; //250

		} else if (tipomenu.substring(0,7) == 'incroci') {
			var space = 300; //250
		} else if (tipomenu.substring(0,15) == 'alzate_cubeline') {
			var space = 320; //250
		} else if (tipomenu.substring(0,11) == 'alzate_mini') {
			var space = 320; //250
		} else if (tipomenu.substring(0,15) == 'alzate_miniline') {
			var space = 320; //250
		} else if (tipomenu.substring(0,15) == 'alzate_ringline') {
			var space = 340; //250
		} else if (tipomenu.substring(0,15) == 'alzate_longline') {
			var space = 340; //250
		} else if (tipomenu.substring(0,11) == 'alzate_long') {
			var space = 340; //250
		} else if (tipomenu.substring(0,11) == 'alzate_ring') {
			var space = 320; //250
		} else if (tipomenu.substring(0,11) == 'alzate_cube') {
			var space = 320; //250
		} else if (tipomenu.substring(0,12) == 'alzate_steel') {
			var space = 320; //250			
		} else if (tipomenu.substring(0,11) == 'alzate_zinc') {
			var space = 320; //250			
		} else if (tipomenu.substring(0,14) == 'balaustra_pali_zink') {
			var space = 320; //250
		} else if (tipomenu.substring(0,14) == 'balaustra_cavi') {
			var space = 320; //250
		} else if (tipomenu.substring(0,14) == 'balaustra_pali') {
			var space = 320; //250
		} else if (tipomenu.substring(0,18) == 'larghezze_longline') {
			var space = 320; //250
		} else if (tipomenu.substring(0,14) == 'larghezze_mini') {
			var space = 320; //250
		
		
		} else {
			var space = 480;
		}	
		
		
		//var space = 400;
		
		var top = windowHeight - space;
		
		// create a new div with the width of the screen
		var container = new Element('div', {
					'styles': 
					{
						'display': 'block',
						'visibility':'hidden',
						'width': '98%',
						'height': space,
						'background':'#FFF',
						'border': '1px solid #AAA',
						'padding':'0px',
						'left':'3px',
						'margin':'0px',
						'position': 'absolute',
						'top': top + 'px'
					}
			  })
			  
		container.setAttribute('id','container2');
			  // div Immagine
			  image = new Element('img', {
			  	'styles':
				{
					'border': '3px solid #FFF',
					'display':'block',
					'visibility': 'hidden',
					'float':'left',
					'background': '#000 url(images/loading.gif) center center no-repeat',
					'margin-top':'20px',
					'margin-left':'20px',
					'height':imgHeight,
					'width': imgWidth,
					'src': hrefSrc,
					'z-index':'1000'
				}			
			})
			  
			//iframe alberto------------------------------------------
			
			
				var iframe = new Element('iframe', {
					'styles': 
					{
						'width': '98%',
						'height': altezzaiframe

					}
			  })
				
			
			iframe.setAttribute('id','iFrame230469');
			iframe.setAttribute('frameBorder', '0');
			
			

			iframe.setAttribute('src', tipomenu+'.html');
			
			/*
			if (tipomenu == 'chisiamo'){
			iframe.setAttribute('src','chisiamo.html');
			} else if (tipomenu == 'contatti') {
			iframe.setAttribute('src','contatti.html');
			} else {
				
			iframe.setAttribute('src','content2.html');	
			}
			*/
			
			/*iframe.setAttribute('src','content1.html');*/
			/*iframe.setAttribute('frameborder', '0');
			iframe.setAttribute('marginwidth', '4');
			iframe.setAttribute('marginheight', '4');*/

			
			
			
			
			iframe.setProperties().injectInside(container);
			
/*
				iframe = new Element('iframe', {
				'styles':
				{					 
				'border': '30px solid #FFF'
				'id': 'iFrame230469',
				'width': '98%',
				'height': 300,
				'src': 'content1.html',
				'scrolling': 'auto'
									 
				 }    
				})*/
				
/*				
				
				iframe.setProperties({
				id: 'iFrame230469', 
				width: '98%',
				height: 300,
				src: 'content1.html',
				frameborder: 0,
				scrolling: 'auto'
			}).injectInside(container);
			  
*/
			  
			// div testo
			  div = new Element('div', {
			    'styles':
				{
						'float':'left',
						'width': '50%',
						//'width':'300px',
						'height':'auto',
						'display':'block',
						'margin-top':'20px',
						'margin-left':'20px'
						
						
				}
			})
			
			
			
			
			/*
			off = new Element('img', {
			  'styles':
			  	{
			  			'float':'left',
						'width':'64px',
						'height':'20px'
						
				}
			
			})		
			  off.src="images/close.jpg";
			 off.addEvent('click',function(){
			 	  	 container.effect('opacity',{duration: 700, transition: Fx.Transitions.linear, wait:true}).start(0.9,0).chain(function(){
					 // var h = container.getStyle('height');																															  					//  image.remove();
					//  container.effect('height',{duration: 700, transition: Fx.Transitions.linear, wait:true}).start(h,0).chain(function(){
					  container.remove();
					  $('overlayed').effect('opacity',{duration: 300, transition: Fx.Transitions.linear, wait:true}).start(0.5,0);
					  $('overlayed').remove();
					 })
			 })
					 
			*/		 
					 
					 
					 
					 
					 
			  
			 div.setAttribute('id','info');			
			
			/*
			 if($(addContent) != false){
			 div.innerHTML = "<h3>" + titleHead + "</h3><p>" + titleContent + "</p>" + "<p>" + addContentCont + "</p>";
			 }else{
			 div.innerHTML = "<h3>" + titleHead + "</h3><p>" + titleContent + "</p>";
			 }
			 */
			 
			 // add overlay
			 winH = window.getScrollHeight();
			 winW = window.getScrollWidth();
			 overlayed = new Element('div', {
	          'styles':
			  {
				  	'width':winW,
					'height':winH,
					'position':'absolute',
					'background-color':'#000',
					'visibility':'hidden',
					'top':'0px',
					'left':'0px'
			  }
			  })
			 
			 
			 
			 
			 
			 //------------------------------------------
				overlayed.addEvent('click',function(){
			 	  	 container.effect('opacity',{duration: 700, transition: Fx.Transitions.linear, wait:true}).start(0.9,0).chain(function(){
					 // var h = container.getStyle('height');																															  					//  image.remove();
					//  container.effect('height',{duration: 700, transition: Fx.Transitions.linear, wait:true}).start(h,0).chain(function(){
					  container.remove();
					  $('overlayed').effect('opacity',{duration: 300, transition: Fx.Transitions.linear, wait:true}).start(0.5,0);
					  $('overlayed').remove();
					 })
			 })
			  
			  //-----------------------------------------
			 
			 
			  overlayed.setAttribute('id','overlayed');			
			  overlayed.injectInside(document.body);
			  
			  image.src = preloadPrev.src;
			  
			  overlayed.effect('opacity',{ duration: 200, transition:Fx.Transitions.linear, wait:true }).start(0,0.5);
			  container.injectInside(bd);
			  image.injectInside(container);
			  image.effect('opacity',{duration: 200, transition: Fx.Transitions.linear, wait:false}).start(0,1);
		  	  container.effect('opacity',{duration: 700, transition: Fx.Transitions.linear, wait:false}).start(0,0.9);
			  container.effect('top',{duration: 1700, transition: Fx.Transitions.Bounce.easeOut, wait:false}).start(windowHeight,top);
			  div.injectAfter(image);
			  //off.injectInside(div);
			  container.makeDraggable();
			 return false;
		})
	}
})
