
	
/*
	Variabili locali
*/
/*var idContainerDettaglio = "ProductBrowser-1";
var idContainerElencoProdotti = "containerElenco";
var offsetTime = 1000;
var s_nonDefinito = 0;
var s_dettaglio = 1;
var s_elencoProdotti = 2;

/*
	Automa a stati finiti che permette di gestire in modo trasparente
	ad altri js gli effetti sugli oggetti della pagina
*/
/*function loopManager(stato)
{
	var almenoUno = false;
	if(typeof $('#'+idContainerDettaglio) != undefined)
	{ 
		if(stato == s_dettaglio)
		{ 
			// qui fai quello che devi nel caso di container dettaglio dopo l'inizializzazione 
			// ...  possibile che non si debba fare nulla ...
			var sortByPanelDefault = $('.ecwid-results-topPanel-sortByPanel .gwt-Label').text();
			$('select.gwt-ListBox option').each(function(){
				if($(this).attr('value') == 'normal'){
					$(this).text(sortByPanelDefault).css({});
				}
			});
			
			//alert(sortByPanelDefault);
			setTimeout( 'loopManager(s_dettaglio);', offsetTime);
			almenoUno = true;
		}
		if(stato == s_nonDefinito)
		{
			// qui fai quello che devi nel caso di container dettaglio a livello di inizializzazione
			
			
			setTimeout( 'loopManager(s_dettaglio);', offsetTime);
			stato = s_dettaglio;
			almenoUno = true;
		}
	}
	if(typeof $('#'+idContainerElencoProdotti) != undefined)
	{ 
		if(stato == s_elencoProdotti)
		{ 
			// qui fai quello che devi nel caso di container elenco prodotti dopo l'inizializzazione 
			// ...  possibile che non si debba fare nulla ...
			setTimeout( 'loopManager(s_elencoProdotti);', offsetTime);
			almenoUno = true;
		}
		if(stato == s_nonDefinito)
		{
			// qui fai quello che devi nel caso di container elenco prodotti a livello di inizializzazione
			setTimeout( 'loopManager(s_elencoProdotti);', offsetTime);
			stato = s_elencoProdotti;
			almenoUno = true;
		}
	}
	if(stato == s_nonDefinito || !almenoUno) setTimeout( 'loopManager(s_nonDefinito);', offsetTime);
}

// Chiamata iniziale ...
setTimeout('loopManager(s_nonDefinito);',offsetTime);
	*/
	
	
/* Variabili locali */
var idContainerDettaglio = "ProductBrowser-1";
var idContainerElencoProdotti = "containerElenco";
var offsetTime = 100;
var s_nonDefinito = 0;
var s_dettaglio = 1;
var s_elencoProdotti = 2;

/*
	Automa a stati finiti che permette di gestire in modo trasparente
	ad altri js gli effetti sugli oggetti della pagina
*/
function loopManager(stato)
{
	var almenoUno = false;
	if(typeof $('#'+idContainerDettaglio) != undefined)
	{ 
		if(stato == s_dettaglio)
		{ 
			// qui fai quello che devi nel caso di container dettaglio dopo l'inizializzazione 
			// ...  possibile che non si debba fare nulla ...
			
			var sortByPanelDefault = $('.ecwid-results-topPanel-sortByPanel .gwt-Label').text();
			$('select.gwt-ListBox option').each(function(){
				if($(this).attr('value') == 'normal'){
					$(this).text(sortByPanelDefault).css({'color':'#666'});
				}
			});
			
			var currentLang = $('#lang_sel .lang_sel_sel img').attr('alt');
			$('body').addClass(currentLang);
			
			if($('body').hasClass('en')){
				$('.description-it').hide();
			} else {
				$('.description-en').hide();
			}
			
			$('.ecwid-productBrowser-categoryPath-storeLink').hide();
			$('.ecwid-productBrowser-categoryPath-separator-first').hide();

			
			$('body').find('a[href="http://www.capitanart.it/en/shop-en/"]').attr('href','http://www.capitanart.it/en/shop-en/#ecwid:category=754299&mode=category&offset=0&sort=normal');
			$('body').find('a[href="http://www.capitanart.it/shop/"]').attr('href','http://www.capitanart.it/shop/#ecwid:category=754299&mode=category&offset=0&sort=normal');

			/*
			if($('.ecwid-productBrowser-head').length>0){
				var mainTitle = $('.ecwid-productBrowser-head').text();
				$('title').text(mainTitle);
				$('meta[name=description]').attr('content',mainTitle);
			}
			*/
			
			if($('.ecwid-productBrowser-details-thumbnail').length>0 && $('meta[property=og:image]').length<1 && $('meta[property=og:title]').length<1){
				var mainThumb = $('.ecwid-productBrowser-details-thumbnail img').attr('src');
				$('<meta property="og:image" content="'+mainThumb+'" />').appendTo('head');
				$('<meta property="og:title" content="'+mainTitle+'" />').appendTo('head');
			
			}
			
			
			$('.ecwid-productBrowser-sku').each(function(){
				var discount = $(this).text();
				var cleanDiscount = '-' + discount.substr(discount.indexOf("-") + 1);
				if($(this).siblings('.discount-listing').length<1){
					if (discount.indexOf('-') > -1) {
					    $('<span class="discount-listing" />').insertAfter(this);
						$(this).next('.discount-listing').text(cleanDiscount);
					} 					
				}
			});

			
			//addDebugText('stato == s_dettaglio');
			setTimeout( 'loopManager(s_dettaglio);', offsetTime);
			almenoUno = true;
		}
		if(stato == s_nonDefinito)
		{
			// qui fai quello che devi nel caso di container dettaglio a livello di inizializzazione
			//addDebugText('stato == s_nonDefinito');
			setTimeout( 'loopManager(s_dettaglio);', offsetTime);
			stato = s_dettaglio;
			almenoUno = true;
			
		}
	}
	if(typeof $('#'+idContainerElencoProdotti) != undefined)
	{ 
		if(stato == s_elencoProdotti)
		{ 
			// qui fai quello che devi nel caso di container elenco prodotti dopo l'inizializzazione 
			// ...  possibile che non si debba fare nulla ...
			//addDebugText('stato == s_elencoProdotti');
			setTimeout( 'loopManager(s_elencoProdotti);', offsetTime);
			almenoUno = true;
		}
		if(stato == s_nonDefinito)
		{
			// qui fai quello che devi nel caso di container elenco prodotti a livello di inizializzazione
			//addDebugText('stato == s_nonDefinito');
			setTimeout( 'loopManager(s_elencoProdotti);', offsetTime);
			stato = s_elencoProdotti;
			almenoUno = true;
		}
	}
	if(stato == s_nonDefinito || !almenoUno) 
	{
		//addDebugText('stato == s_nonDefinito || !' + ((!almenoUno)?'false':'true'));
		setTimeout( 'loopManager(s_nonDefinito);', offsetTime);
	}
}

var debugCounterRow = 0;
function addDebugText(t)
{
	if(t.length > 0)
	{	
		var obj = document.getElementById('debugBox');
		if(obj) obj.innerHTML = '' + debugCounterRow + ' - ' + t + obj.innerHTML;
	}
}

/* Chiamata iniziale ... */
setTimeout('loopManager(s_nonDefinito);',offsetTime);	
	
$(document).ready(function() { 
		
		
		
// ---- Banner Home ----------------------------------------------------------------------------------------------------------
	
	var interval;
	
	$('ul#ecwid-featured-products')
	.roundabout({
	minOpacity: 0.2, // invisible!
	minScale: 0.1, // tiny!
	maxScale: 1.6
	
	    })
		.hover(
			function() {
				// oh no, it's the cops!
				clearInterval(interval);
			},
			function() {
				// false alarm: PARTY!
				interval = startAutoPlay();
			}
		);
	
	// let's get this party started
	interval = startAutoPlay();
	
	
	function startAutoPlay() {
	return setInterval(function() {
		$('ul#ecwid-featured-products').roundabout_animateToNextChild();
	}, 4000);
	}
		
		
		
				
	// ---- Main Menu ----------------------------------------------------------------------------------------------------------
		

	
	$('#main-menu li').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});



	
	$('.stepcarousel a').lightBox({});
	
	$('.menu-item-343>a').click(function(){
		return false;
	});
	
		
	
	
		


	  // ---- PreFilled   ----------------------------------------------------------------------------------------------------------
			
		$.fn.preFilled = function() {
		$(this).focus(function(){
			if( this.value == this.defaultValue ) {
				this.value = "";
			}				   
		}).blur(function(){
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
		};
		
		$("#subForm .fieldwrap input,input.email,input.name").preFilled();
		
		
// ---- Slide Out Box   ----------------------------------------------------------------------------------------------------------
 
  
	  $(function() {
			$('#click-slider').toggle(function() {
				$(this).parent().animate({left:'0px'}, {queue:false, duration: 500});
		    }, function() {
				$(this).parent().animate({left:'-500px'}, {queue:false, duration: 500});
		    });
	  });
	  
	  $("#invia-slider").click(function(){
	  		if(!$('#slider-privacy').is(':checked')){
				$('.slider-privacy-label').addClass('error-slider');
				return false;
			}
	  });
	  
	  $("#slider-privacy").click(function(){
	  		if(!$(this).is(':checked')){
				$('.slider-privacy-label').addClass('error-slider');
			}else{
				$('.slider-privacy-label').removeClass('error-slider');
			}
	  });
	  

	// ---- Lightbox  ----------------------------------------------------------------------------------------------------------
 
		
		$('.ngg-gallery-thumbnail a').lightBox({fixedNavigation:true});
		
		$('.ngg-galleryoverview .gallery-title').css({'display':'inline'}).appendTo('#content h2');
		
});
