/* Nome Cliente 	laccio.com */
/* Creato:			9/10/2008 */
/* Autore:			simone@evoluzionetelematica.it */
/* Ultima Modifica:	gg/mm/aaaa	Autore: Nome Cognome *///<![CDATA[


var laccio = {
	
	startLoad: function(){
		
		//if ($('container')) $('container').tween('opacity' , 1) // Effetto FADe di CONTAINER
		
		if ($$('.scroll') != '') laccio.scrollbar()
		if ($('prodotti')) laccio.scrollerContent()
		if ($('cornerShops')) laccio.scrollerCornerShops()
		if ($('exclusiveShops')) laccio.scrollerExclusiveShops()
		if ($('prodotti'))	laccio.initProdotto();
		if ($('exclusiveShops')) laccio.initGallery()
		//if ($$('.formInfo')) laccio.initForm()
	},
	
	startDomReady: function(){
		
		if ($$('.boxed') != '') laccio.initSqueezeBox()
		
		//$('container').setStyle('opacity' ,0) // Setto a 0 L'opacità del container x far fare l'effetto FADE in entrata di pagina
		
		objActive = null; // variabile usata x sapere quale oggetto è attivo

		if ($('prodotti')) laccio.initDettagli()
		if ($('exclusiveShops')) laccio.initShops()
		//if ($('myForm')) laccio.send()
	},	

	// COLLEZIONE 2008
	
	scrollerContent: function() // usato per lo scroller verticale dei prodotti
	{
		var container = $('container');
		var prodotti = $('prodotti');
		//var elements = $$('#contenuti li');
		var containerHeight = container.getStyle('height').toInt(); // numero di elementi contenuti nell' UL contenuti

		// Scroller destra e sinistra
		var myScroller = new Scroller(prodotti, {
									  	area: Math.round(containerHeight/2),
										velocity: 0.1
		});
		myScroller.start();
		prodotti.addEvent('mouseover', myScroller.start.bind(myScroller));
		prodotti.addEvent('mouseout', myScroller.stop.bind(myScroller));
		
	},
	
	fadeDettaglio: function(obj, stato)
	{
		
		if (stato) {// mostro il dettaglio

				if(objActive) {

					objActive.setStyle('display', 'none') // se esiste un oggetto aperto lo chiudo
					objActive.setStyle('opacity', 0);
				}
				
				obj.setStyle('display', 'block') // abilito l'oggetto cliccato
				obj.tween('opacity', 1); 
				var contImgDettaglio = obj.getFirst() // Primo nodo di DL -> DD che contiene l'img SHIM
				var ImgDettaglio = contImgDettaglio.getFirst() // IMG SHIM
				//ImgDettaglio.setProperty('src', 'img/prodotti/big/'+ImgDettaglio.getProperty('id')+'.jpg')
			  ImgDettaglio.setProperty('src', ImgDettaglio.getProperty('rel'))
				
				objActive = obj; // Setto la variabile objActive con l'oggetto cliccato
		} 
		else {// nascondo il dettaglio
			
			obj.tween('opacity', 0)
			
		}

	},

	initProdotto: function() // inizializzo il click sulle thumb dei prodotti
	{

		var myBtnClose = new Element('img', {
			'id': 'close',
			'src': 'img/btn-close-dettaglio.gif',
			'width': '28px',
			'height': '28px',
			'alt': 'Chiudi',
			'styles': {
				'display': 'block',
				'position': 'absolute',
				'top': '50%',
				'left': '50%',
				'z-index': 201,
				'margin': '0 0 0 0'
			},
			'events': {
				'click': function(){
					//
				},
				'mouseover': function(){
					//alert('mouseovered');
				}
			}
		});	
		
		var arrayProdotti = $$('#collezione .prodotto .thumb'); // tutte le Thumb dei Prodotti

		arrayProdotti.each(function(element) {
			
			//var myEffects = new Fx.Morph(element, {duration: 200, transition: Fx.Transitions.linear});
			
			element.addEvent('click', function(){

			
				var prodotto = this.getParent() // prendo l'oggetto .PRODOTTO
				var dettaglio = prodotto.getChildren().filter('.dettaglio'); // prendo l'oggetto .DETTAGLIO
				
				laccio.fadeDettaglio (dettaglio, true) // mostro il dettaglio della THUMB cliccata
									
				
				dettaglio.addEvent('click', function(){ // associo al click sul dettaglio la chiusura dalla pop up
					laccio.fadeDettaglio (this, false) // nascondo il detaglio
				})				
				
				
			})
		
		});
		
	},

	initDettagli: function() // Nascondo i dettagli dei prodotti al caricamento di pagina
	{
		var arrayProdotti = $$('#prodotti li .dettaglio'); // elenco dei dattagli del prodotto
	
		arrayProdotti.each(function(element) {
			element.setStyle('display', 'none') // nascondo i dettagli
			element.setStyle('opacity', 0) // setto l'opacità dei dettagli a 0
		});
	},
	
	scrollbar: function() // Usata per la Scrollbar dei testi
	{
		var myScroll = new MooScroll({selector:'.scroll'});
	},
	
	// PUNTI VENDITA
	
	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()
	
	scrollerCornerShops: function() // usato per lo scroller verticale dei punti vendita
	{
		var shops = $('cornerShops');

		// Scroller up/down
		var myScroller = new Scroller(shops, {
									  	//area: Math.round(containerHeight/2),
										area: Math.round(225),
										velocity: 0.1
		});
		myScroller.start();
		//shops.addEvent('mouseover', myScroller.start.bind(myScroller));
		//shops.addEvent('mouseout', myScroller.stop.bind(myScroller));
		
	},	
	
	scrollerExclusiveShops: function() // usato per lo scroller verticale dei punti vendita
	{
		var shops = $('exclusiveShops');

		// Scroller up/down
		var myScroller = new Scroller(shops, {
									  	//area: Math.round(containerHeight/2),
										area: Math.round(225),
										velocity: 0.1
		});
		myScroller.start();
		//shops.addEvent('mouseover', myScroller.start.bind(myScroller));
		//shops.addEvent('mouseout', myScroller.stop.bind(myScroller));
		
	},	
	
	initShops: function()
	{
		
		
		var shops = $$('#exclusiveShops .exclusiveShop')
		var fotografie = $$('#exclusiveShops .exclusiveShop .fotografie')
		
		// NASCONDO LE FOTOGRAFIE DEI PUNTI VENDITA
		fotografie.each(function(element) {
			element.setStyle('opacity' ,0)		
		})
		
		shops.each(function(element) {
		
			element.addEvent('mouseover', function(){
				
				if (element.getChildren().filter('.fotografie')) {
					
					var fotografie = element.getChildren().filter('.fotografie');
					//fotografie.setStyle('opacity' ,1)
					fotografie.tween('opacity' , 1)
				}
				
			});
			
			element.addEvent('mouseout', function(){

				if (element.getChildren().filter('.fotografie')) {
					var fotografie = element.getChildren().filter('.fotografie');
					//fotografie.setStyle('opacity' ,0)
					fotografie.tween('opacity' , 0)
				}
			})			
		})
	},
	
	// 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: 200, transition: Fx.Transitions.linear});


			element.addEvent('focus', function(){
				myEffects.start({
					'background-color': '#90C',
					'color': '#FFF'
				});
			})

			element.addEvent('blur', function(){
				myEffects.start({
					'background-color': '#FFF',
					'color': '#000'
				});
			})			
				
		});
		// 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();

			laccio.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')) {
					
					
					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) {
					
						element.setProperty('value', '');
						if ( element.getProperty('type') ==  'checkbox'){
							element.setProperty('checked', false);						
						}
						
					
					})				

				}
				
			}});
			//Send the form.
			this.send();
			
		});		
	}	// Fine Send()	
	 
} // chiusura classe laccio

///////////////////////////////////////////////////////

window.addEvent('domready', laccio.startDomReady);
window.addEvent('load', laccio.startLoad);

//]]>
