/*Cerca nel sito*/
$(document).keydown(function(e) {
if($('#srcText').data('focused')){
lastKeyPressCode = e.keyCode;
switch (e.keyCode) {
case 13: // return

    
      var query = $('#srcText').val();
      location.href='/risultati-ricerca.aspx?q=' + query;

    
    return false;
break;
default:
break;
}
}
});
$(document).ready(function () {
$('#srcText')
    .data('focused', false)
    .focus(function() { $.data(this, 'focused', true); })
    .blur(function() { $.data(this, 'focused', false); });
}); 
function ricercaForm(){

      var query = $('#srcText').val();
      location.href='/risultati-ricerca.aspx?q=' + query;
}
/*fine cerca nel sito*/

/* Barra nav testimonial */
 var contTestS = 1;
 var pag = 0;
 testimonialarray = new Array(); 
 $(document).ready(function() {
 $.ajax({
   type: "GET",
     url: "/img/release.xml",
   dataType: "xml",
   success: function(xml) {
    var tot = $(xml).find('testimonial').length;
  
    pag = Math.ceil(tot/4);
    $("#ferc-dx").click(function(){
       if (contTestS<pag){
        contTestS=contTestS+1;
        spostaTest(1);
      }
      });
    $("#ferc-sx").click(function(){
       if (contTestS>1){
        contTestS=contTestS-1;
        spostaTest(2);
      }
      });
    var count =0;
     $(xml).find('testimonial').each(function() {
       count=count+1;
                     
       var nome = $(this).find('nome').text();
       var url = $(this).find('url').text();
        var trg = $(this).find('target').text();
       var testo = $(this).find('testo').text();
       var  img = $(this).find('foto').text();
      
       $("#cont-vet").append('<div class=\"bgFoto\"><a target=\"' + trg + '\" href=\"'+url+'\" id=\"botest'+count+'\"><img src=\"'+img+'\" alt=\"'+nome+'\" width=\"89\" height=\"67\" /></a></div>');
       testimonialarray[count-1] = new Array(nome, testo, url);
       $("#cont-vet").append('<div class=\"finestrapopup\" id=\"botest'+count+'\"><div class=\"copro-newsRelease\"><a target=\"' + trg + '\" href=\"'+url+'\">'+nome+'</a><p>'+testo+'</p><a href=\"'+url+'\" target=\"' + trg + '\" class=\"continua\">continua</a></div><div class=\"chiusa-box-newRelease\"><!-- --></div></div>');
        $("#cont-vet a#botest"+count).hover(function(){
         
        displaytooltipt($(this).attr('id'),trg);
          
      });
      $("#cont-vet a#botest"+count).mouseleave(function(){
          flagImg=0;
        setTimeout(function() {nasctooltipt(); }, 100);
      });
     });
     }
 });
});
var spostamentoR = 0;
function spostaTest(numero){
    if(numero==1){
     spostamentoR = spostamentoR -440;
    $('#cont-vet').animate({marginLeft:spostamentoR}, 1500, function() {});
    }else{
     spostamentoR = spostamentoR +440;
    $('#cont-vet').animate({marginLeft:spostamentoR}, 1500, function() {});  
    }
  }
var flagImg =0;
var flagToolt =0;


function displaytooltipt(id,trg){
  
  var taglio = id.length;
  var punto = id.substr(6,taglio-1);
  punto=punto-1;
  flagImg=1;
  var posL = $("#"+id).position();
    var pos = $("#"+id).offset();
    var height = $("#"+id).height();
    var offpnlX = ($("#"+id).width())/2;
    $(".finestrapopup").css({ "left": posL.left + offpnlX  + "px", "top": pos.top - height-20+ "px" }); 
  $(".copro-newsRelease").html('<a href=\"'+testimonialarray[punto][2]+'\">'+testimonialarray[punto][0]+'</a><p>'+testimonialarray[punto][1]+'</p><a target=\"'+trg+'\" href=\"'+ testimonialarray[punto][2]+'\" class="continua">continua</a>');
  $(".finestrapopup").fadeIn('slow', function() {});
  $(".finestrapopup").mouseenter(function(){flagToolt=1;});
  $(".finestrapopup").mouseleave(function(){flagToolt=0;setTimeout(function() {nasctooltipt(); }, 100);});
}
function nasctooltipt(){
  if (flagImg == 0 && flagToolt == 0){
    $(".finestrapopup").fadeOut('fast', function() {});
    }
  }
  


/*SCRIPT PER TOPMENU*/
;(function($){
  $.fn.superfish = function(op){
    var menuIDs= new Array(1064,1083,1088,1112,1122,1132,1137,1146);
    var sf = $.fn.superfish,
      c = sf.c,
      $arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
      over = function(){
        var $$ = $(this), menu = getMenu($$);
        clearTimeout(menu.sfTimer);
        $$.showSuperfishUl().siblings().hideSuperfishUl();
      },
      out = function(){
        var $$ = $(this), menu = getMenu($$), o = sf.op;
        clearTimeout(menu.sfTimer);
        menu.sfTimer=setTimeout(function(){
          o.retainPath=($.inArray($$[0],o.$path)>-1);
          $$.hideSuperfishUl();
          if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
        },o.delay);  
      },
      getMenu = function($menu){
        var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
        
        sf.op = sf.o[menu.serial];
        
      
        return menu;
      },
      addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
      
    return this.each(function() {
      var s = this.serial = sf.o.length;
      var o = $.extend({},sf.defaults,op);
      o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
        $(this).addClass([o.hoverClass,c.bcClass].join(' '))
          .filter('li:has(ul)').removeClass(o.pathClass);
      });
      sf.o[s] = sf.op = o;
      
      $('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
        if (o.autoArrows) addArrow( $('>a:first-child',this) );
      })
      .not('.'+c.bcClass)
        .hideSuperfishUl();
      
      var $a = $('a',this);
      $a.each(function(i){
        var $li = $a.eq(i).parents('li');
        $li.eq(i).not('.sep').mouseenter(function(){over.call($li);event.stopPropagation();}).mouseleave(function(){out.call($li);event.stopPropagation();});
        
      });
      o.onInit.call(this);
      
    }).each(function() {
      var menuClasses = [c.menuClass];
      if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
      $(this).addClass(menuClasses.join(' '));
    });
  };

  var sf = $.fn.superfish;
  sf.o = [];
  sf.op = {};
  sf.IE7fix = function(){
    var o = sf.op;
    if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
      this.toggleClass(sf.c.shadowClass+'-off');
    };
  sf.c = {
    bcClass     : 'sf-breadcrumb',
    menuClass   : 'sf-js-enabled',
    anchorClass : 'sf-with-ul',
    arrowClass  : 'sf-sub-indicator',
    shadowClass : 'sf-shadow'
  };
  sf.defaults = {
    hoverClass  : 'sfHover',
    pathClass  : 'overideThisToUse',
    pathLevels  : 1,
    delay    : 300,
    animation  : {opacity:'show'},
    speed    : 'normal',
    autoArrows  : false,
    dropShadows : true,
    disableHI  : true,    // true disables hoverIntent detection
    onInit    : function(){}, // callback functions
    onBeforeShow: function(){},
    onShow    : function(){},
    onHide    : function(){}
  };
  $.fn.extend({
    hideSuperfishUl : function(){

      var o = sf.op,
        not = (o.retainPath===true) ? o.$path : '';
      o.retainPath = false;
      var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
          .find('>ul').hide().css('visibility','hidden');
      o.onHide.call($ul);
      return this;
    },
    showSuperfishUl : function(){
     
      var o = sf.op,
        sh = sf.c.shadowClass+'-off',
        $ul = this.addClass(o.hoverClass)
          .find('>ul:hidden').css('visibility','visible');
      sf.IE7fix.call($ul);
      o.onBeforeShow.call($ul);
      $ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
      return this;
    }
  });

})(jQuery);



//BINDING, APPENDING E REMOVING DELLE VOCI DI MENU
menuIDs= new Array(1064,1083,1088,1112,1122,1132,1137,1146);
function bindMenu(){
  for(i=0;i<menuIDs.length;i++){
    $('#d'+menuIDs[i]).hover(appendSubmenu,removeSubmenu);
    //$('#d'+menuIDs[i]).addClass('sfHover');
  }
}
function appendSubmenu(){
splitID=$(this).attr('id').split('d',2);
currentID=splitID[1];
//alert(splitID[1]);
$subList=$('#'+currentID).html();
//alert($subList); 
$('#d'+currentID).append($subList);
jQuery('ul#topMenu').superfish();
}
function removeSubmenu(){
splitID=$(this).attr('id').split('d',2);
currentID=splitID[1];
//alert(splitID[1]);
$subList=$('#d'+currentID+' ul'); 
//alert($subList);
$('#d'+currentID).children('ul').remove();
  jQuery('ul#topMenu').superfish();
}


//TOGGLER DELLA PAGINA ARCHIVIO DEI COMITATI
function toggleDesc(link){
$li=$(link).parent();

if(($li.index()+1)%3==0)
{
$li1=$li.prev();
$li2=$li1.prev();
}
  
if(($li.index()+1)%3==1)
{
$li1=$li.next();
$li2=$li1.next();
}  
  
if(($li.index()+1)%3==2)
{
$li1=$li.next();
$li2=$li.prev();
}  
  
  
$desc=$li.children('p');
if($desc.css('display')=='none')
{
    $.each($('ul.comitatiArchivio li p'), function() {
      $(this).slideUp();
   });
  $desc.slideDown();
  $li1.children('p').slideDown();
  $li2.children('p').slideDown();

}
else
{
  $desc.slideUp();
  $li1.children('p').slideUp();
  $li2.children('p').slideUp();

}
}

function aprifin(nome,titolo,larghezza,altezza,ridim,scrolla)  {
  centroX=(screen.width-larghezza)/2
  centroY=(screen.height-altezza)/2
  afin=window.open(nome,titolo,"width="+larghezza+",height="+altezza+",resizable="+ridim+",scrollbars="+scrolla+",screenX="+centroX+",left="+centroX+",screenY="+centroY+",top="+centroY);
  afin.focus();
}

