
window.addEvent('domready', function() {
									 
									 
//TTIPS  
    	var tipz = new Tips('.tipz',{  
         	className: 'tipzz',  
         	//fixed: true,  
         	hideDelay: 5,  
         	showDelay: 50  
     	});

// AJAX CALLS

	//1
	
	 $$('.t-type').addEvent('click', function(event) {  
        //prevent the page from changing  
         event.stop();  
         //make the ajax call, replace text
		//var ct = document.getElementById('loaderboxmsg');
		if(Browser.Engine.trident4){}else{
			
			var myMorphb = new Fx.Morph('loaderbox',{'duration':500,transition: Fx.Transitions.Expo.easeOut});  
         		myMorphb.start({
							  'height': 120, //Morphs the height from the current to 100px.
    						  'width': 120,   //Morphs the width from the current to 300px.
							  'opacity': 0.8
							  
							  });
			
			}
		
				
				
		
		$('loaderbox').innerHTML="<p style=\"text-align:center\"></p>";
		//$('loaderbox').setStyle('background','url(img/layout/loading.gif) #fff no-repeat center center');
         $('loaderbox').addClass('mbLoading');
		
		
		
		
		
		
		var req = new Request.HTML({  
             method: 'get',  
             url: this.get('href'),  
             data: { 'do' : '1' },  
             onRequest: function() { 
				
				
				//alert("loading in progress");
				//$('loaderbox').setHTML('Richiesta fallita');
				//do effect  
				//
				//alert("requsting...");
         		
				
				},
				
             update: $('loaderbox'),
			 
             onComplete: function(response) { 
			 //$('loaderbox').setStyle('background-image','none');
			 $('loaderbox').removeClass('mbLoading');
			
			 	var myMorph = new Fx.Morph('loaderbox',{'duration':1100,transition: Fx.Transitions.Expo.easeOut});  
         		myMorph.start({
							  'height': 325, //Morphs the height from the current to 100px.
    						  'width': 525,   //Morphs the width from the current to 300px.
							  'opacity': 1
							  
							  });			
             }  
         }).send();  
     });  
	
	
	//2
	
	
	// AJAX CALLS
	
	 $$('.tb-type').addEvent('click', function(event) {  
        //prevent the page from changing  
         event.stop();  
         //make the ajax call, replace text
		//var ct = document.getElementById('loaderboxmsg');
		if(Browser.Engine.trident4){}else{
			
			var myMorphb = new Fx.Morph('loaderboxb',{'duration':500,transition: Fx.Transitions.Expo.easeOut});  
         		myMorphb.start({
							  'height': 120, //Morphs the height from the current to 100px.
    						  'width': 120,   //Morphs the width from the current to 300px.
							  'opacity': 0.8
							  
							  });
			
			}
		
				
				
		
		$('loaderboxb').innerHTML="<p style=\"text-align:center\"></p>";
		//$('loaderbox').setStyle('background','url(img/layout/loading.gif) #fff no-repeat center center');
         $('loaderboxb').addClass('mbLoading');
		
		
		
		
		
		
		var req = new Request.HTML({  
             method: 'get',  
             url: this.get('href'),  
             data: { 'do' : '1' },  
             onRequest: function() { 
				
				
				//alert("loading in progress");
				//$('loaderbox').setHTML('Richiesta fallita');
				//do effect  
				//
				//alert("requsting...");
         		
				
				},
				
             update: $('loaderboxb'),
			 
             onComplete: function(response) { 
			 //$('loaderbox').setStyle('background-image','none');
			 $('loaderboxb').removeClass('mbLoading');
			
			 	var myMorph = new Fx.Morph('loaderboxb',{'duration':1100,transition: Fx.Transitions.Expo.easeOut});  
         		myMorph.start({
							  'height': 325, //Morphs the height from the current to 100px.
    						  'width': 525,   //Morphs the width from the current to 300px.
							  'opacity': 1
							  
							  });			
             }  
         }).send();  
     });  
	

	


////////// SCROLLS
			

			var myScroll = new Fx.Scroll('mystage', {
				wait: false,
				duration: 1600,
				transition: Fx.Transitions.Quad.easeOut
			});



			$('gotohome').addEvent('click', function(event) {
				event = new Event(event).stop();
				myScroll.toElement('home');
				mapClean();
				
			});
			
			
			$('gotohouses').addEvent('click', function(event) {
				event = new Event(event).stop();
				myScroll.toElement('houses');
				mapClean();
				$$('.innerLoaderBox').destroy();
				//alert("gotohoyuses");
			
			});
			
			
			$('gotolocation').addEvent('click', function(event) {
				event = new Event(event).stop();
				myScroll.toElement('location');
				mapClean();
				$$('.innerLoaderBox').destroy();
				
				
			});
	
	
			$('gotocontacts').addEvent('click', function(event) {
				event = new Event(event).stop();
				myScroll.toElement('contacts');
				mapClean();
				$$('.innerLoaderBox').destroy();
				
			});
			
			$('gotolameta').addEvent('click', function(event) {
				event = new Event(event).stop();
				myScroll.toElement('lameta');
				mapClean();
				$$('.innerLoaderBox').destroy();
				
			
			});
			

			
/////////////////////
		
		//MAP SETUP
			
		
			
		var Gmapsbox = new Class({
			
			Implements:Options,
			
			options:{
			//overlayOpacity:0.4,
			initialWidth:800,
			initialHeight:0,
			resizeDuration:2000,
			resizeTransition:'expo:in:out'

			},
			
			initialize: function(options){
				this.initGmapsbox();
				this.activated = false;
				this.closed = true;
				this.setOptions(options);
				
			},//end init
			
			initGmapsbox: function(){
				//alert('inizializzo gmapbox');
				this.setupHTML();
				this.setupEffects();
				this.setupEvents();
				

				
			},
			
			shout: function(){
			alert('shout');
			},
			
			showMap: function(){
			//alert('showing map');
			///////####this.overlay.setStyles({ 'top': -$(window).getScroll().y,'height':$(window).getScrollSize().y+$(window).getScroll().y });
		
			this.center.addClass('mbLoading');
			this.center.setStyle('top',125);
			this.center.tween('opacity',1);
			//this.center.tween('width',820);
			//this.center.tween('height',400);
			
			var targetSize = {};
			targetSize.height = 378;
			targetSize.width = 800;
			this.center.morph(targetSize);//onComplete: show all items
		
			///////####this.overlay.tween('opacity',this.options.overlayOpacity);//onComplete: center.tween opacity
			
			
			},
			
			printMap: function(){
			//alert ('outputting map');
			this.center.removeClass('mbLoading');
			
			this.mLayer = new Element('div', { 'id':'maplayer','styles':{ 'opacity':'0','visibility':'visible','background':'red','z-index':'99' }}).inject(this.center);
			//this.mapLayer.inject($('mbCenter'));
			this.center.innerHTML='<div id="mapLayer" style="width:800px; height:380px; z-index:109; position:absolute"></div><div id="hidemap" style="width:65px; height:55px; z-index:120; position:absolute; top:0; left:380px;cursor:pointer"><img src="img/layout/closemap.gif" title="Close map"/></div>';
			this.map = new GMap2($('mapLayer'));
			
			this.RM_HTML = '<div style="width: 210px; padding-right: 10px">Residenza Marganai</div>';
			this.PO_HTML = '<div style="width: 210px; padding-right: 10px">Porto</p></div>';
			this.AE_HTML = '<div style="width: 210px; padding-right: 10px">Aeroporto</div>';
			
			
			
			this.map.addControl(new GLargeMapControl());
			this.map.enableScrollWheelZoom();
			this.map.addControl(new GMapTypeControl());
			this.map.addControl(new GOverviewMapControl());	
			this.map.setCenter(new GLatLng(39.304570624805464,8.56359601020813), 10);		
				// Place a marker in the center of the map and open the info window
				// automatically
			this.marker = new GMarker(this.map.getCenter());				
			this.map.addOverlay(this.marker);
			
			//this.marker.openInfoWindowHtml(this.RM_HTML);
			this.map.panTo(new GLatLng(39.36,8.87),10);
			
			this.iconBlue = new GIcon(); 
			this.iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
			this.iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
			this.iconBlue.iconSize = new GSize(12, 20);
			this.iconBlue.shadowSize = new GSize(22, 20);
			this.iconBlue.iconAnchor = new GPoint(6, 20);
			this.iconBlue.infoWindowAnchor = new GPoint(5, 1);
					
			this.porto = new GMarker(new GLatLng(39.211773,9.111786),this.iconBlue);                         
  			this.map.addOverlay(this.porto);
			
			this.aereoporto = new GMarker(new GLatLng(39.249005,9.057198),this.iconBlue);                         
  			this.map.addOverlay(this.aereoporto);
			
			this.funtanamare = new GMarker(new GLatLng(39.28827632318578,8.436555862426758),this.iconBlue);                         
  			this.map.addOverlay(this.funtanamare);
			
		
			this.nebida = new GMarker(new GLatLng(39.33247177216473,8.420634269714355),this.iconBlue);                         
  			this.map.addOverlay(this.nebida);	
			
			this.caladomestica = new GMarker(new GLatLng(39.37320579000698,8.380250930786133),this.iconBlue);                         
  			this.map.addOverlay(this.caladomestica);	
			
			
			GEvent.addListener(this.marker, "click", function() {
				myGMpopup('<div style="width: 210px; padding-right: 10px">Residenza Marganai</div>');
			});		
			
			GEvent.addListener(this.porto, "click", function() {
				myGMpopupPorto('<div style="width: 210px; padding-right: 10px">Porto</p></div>');
			});
			
			GEvent.addListener(this.aereoporto, "click", function() {
				myGMpopupAereoporto('<div style="width: 210px; padding-right: 10px">Aeroporto</p></div>');
			});
			
			GEvent.addListener(this.funtanamare, "click", function() {
				myGMpopupFuntanamare('<div style="width: 210px; padding-right: 10px">Funtanamare - 11 Km.</p></div>');
			});

			GEvent.addListener(this.nebida, "click", function() {
				myGMpopupNebida('<div style="width: 210px; padding-right: 10px">Nebida - 14 Km.</p></div>');
			});
			GEvent.addListener(this.caladomestica, "click", function() {
				myGMpopupCaladomestica('<div style="width: 210px; padding-right: 10px">Cala Domestica - 28 Km.</p></div>');
			});			
			
			
			
			$('hidemap').addEvent('click',function(){this.closeMap(); }.bindWithEvent(this));
			},
			
			GMpopup: function (popupMessage){
			this.marker.openInfoWindowHtml(popupMessage);			
			},
			GMpopupPorto: function (popupMessage){
			this.porto.openInfoWindowHtml(popupMessage);			
			},			
			GMpopupAereoporto: function (popupMessage){
			this.aereoporto.openInfoWindowHtml(popupMessage);			
			},	
			GMpopupFuntanamare: function (popupMessage){
			this.funtanamare.openInfoWindowHtml(popupMessage);			
			},
			GMpopupNebida: function (popupMessage){
			this.nebida.openInfoWindowHtml(popupMessage);			
			},
			GMpopupCaladomestica: function (popupMessage){
			this.caladomestica.openInfoWindowHtml(popupMessage);			
			},			
			
			closeMap: function(){
			//alert('closing map');
			GUnload();
			this.cancelAllEffects();
			///////####this.overlay.tween('opacity',0);//see onComplete in prepareEvents() 
			this.center.setStyles({'width':this.options.initialWidth,'height':0});
			this.center.tween('opacity',0);//see onComplete in prepareEvents() 
			this.map = null;
			this.center.innerHTML = "";
			this.mode = null;
			},
			
			cancelAllEffects:function(){
			///////####this.overlay.get('tween').cancel();
			this.center.get('morph').cancel();
			this.center.get('tween').cancel();
			this.center.retrieve('setFinalHeight').cancel();
		
			},
			
			setupHTML:function(){		
			if(!Browser.Engine.trident4){
				//alert('not ie6');

			};
				
			///////####this.overlay = new Element('div', { 'id':'mbOverlay','styles':{ 'opacity':'0','visibility':'visible' }}).inject($(document.body));
			this.center = new Element('div', {'id':'mbCenter', 'styles':{'width':this.options.initialWidth,'height':this.options.initialHeight,'marginLeft':0,'opacity':0,'position':'absolute','left':0, 'top':0}}).inject($('wrapper'));
			this.close = new Element('a',{'id':'mbCloseLink'});
		

			},
			
			setupEffects:function(){
			///////####this.overlay.set('tween',{ duration:'short',link:'cancel' });
			this.center.set('tween',{ duration:'short',link:'chain' });
			this.center.set('morph',{ duration:this.options.resizeDuration,link:'chain',transition:this.options.resizeTransition });
			this.center.store('setFinalHeight',new Fx.Tween(this.center,{property:'height',duration:'short'}));
		
			},
			
			
			setupEvents: function(){
			this.center.get('morph').addEvent('onComplete',function(){this.printMap();}.bindWithEvent(this));
			///////####$(this.overlay).addEvent('click',function(){ this.closeMap(); }.bindWithEvent(this));
			
			}
			
			
		});//END MILKBOX;


		 var myGmapsbox = new Gmapsbox();

			$('openMap').addEvent('click', function(event) {
				event = new Event(event).stop();
				myGmapsbox.showMap();
			});
			
		
		//access to openInfoWindowHtml method
		var myGMpopup = function(popupMsg){			
			myGmapsbox.GMpopup(popupMsg);
			
			}
			
		var myGMpopupPorto = function(popupMsg){			
			myGmapsbox.GMpopupPorto(popupMsg);
			
			}
			
		var myGMpopupAereoporto = function(popupMsg){			
			myGmapsbox.GMpopupAereoporto(popupMsg);
			
			}
			
		var myGMpopupFuntanamare = function(popupMsg){			
			myGmapsbox.GMpopupFuntanamare(popupMsg);
			
			}

		var myGMpopupNebida = function(popupMsg){			
			myGmapsbox.GMpopupNebida(popupMsg);
			
			}
		var myGMpopupCaladomestica = function(popupMsg){			
			myGmapsbox.GMpopupCaladomestica(popupMsg);
			
			}
		
		
		
		
		///////////////////////
			
		var mapClean = function(){ 
		if ($('mapLayer')){ 
			
			myGmapsbox.closeMap();
			
			}else{}
		
		}	
			


	
			

 });



