/* Nome Cliente 	SandriniScale x ETIKASTAIRS.IT */
/* Creato:			15/09/2008 */
/* Autore:			simone@evoluzionetelematica.it */
/* Ultima Modifica:	gg/mm/aaaa	Autore: Nome Cognome *///<![CDATA[

var etika = {

    // Utilizzare una variabile per fare riferimento al file SWF incorporato.

	startLoad: function(){
		if ($('slideshow')) etika.injectFlash()
		if ($$('.scroll') != '') etika.scrollbar()
		if ($('mask')) etika.scrollerContent() // il div MASK è presente solo se uso lo scroller orizzontale
		if ($$('.formInfo') != '') etika.initForm()
	},
	
	startDomReady: function(){
		//if ($$('h1') != '') etika.mysIFR()
		if ($('mask')) etika.initGallery()
		if ($('myForm')) etika.initSqueezeBox()
		if ($('myForm')) etika.send()
	},	

	injectFlash: function() // inietto il file swf nel codice
	{

		var myFlash = new Swiff('slideshow.swf', {
			id: "slideshow",
			width:  870, 
			height: 335, 
			container: $('slideshow'),
			vars: {file: 'xml/slideHome.xml'},
			events: {
				onLoad: function() {
					//alert("Flash is loaded!")
				}
			}
		});
		var myMusic = new Swiff('music.swf', {
			id: "music",
			width:  4, 
			height: 4, 
			container: $('music'),
			events: {
				onLoad: function() {
					//alert("Flash is loaded!")
				}
			}
		});		

	},
	
	scrollbar: function() // Usata per la Scrollbar dei testi
	{
		var myScroll = new MooScroll({selector:'.scroll'});
	},
	
	scrollerContent: function() // usato per lo scroller orizzontale
	{
		var mask = $('mask');
		var content = $('contenuti');
		var elements = $$('#contenuti li');
		var count = elements.length; // numero di elementi contenuti nell' UL contenuti
		var largh = 480 * count; // larghezza da assegnare al div CONTENUTI in base al numero di elementi presenti in esso

		content.setStyle('width', largh); //imposto la larghezza di "Contenuti" in base agli elementi presenti in esso

		// Scroller destra e sinistra
		var myScroller = new Scroller(mask, {
									  	area: Math.round(window.getWidth() / 3),
										velocity: 0.1
		});
		myScroller.start();
		mask.addEvent('mouseover', myScroller.start.bind(myScroller));
		mask.addEvent('mouseout', myScroller.stop.bind(myScroller));
		
		// Scroll iniziale per portere il testo in centro peagina
		var myFx = new Fx.Scroll(mask, {
			offset: {
				'x': -((document.body.offsetWidth/2)+20), // il 20 è il margin del "riferimento"
				'y': 0
			},
			wheelStops:false
		}).toElement('riferimento');
		
		
	},
	
	initGallery: function() { // Inizializzo la gallery delle foto con zoom
		Milkbox = new Milkbox();
	},

	initSqueezeBox: function() // Inizializzo lo squuezebox x effetto lightbox x iFrame
	{
		SqueezeBox.assign($$('a.boxed'), {
			parse: 'rel'
		});

	}, // Fine initSqueezeBox()
	/*
	mysIFR: function () {
		
		// calcolo il percorso del file font.swf in base alla cartella in cui mi trovo (x le lingue)
		
		var path = location.pathname;
		var li = path.length;
		var lf = path.replace(/\//g,'').length;
		var n = li-lf-2;
		var result = "";
		
		for(var i=0; i<n; i++)
		{
		  result += "../";
		}
		
		result += 'js/perpetua.swf';
		// fine calcolo persorso font.swf
		
		var perpetua = {
			src: result
			,ratios: [7,1.32,11,1.31,13,1.24,14,1.25,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16]
		};

		// You probably want to switch this on, but read <http://wiki.novemberborn.net/sifr3/DetectingCSSLoad> first.
		//sIFR.useStyleCheck = true;
		sIFR.activate(perpetua);
		
		sIFR.replace(perpetua, {
			selector: 'h1, h2'
			,wmode: 'transparent'
			,css: [
			  '.sIFR-root { text-align: center; color:#FFFFFF;}'
			  ,'a { text-decoration: none; }'
			  ,'a:link { color: #000000; }'
			  ,'a:hover { color: #CCCCCC; }'
			]
			,filters: {
			  DropShadow: {
				knockout: false
				,distance: 1
				,color: '#000000'
				,strength: 2
			  }
			}

		})
	}, // fine mysIFR
	*/
	// METODI X FORM	
	initForm: function()
	{

		var list = new Array;
		
		var myInput = $$('.formInfo label input');
		var myTextarea = $$('.formInfo label textarea');
		var mySelect = $$('.formInfo label select');
		
		var list = list.concat(myInput, myTextarea, mySelect)
		
		list.each(function(element) {


			var myEffects = new Fx.Morph(element, {duration: 300, transition: Fx.Transitions.Sine.easeOut});


			element.addEvent('focus', function(){
				myEffects.start({
					'background-color': '#FF9'
				});
			})

			element.addEvent('blur', function(){
				myEffects.start({
					'background-color': '#FFF'
				});
			})			
				
		});
		// loop through all anchor tags
	},

	sfondoRisposta: function() {

			// Costruisco i div contenitori del messaggio
			//SFONDO NERO SCURO
			var mySfondo = new Element('div', {
				'id': 'sfondo',
				'styles': {
					'position': 'absolute',
					'top': 0,
					'left': 0,
					'z-index': 200,
					'display': 'block',
					'width': '100%',
					'height': '100%',
					'background-color': '#000'
				},
				'events': {
					'load': function(){
						alert('piero')
					},					
					'click': function(){
						this.dispose();
						myRisposta.dispose();
						myBtnClose.dispose();
					},
					'mouseover': function(){
						//alert('mouseovered');
					}
				}
			});
			//DIV X TESTI
			var myRisposta = new Element('div', {
				'id': 'risposta',
				'styles': {
					'display': 'block',
					'position': 'absolute',
					'top': '50%',
					'left': '50%',
					'z-index': 200,
					'width': '360px',
					'height': '360px',
					'margin': '-200px 0 0 -200px',
					'padding': '20px',
					'background-color': '#FFF',
					'color': '#F00'
				},
				'events': {
					'click': function(){
						this.dispose();
						mySfondo.dispose();
						myBtnClose.dispose();
					},
					'mouseover': function(){
						//alert('mouseovered');
					}
				}
			});
			//DIV X TESTI
			var myBtnClose = new Element('img', {
				'id': 'close',
				'src': 'img/closebox-trans.png',
				'width': '30px',
				'height': '30px',
				'alt': 'Chiudi',
				'styles': {
					'display': 'block',
					'position': 'absolute',
					'top': '50%',
					'left': '50%',
					'z-index': 201,
					'margin': '-215px 0 0 185px'
				},
				'events': {
					'click': function(){
						this.dispose();
						myRisposta.dispose();
						mySfondo.dispose();
					},
					'mouseover': function(){
						//alert('mouseovered');
					}
				}
			});			
			
			mySfondo.setStyle('opacity', 0.8);
			mySfondo.inject('container', 'after');
			myRisposta.inject(mySfondo, 'after');
			myBtnClose.inject(mySfondo, 'after');

	},
	
	/* Meetodo per Spedire la FORM con Ajax */
	send: function(){

		$('myForm').addEvent('submit', function(e) {
			// Prevent the submit event
			new Event(e).stop();

			etika.sfondoRisposta()
			
			// This empties the log and shows the spinning indicator
			var log = $('risposta').empty().addClass('loading');
			
			//send takes care of encoding and returns the Ajax instance.
			//onComplete removes the spinner from the log.
			
			this.set('send', {onComplete: function(response) {
				
				//alert(response)
				
				log.removeClass('loading');
				
				log.set('html', response);

				// se nel codice HTML compare uno SPAN con ID "emailSpedita" azzero i campi del form
				if ($('emailSpedita')) {
					
					$('nome').setProperty('value', '');
					$('azienda').setProperty('value', '');
					$('email').setProperty('value', '');
					$('telefono').setProperty('value', '');
					$('messaggio').setProperty('value', '');
					$('autorizzo').checked = false;
					
				}
				
			}});
			//Send the form.
			this.send();
			
		});		
	}	// Fine Send()	
	 
} // chiusura classe ETIKA

///////////////////////////////////////////////////////

window.addEvent('domready', etika.startDomReady);
window.addEvent('load', etika.startLoad);
//]]>
