var BASE_URL = '';
//BASE_URL = '/bolzani';

soundManager.url = AIDAJS.baseUrl + '/soundmanager2/';
soundManager.altUrl = AIDAJS.baseUrl + '/soundmanager2/';
soundManager.debugMode = false;

var sound;

soundManager.onready(function()
{
	sound = soundManager.createSound({
		id: 'menu_sound',
		url: BASE_URL + '/tpl/default/media/blop.mp3',
		volume: 30
	});
});

Event.onReady(function()
{
	if(I('landing'))
	{
		I('landing').addEvent('mousemove', function(event)
		{
			var m = event.mousePosition('landing');
			I('landing_wrapper').css('left', 200 - (m[0] / 900 * 1030)); // + 50px per lato
		});
		
		$('#landing .landing-item').each(function($item)
		{
			var $photo = $('.photo', $item)[0];
			var $title = $('.title', $item)[0];
			var $text = $('.text', $item)[0];
			var $objects = $('.objects', $item)[0];
			var $bottom = $('.bottom', $item)[0];
			
			if (Agent.trident) 
			{
				$objects.hide();
			}
			else
			{
				$objects.css('opacity', 0);
			}
			$bottom.css('opacity', 0);
			
			$item.addEvent('mouseenter', function()
			{
				this.addClass('hover');
				
				$photo.morph({
					css: {
						top: ['px', ACTUAL, 0]
					},
					time: 1,
					effect: EE.outElastic,
					stop: true
				});
				
				if (Agent.trident) 
				{
					$objects.show().morph({
						css: {
							top: ['px', ACTUAL, 180]
						},
						time: 1,
						effect: EE.outElastic,
						stop: true
					});
				}
				else
				{
					$objects.morph({
						css: {
							top: ['px', ACTUAL, 180],
							opacity: [ACTUAL, 1]
						},
						time: 1,
						effect: EE.outElastic,
						stop: true
					});
				}
				
				$title.morph({
					css: {
						top: ['px', ACTUAL, 300]
					},
					time: 1,
					effect: EE.outElastic,
					stop: true
				});
				
				$bottom.morph({
					css: {
						opacity: [ACTUAL, 1]
					},
					time: 1,
					effect: EE.outCubic,
					stop: true
				});
				
				if(sound)
				{
					sound.play();
				}
				
			}).addEvent('mouseleave', function()
			{
				this.removeClass('hover');
				
				$photo.morph({
					css: {
						top: ['px', ACTUAL, 50]
					},
					time: 1,
					effect: EE.outElastic,
					stop: true
				});
				
				if (Agent.trident) 
				{
					$objects.css({
						display: 'none',
						top: 240
					});
				}
				else 
				{
					$objects.morph({
						css: {
							top: ['px', ACTUAL, 240],
							opacity: [ACTUAL, 0]
						},
						time: 1,
						effect: EE.outElastic,
						stop: true
					});
				}
				$title.morph({
					css: {
						top: ['px', ACTUAL, 320]
					},
					time: 1,
					effect: EE.outElastic,
					stop: true
				});
				
				$bottom.morph({
					css: {
						opacity: [ACTUAL, 0]
					},
					time: 1,
					effect: EE.outCubic,
					stop: true
				});
			});
		});
	}
	
	if(I('lista'))
	{
		$('#lista div.item-immobile').each(function($item)
		{
			var url = $('.dettaglio a', $item)[0].href;
			
			$item.addEvent('mouseenter', function()
			{
				this.addClass('hover');
			}).addEvent('mouseleave', function()
			{
				this.removeClass('hover');
			}).addEvent('click', function()
			{
				document.location = url;
			}).css('cursor', 'pointer');
			
			
		});
		
		$('#lista div.item-immobile li span').each(function($span)
		{
			$span.append(['em']);
		});
	}
	
	if(I('right_simili'))
	{
		$('#right_simili div.item-simile').each(function($item)
		{
			var url = $('.dettaglio a', $item)[0].href;
			
			$item.addEvent('mouseenter', function()
			{
				this.addClass('hover');
			}).addEvent('mouseleave', function()
			{
				this.removeClass('hover');
			}).addEvent('click', function()
			{
				document.location = url;
			}).css('cursor', 'pointer');
		});
		
		$('#right_simili span').each(function($span)
		{
			$span.append(['em']);
		});
	}
	
	if(I('dettaglio_info'))
	{
		$('#dettaglio_info span').each(function($span)
		{
			$span.append(['em']);
		});
	}
	
	if(I('right_modo'))
	{
		var modos = $('#right_modo .right-modo'), act = 0, modoLen = modos.length;
		
		modos.each(function($modo)
		{
			var url = $('a', $modo)[0].href;
			
			$modo.css({
				opacity: 0,
				zIndex: '1'
			}).addEvent('click', function()
			{
				document.location = url;
			});
		});
		
		modos[0].css('zIndex', '2').morph({
			css: {
				opacity: [0, 1]
			},
			time: 0.5,
			effect: EE.outCubic
		});
		
		setInterval(function() {
			
			modos[act].css('zIndex', '1').morph({
				css: {
					opacity: [1,0]
				},
				time: 0.5,
				effect: EE.outCubic
			});
			
			act = (++act % modoLen);
			
			modos[act].css('zIndex', '2').morph({
				css: {
					opacity: [0, 1]
				},
				time: 0.5,
				effect: EE.outCubic
			});
			
		}, 7000);
	}
	
	
	if(I('check_questions'))
	{
		I('check_questions').addEvent('click', function()
		{
			var a1, a2, a3, a4, a5, a6, a7, aas = {
				A: 0,
				B: 0,
				C: 0,
				D: 0,
				E: 0
			};
			
			$('input[name=question_1]').each(function($input)
			{
				if($input.checked)
				{
					a1 = $input.value;
					
					aas[a1]++;
				}
			});
			
			$('input[name=question_2]').each(function($input)
			{
				if($input.checked)
				{
					a2 = $input.value;
					
					aas[a2]++;
				}
			});
			
			$('input[name=question_3]').each(function($input)
			{
				if($input.checked)
				{
					a3 = $input.value;
					
					aas[a3]++;
				}
			});
			
			$('input[name=question_4]').each(function($input)
			{
				if($input.checked)
				{
					a4 = $input.value;
					
					aas[a4]++;
				}
			});
			
			$('input[name=question_5]').each(function($input)
			{
				if($input.checked)
				{
					a5 = $input.value;
					
					aas[a5]++;
				}
			});
			
			$('input[name=question_6]').each(function($input)
			{
				if($input.checked)
				{
					a6 = $input.value;
					
					aas[a6]++;
				}
			});
			
			
			$('input[name=question_7]').each(function($input)
			{
				if($input.checked)
				{
					a7 = $input.value;
					
					aas[a7]++;
				}
			});
			
			if(a1 && a2 && a3 && a4 && a5 && a6 && a7)
			{
				var max = 0, a, result, slug, desc;
				
				for(var i in aas)
				{
					if(aas[i] > max)
					{
						max = aas[i];
						
						a = i;
					}
				}
				
				switch(a)
				{
					case 'A':
					
						name = 'In centro';
						slug = 'in-centro';
						desc = 'La città è il tuo ambiente naturale e ti muovi al suo interno con grande naturalezza e disinvoltura. I servizi sono ciò che contano di più per te, così come la vicinanza ai posti che frequenti maggiormente. Sei un tipo "in centro", e per te abbiamo preparato degli splendidi appartamenti nel cuore pulsante della città.';
					
					break;
					case 'B':
						
						name = 'Un mini';
						slug = 'un-mini';
						desc = 'Sei un tipo giovane e ambizioso, sai gestire la tua vita e sai come vivere affrontando i problemi della vita quotidiana giorno per giorno. "Un mini" è la tipologia adatta a te, che vuoi contenere i costi senza privarti di stile e vicinanza alle tue frequentazioni abituali. Per te sono pronti ambienti organizzati e rifiniti con stile.';
						
					break;
					case 'C':
					
						name = 'In famiglia';
						slug = 'in-famiglia';
						desc = 'La famiglia su tutto! Tranquillità, passione per le piccole soddisfazioni di ogni giorno e amore per i tuoi cari fanno di te un tipo "In famiglia". Ambienti tranquilli, spaziosi e lontani dal caos del centro cittadino ti permettono di offrire ai tuoi familiari il posto giusto dove vivere. Per te abbiamo degli splendidi villini con finiture pietre faccia a vista, la nostra specialità';
					
					break;
					case 'D':
					
						name = 'Voglio il top';
						slug = 'voglio-il-top';
						desc = 'Alla tua vita non manca niente, ami gli agi e la ricercatezza di ambienti ampi e ben strutturati. Sei un tipo da "Voglio il top". Le nostre case singole, con ampi scoperti e garages, sono il luogo ideale per la tua comodità.';
					
					break;
					case 'E':
					
						name = 'Nido d\'amore';
						slug = 'nido-d-amore';
						desc = 'Sei sei un tipo da "Nido d\'amore" beh... stai vivendo il tuo rapporto di coppia come una bella favola e le belle favole meritano bellissime ambientazioni! Spazi pensati per le coppie giovani o collaudate, con le comodità necessarie alla vita per due e... perchè no: per eventuali bambini in arrivo!';
					
					break;
				}
				
				Env.scroll({
					left: 0,
					top: 0,
					effect: EE.outCubic,
					time: 0.7
				});
				
				
				I('dettaglio_left').morph({
					css: {
						opacity: [1, 0]
					},
					onFinish: function()
					{
						Ajax.get({
							url: BASE_URL + '/index.php?mdu=quiz/ajax&tipo=' + a,
							onFinish: function(t)
							{
								t = JSON.parse(t);
								
								if(t && t.success)
								{
									var $div = N(['div', {
										style: {
											opacity: 0
										},
										id: 'right_interessarti'
									}]);
									
									$div.innerHTML = '<h3>Case che potrebbero interessarti</h3>' + t.html;
									
									I('right_modo').after($div);
									
									I('right_interessarti').morph({
										css: {
											opacity: [0, 1]
										}
									});
								}
								
						
								$('#dettaglio_left h2')[0].replaceChilds('Sei un tipo "' + name + '"');
								
								I('quiz_content').innerHTML =
									'<div id="dettaglio_head" class="' + slug + '">' +
										'<h3>' + name + '</h3>' +
										'<p>' + desc + '</p>' +
									'</div>' +
									'<div id="quiz_link"><a href="' + BASE_URL + '/immobili/' + slug + '.html">Guarda tutte le case Bolzani che fanno per te</a></div>';
									
								I('dettaglio_left').morph({
									css: {
										opacity: [0, 1]
									}
								});
								
							}
						});
					}
				});
				


			}
		});
	}
	
	
	Require.module(['show', 'lightshow'], function()
	{
		LightShow.init();
	});
});

