    //offuscatore [v0.2]
    function offusca_ind(uno) {
      var domain = "nardigarden"+"."+"it";
      document.write("<a href=" + "ma" + "il" + "to:" + uno + "@" + domain +" class=\"link\" >" + uno + "@" + domain + "</a>");
    }
    
    
  function initCarousel() {
    $('#box-img').svCarousel({
      transition_mode: 'alone_in',
      in_time: 500,
      
      controls: 2,
      controls_target: $('#sv-box'),
      controls_position: 'append',
      controls_always: true,
      
      autoplay: false,
      keys : true
    });
  }
  
  
  function swapVariant() {
    var $parent = $('#box-varianti'),
        idx = $('#box-varianti li').index(this),
        variante = varianti[idx],
        $box_img = $('#box-img'),
        html_li = '';
    // set active
    $parent.find('.active').removeClass('active');
    $(this).addClass('active');
    // sostituzione immagini
    $box_img.empty();
    for(var i=0; i<variante.imgs.length; i+=1) {
      html_li += '<li><img src="'+variante.imgs[i]+'"></li>'
    }
    $box_img.append(html_li);
    // nuovo init Carousel per le nuove immagini
    $('#sv-box .svScorri').remove();
    initCarousel();
    // sostituzione testi
    $('#box-info').html(variante.materiale + (variante.materiale ? '<br>' : '') + variante.codice);
    // set hash
    window.location.hash = variante.codice;
  }
  
  
  function changeVariant() {
    var hash = window.location.hash.replace('#','');
    if (hash.length > 2) {
      $('#box-varianti li[rel="'+hash+'"]').trigger('click');
    }
  }
  
  
  // funzione per lo slideUp/Down del menu basic
  function menuBasic() {
    
    $('div.navbox h4').click(function() {
      $(this).next().slideToggle();
    });
    
  }
  
  
  // funzione per lo slideUp/Down di tutto il menu nei prodotti
  function menuSlideToggle() {
    $('div.navbox h2').click(function() {
      var $navbox = $(this).parent();
      if ($navbox.hasClass('active')) {
        $navbox.animate({'height': '14px', 'paddingTop':'5px', 'paddingBottom':'5px'}, 200,
          function() {
            $(this).removeClass('active');
          }
        );
      } else {
        $navbox.animate({'height': '180px', 'paddingTop':'15px', 'paddingBottom':'15px'}, 500,
          function() {
            $(this).addClass('active');
            $(this).removeAttr('style');
          }
        );
      }
      
    });
  }
  
  
  function formIsValid(form) {
    var $form = form || $('#contact-form'),
        errors = 0;
    
    $form.find('input[type="text"], input[type="password"], textarea').each(function(i){
      if($(this).siblings('label').text().indexOf('*') > 1) { // if is required
        if ($(this).val().length < 2
            || ($(this).attr('name') == 'email' && !$(this).val().match(/^[\w\d\._%\+\-]+@[a-zA-Z_\-]+?\.[a-zA-Z]{2,6}$/))) {
          $(this).parent().addClass('error');
          errors += 1;
        }
      }
    });
    
    var $accept = $form.find('input[name="autorizzo"]');
    if ($accept.length > 0 && !$accept.is(':checked')) {
      $accept.parent().addClass('error');
      errors += 1;
    }
    
    return (errors) ? false : true;
  }
  
  
  function bindForm() {
    
    // mostra/nasconde la label sopra i campi
    $('#contact-form, #login-form').find('input[type="text"],input[type="password"],textarea')
      .focus(function() {
        $(this).siblings('label').hide().parent().removeClass('error');
      })
      .blur(function() {
        if (!$(this).val()) {
          $(this).siblings('label').show();
        }
      })
      .filter(function() {
        return $(this).val() != '';
      })
      .siblings('label').hide();
    
    $('#contact-form input[name="autorizzo"]').change(function() {
      $(this).parent().removeClass('error');
    })
    
  }
  
  
  // fn bind e setup Store Locator/ Agenti
  var svLocator = function() {
    
    var _params, _target, _select_str;
    
    function init(select_str, link, lang, nx) {
      // assign globals
      _select_str = select_str;
      _target = link;
      _params = { 'lingua': lang, 'agenti': nx };
      
      // bind select contineti e nazioni
      $('select.js').live('change', _bindSelect);
      // bind select delle regioni
      //$('#regioni .tmp').live('change', function() {
      //  ($(this).val() > 0) ? $('a.submit').show() : $('a.submit').hide();
      //});
      // bind click cerca
      $('a.submit').click(_bindSubmit);
      // al document ready lancio il change sul select continente
      $('select[name="continente"]').trigger('change');
      
    }
    
    function _bindSelect() {
      var that = this,
          $opt = $(that).find('option:selected'),
          tos = $opt.val(),
          
          has_regioni = $opt.hasClass('showregioni'),
          has_province = $opt.hasClass('showprovince'),
          
          is_nazione = $(that).parent().hasClass('nazioni'),
          is_regione = $(that).parent().hasClass('regioni'),
          is_provincia = $(that).parent().hasClass('province'),
          
          $next_p = $(that).parent().next(),
          $current_options, html_select;
      
      // se sono sull'ultimo select
      if(!$next_p.is('p')) { 
        $('a.submit').show();
        return false;
      }
      
      // incremental select discovering
      (is_regione || has_regioni) ? $('#regioni').show() : $('#regioni').hide();
      (is_provincia || has_province) ? $('#province').show() : $('#province').hide();
      
      // submit show/hide
      $('a.submit').hide();
      if(is_nazione && tos > 0 && !has_regioni) { $('a.submit').show(); }
      if(is_regione && tos > 0 && !has_province) { $('a.submit').show(); }
      
      // remove select and get new ones
      $next_p.find('.tmp').remove();
      $current_options = $next_p.find('.n'+tos);
      
      html_select = '<select class="tmp"><option value="0">-- '+_select_str+' --</option></select>';
      $current_options.clone().appendTo($(html_select).addClass('tmp').appendTo($next_p));
      $next_p.find('.tmp').addClass('js');
      // empty results
      $('#store-results').empty();
    }
    
    function _bindSubmit() {
      var has_regioni = $('#regioni').is(':visible'),
          has_province = $('#province').is(':visible');
      // remove old parameters
      delete _params['nazione'];
      delete _params['regione'];
      delete _params['provincia'];
      
      if (has_province) {
        _params['provincia'] = $('#province .tmp option:selected').val();
      } else if (has_regioni) {
        _params['regione'] = $('#regioni .tmp option:selected').val();
      } else {
        _params['nazione'] = $('#nazioni .tmp option:selected').val();
      }
      
      $.get(_target, _params, function(resp) {
          $('#store-results').html(resp);
        });
      
      return false;
    }
    
    return {
      init : init
    }
    
  }();
  
  
  
  // realizzazioni
  
  function swapRealiz(e) {
    e.preventDefault();
    
    var $parent = $('#realizzazioni'),
        idx = $(this).attr('href').match(/r-\d{1,}$/)[0],
        realiz = realizzazioni[idx],
        $box_img = $('#img_ref'),
        html = '';
    
    // set active
    $parent.find('.active').removeClass('active');
    $(this).addClass('active');
    // sostituzione immagini
    $box_img.empty();
    for(var i=0; i<realiz.imgs.length; i+=1) {
      html += '<img src="'+realiz.imgs[i]+'"><br>';
    }
    $box_img.append(html);
    // sostituzione testi
    $('#box-info').html(realiz.dida);
    // set hash
    window.location.hash = idx;
  }
  
  function changeRealiz(e) {
    var hash = window.location.hash.replace('#','');
    $a = $('#realizzazioni a[href*="'+hash+'"]');
    if ($a.length > 0) {
      $a.trigger('click');
    }
  }
  
  function scorriRealiz(e) {
    e.preventDefault();
    var $active = $('#realizzazioni .active'),
        $li = $active.parent(),
        $el,
        $scorri = $('#scorri');
    
    $el = $(this).hasClass('avanti') ? $li.next() : $li.prev();
    $el.find('a').trigger('click');
    
    var idx = $el.index('#realizzazioni li');
    switch(idx) {
      case 0:
        $scorri
          .find('.indietro').remove().end()
          .prepend('<b class="indietro"></b>');
        break;
      case ($('#realizzazioni li').length-1):
        $scorri
          .find('.avanti').remove().end()
          .append('<b class="avanti"></b>');
        break;
      default:
        $scorri
          .find('b,a').remove().end()
          .prepend('<a href="#" class="indietro"></a>')
          .append('<a href="#" class="avanti"></a>');
    }
    
  }
  
  
  // LANCIATE SU OGNI PAGINA
  $(function() {
    
    // Analytics track downloads
    $('a.download').click(function() {
      
      sub = $(this).hasClass('pdf') ? 'pdf' : 'other';
      
      try {
        pageTracker._trackPageview('/downloads/'+sub);
      } catch(e) {}
      
    });
    
    
    // select menu mobile
    var mobile = function() {
      
      if (window.innerWidth > 595) { return; }
      
      // creazione select menu
      var $links = $('#intestazione .nav1 a');
      var htmlSelect = document.createElement('select');
      var options = '<option value="">- menu -</option>';
      $links.each(function(i) {
        if(i == 2) { options += '<option value="">--</option>';  }
        //var selected = $(this).parent().hasClass('selected') ? 'selected' : '';
        var selected = '';
        options += '<option '+selected+' value="'+this.href+'">'+$(this).text()+'</option>';
      });
      
      $(htmlSelect)
        .addClass('m-nav1')
        .append(options)
        .appendTo('#intestazione')
        .change(function() {
          var link = $(this).find(':selected').val();
          if (link != '') {
            window.location = link;
          }
        });
      
      // gestione descrizione prodotto
      $('<a href="#">info</a>')
        .addClass('product-more')
        .appendTo($('.page-prodotto #box-info').parent())
        .click(function() {
          $('div.span2.f_dx').toggle();
        });
      
      t = setInterval(function() {
        var h = $('#box-img img').eq(0).height();
        $('#box-img').css('height', h + 'px');
        if(h > 50) { clearInterval(t) }
      }, 500);
      
    };
    mobile();
    
    window.onresize = function() {
      if (window.innerWidth < 595) {
        if($('select.m-nav1').length === 0) { mobile(); }
      } else {
        $('select.m-nav1').remove();
      }
    }
    
  });
  
  
  
  /*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
