$(document).ready(function(){
  
  // SE ESISTE l'ID #theImages LANCIA:
  // window.onload = initGalleryScript; (da togliere da item_gallery.js)
  
  $('.bf-form #idForm').css('visibility','visible');
  $('#mycarousel').css('visibility','visible');
  
  
  
  
  /*Personalizzazione select booking form*/
  $('.my-dropdown').sSelect({
    ddMaxHeight: '300px'
  });
  $('#hotel_list .my-dropdown').sSelect({
    ddMaxHeight: '300px'
  });  
  
  
  /*SLIDESHOW PREV/NEXT*/
  $('#s1').cycle({ 
    timeout: 4000, // disable automatic transitions 
    fx: 'fade',
    speed: 'fast',
    prevNextEvent: 'click',
    prev: '#prev',
    next: '#next'
  });
  
  /*FINE GALLERY PREV/NEXT*/  
  $('#mycarousel').jcarousel({
    wrap: 'circular',
    scroll: 3
  });
  
  
  /*Fancybox*/
  $(".group").fancybox({
    titlePosition: 'over'
  });
  
  
  //Apertura esterna documenti PDF
  $('a[rel=external]').attr('target', '_blank');
  
  
  
  $('.item_more a').live("click", function(){
    var id_ele = parseInt($(this).parent('div').attr('id').replace('more_', ''), 10);
    //alert(id_ele);
    $('#elem_'+id_ele+' .item_abstract').removeClass('hide');
    $('#elem_'+id_ele+' .txt-small').addClass('hide');
    $('#elem_'+id_ele+' .item_more').addClass('hide');
    $('#elem_'+id_ele+' .item_close').removeClass('hide');
    return false;
  });  
  $('.item_close a').live("click", function(){
    var id_close = parseInt($(this).parent('div').attr('id').replace('close_', ''), 10);
    //alert(id_close);
    
    $('#elem_'+id_close+' .item_abstract').addClass('hide');
    $('#elem_'+id_close+' .txt-small').removeClass('hide');
    $('#elem_'+id_close+' .item_more').removeClass('hide');
    $('#elem_'+id_close+' .item_close').addClass('hide');
    
    return false;
  });
  
});

//GOOGLE MAP 48.871289,2.326301

function initialize() {

  var locations = [
    ["<div id=\"gmap_infowindow\"><h3>Hôtel Le Vignon</h3>23 rue Vignon 75008 PARIS<br />Tél. : +33 (0)1 47 42 93 00<br />Fax : +33 (0)1 47 42 04 60<br /><a href=\"mailto:reservation@hotelvignon.com\">reservation@hotelvignon.com</a><br /><br /><a style=\"font-size:12px;font-weight:bold;color:#333;\" href=\"javascript:;\" onclick=\"hhotelSearch('FRPARHTLVignon', '', '', '', '', '', '&FSTBKNGTrackLink=');\">Book Now!</a></div>", 48.871289,2.326301 , 1],
  ];

  var map = new google.maps.Map(document.getElementById('map_canvas'), {
    zoom: 15,
    center: new google.maps.LatLng(48.871289,2.326301),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  var infowindow = new google.maps.InfoWindow({
    'maxWidth': 300
  });

  var marker, i;

  for (i = 0; i < locations.length; i++) {
    marker = new google.maps.Marker({
      position: new google.maps.LatLng(locations[i][1], locations[i][2]),
      map: map
    });

    google.maps.event.addListener(marker, 'click', (function(marker, i) {
      return function() {
        infowindow.setContent(locations[i][0]);
        infowindow.open(map, marker);
      }
    })(marker, i));
  };
}

$(window).load( function() {
  if($('#map_canvas').length > 0){
    initialize();
  }
}); // close window.load
