function google_maps(){

  $('body').find('.google_maps').each(function(){

    title = $(this).attr('title'); 
    _id = $(this).attr('id');
    _lat = $(this).find('#lat').val();
    _lng = $(this).find('#lng').val();
    _zoom = $(this).find('#zoom').val();
   _msg = $(this).find('#msg').val();
      if (_msg!=undefined){
      _msg = '';
    }

    if (_zoom!=undefined){
      _zoom = parseFloat(_zoom);
    }

    $('#lng').remove();
    $('#lat').remove();
    $('#zoom').remove();
    initialize(_id, _lng, _lat, _zoom, _msg);
  });

  

  $('body').find('.flash_obj').each(function(){
     _swf = $(this).find('#swf').val();
     _id = $(this).attr('id');
     _width = parseFloat($(this).css('width'));
     _height = parseFloat($(this).css('height'));
     s_flash = new SWFObject(_swf, _id, _width, _height, "0");
     s_flash.addParam("wmode", "transparent");
     s_flash.write(_id);
  });

  $('.download').click(function(){
    file = $(this).attr('href');
    _href= 'download.php?f=' + file;
    $(this).attr('href', _href)

  });
  
  
 // init_class();
}

function init_class(){
  $(".open-photo").click(function(){
    _rel =$(this).attr('rel');
    click_photo(_rel)
    return false;
  });
  lista_cani();
  
  $(".form_contatti button").click(function(){
    if (!$('#autorizzo').attr('checked')){
      alert('Autorizzare il trattamento dei dati personali')
      return false;
    }
  });
  
  $('.open_chi-siamo').click(function(){
    _href = $(this).attr('href');
    $('#image_page img#main-img').attr('src', _href);
    return false;
  });
  
  
  /*
  if($('body').attr('id')=='nostri_cani'){
    //alert($('.sesso').html())
    if ($('.sesso').html()!=null){
      //alert($('.sesso').html())
      if ($('.sesso').html()=='Femmina'){
        //alert(1)
        $('.lista_nostri_cani').toggle();
      }      
    }
  }*/
  /*
  $('.toggle_nostri-cani').click(function(){
    //sesso = $(this).attr('href');
    //alert(sesso)
    $('.lista_nostri_cani').toggle();
    return false;
  });*/
  
  $('span.privacy a').attr('rel', 'prettyPhoto[iframes]');
  //$('span.privacy a').click(function(){
    //$(this).attr('rel', 'prettyPhoto[iframes]');
    //window.open(this.href, 'Privacy', 'width=800,height=600');
    //return false;
  //});
  
}

function click_photo(_rel){
  //alert("a.open-photo[rel^='" + _rel + "']")
  //alert($("a.open-photo[rel^='" + _rel + "']").attr('href'));
  _href = $("a.open-photo[rel^='" + _rel + "']").attr('href')
  $('#container-photo img').attr('src', _href);
  _didascalia = $('#didascalia_'+ _rel).html();
  //alert(_didascalia)
  $('#didascalia-photo').html(_didascalia);
  $('#lista-cani li a img').css('border', '3px solid #EEF5FC');
  $("a.open-photo[rel^='" + _rel + "']").find('img').css('border', '3px solid #017DC7');
  
}

var select_list = 1;
var tot_list = 0;
function lista_cani(){
  //tot_list = $('#lista-cani li').size();
  limit = 3;
  x=0;
  page = 1;
  $('#lista-cani li').css('display','none');
  $('#lista-cani li').each(function(){
    if (x==limit){
      page++;
      x=1;
    }else{
      x++;
    }
    if(page==select_list){
      $(this).addClass('nav_select');
    }
    $(this).addClass('nav_' + page); 
  });
  $('.title-photo').css({'display':'none'});
  
  
  
  /*for(z=x; z<4; z++){
    $('#lista-cani').append('<li class="null_list nav_' + page + '"></li>');
  }*/
  
  
  
  
  tot_list = page;
  for(i=1;i<=page; i++){
    if(i==1){
      link_page = '<a href="#'+i+'" class="nav_link_select" rel="'+i+'">[' + i + ']</a> '; 
    }else{  
      link_page += '<a href="#'+ i + '" class="nav_link" rel="'+i+'">[' + i + ']</a> ';
    }
  }
  //alert(link_page)
   $("#lista-cani").after('<div id="nav"></div>');
   content = '<a href="#back" id="back"></a>';
   content +='<div id="content_nav">'+link_page+'</div>';
   content += '<a href="#next" id="next"></a><div style="clear:both;"></div>';
   //alert(content)
   $('#nav').html(content);
  
   
   $('#back').click(function(){
    if(select_list!=1){
      select_list--;
      select_list_fn();
    }
    return false;
   });
   $('#next').click(function(){
    if(select_list!=tot_list){
      select_list++;
      select_list_fn();
    }
    return false;
   });
   $('.nav_link').click(function(){
    select_list = $(this).attr('rel');
    select_list_fn(select_list);
    return false;
   });
   
   function select_list_fn(x){
    $('.nav_link_select').removeClass('nav_link_select');
    $('#lista-cani li').removeClass('nav_select').css('display', 'none');
    $('.nav_' + select_list).addClass('nav_select');
    $('.nav_link_select').removeClass('nav_link_select');
    $("#content_nav a[rel^='" + select_list + "']").addClass('nav_link_select');
   }
   _rel = $('#lista-cani li a:first').attr('rel')
  // alert(_rel)
   click_photo(_rel)
  //$('#lista-cani').a('<div>').attr('id', 'nav');
}





function initialize(id, lng, lat, zoom, msg) {

      if (GBrowserIsCompatible()) {

        var map = new GMap2(document.getElementById(id));

        map.setCenter(new GLatLng(lat, lng), zoom);

        map.setUIToDefault();

        var latlng = new GLatLng(lat, lng);

        map.addOverlay(new GMarker(latlng));

        if (msg!=undefined){

          map.addOverlay(createMarker(latlng, map, msg));

        }

      }

    }





function createMarker(latlng, map, msg) {

      var marker = new GMarker(latlng);

      GEvent.addListener(marker,"click", function() {

        map.openInfoWindowHtml(latlng, msg);

      });

      return marker;

	}
