$(document).ready(function() {
  
  $('a[rel*=lightbox]').lightBox({fixedNavigation:true,
                                    imageBlank: '',
                                    imageLoading: '/' + window.templatePath + 'images/' + window.pagegroupHost +'/lightbox/loading.gif',
                                    imageBtnClose: '/' + window.templatePath + 'images/' + window.pagegroupHost +'/lightbox/lightbox-btn-close.png',
                                    imageBtnPrev: '/' + window.templatePath + 'images/' + window.pagegroupHost +'/lightbox/lightbox-btn-prev.png',
                                    imageBtnNext: '/' + window.templatePath + 'images/' + window.pagegroupHost +'/lightbox/lightbox-btn-next.png'
                                  });
  
  var overlay_content = $('#overlay_content');
  
  $("a[rel*=overlay]").overlay({
    effect: 'apple',
    mask: {
      loadSpeed: 200,
      opacity: 0.9
    },
    onBeforeLoad: function() {
      
      var iframe = document.createElement('iframe');
      
      iframe.src = this.getTrigger().get(0).href;
      iframe.style.border = '0 none';
      iframe.style.height = '260px';
      iframe.style.width = '410px';
      
      overlay_content.children().remove();
      overlay_content.append(iframe);
      
    },
    onClose: function() { overlay_content.children().remove(); }
  });
  
  
  
  $('.tpl-menu li').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
  
  $('.tpl-head .tpl-res select[name=room_quantity]').change(function() {
    $('.tpl-head .tpl-res span.OR_select_button').text($(this).val());
  }).mouseenter(function() {
    $('.tpl-head .tpl-res span.OR_select_button').css('background-position','117px -21px');
  }).mouseout(function() {
    $('.tpl-head .tpl-res span.OR_select_button').css('background-position','117px 0px');
  });
  
  var mapElm = document.getElementById("mapsearch");
  
  if(mapElm && typeof GClientGeocoder != 'undefined') {
    
    var geocoder = new GClientGeocoder();
    
    geocoder.getLatLng("Hotel Bonjour Sebastian-Kneipp-Str.9 65812 Bad Soden", function(latlng) {
      
      var map = new GMap2(mapElm);
      
      map.setCenter(latlng, 14);
      map.addControl(new GSmallMapControl());
      
      if(window.pagegroup_id == 1) {
        var hotel_name = 'Hotel Bonjour';
        var hotel_street = 'Sebastian-Kneipp-Str. 9';
        var hotel_zip = '65812';
        var hotel_location = 'Bad Soden';
        var hotel_telefon = '+49 (0) 6196 - 60 99 0';
        var hotel_fax = '+49 (0) 6196 - 27 03 0';
        var hotel_mail = 'info@hotelbonjour.de';
      } else {
        var hotel_name = 'Hotel la Maison';
        var hotel_street = 'Sebastian-Kneipp-Str. 14';
        var hotel_zip = '65812';
        var hotel_location = 'Bad Soden';
        var hotel_telefon = '+ 49 ( 0 ) 6196 - 56 16 950';
        var hotel_fax = '+ 49 ( 0 ) 6196 - 56 16 960';
        var hotel_mail = 'info@la-maison-hotel.de';
      }
      
      var html = '<h3 style="margin-top:0;">' + hotel_name + '</h3><p>' + hotel_street + '<br />' + hotel_zip + ' '+ hotel_location + '</p><p><b>Tel.:</b> ' + hotel_telefon + '<br><b>Fax:</b> ' + hotel_fax + '<br><b>E-Mail:</b> <a href="mailto:' + hotel_mail + '" title="E-Mail senden an ' + hotel_name + '">' + hotel_mail + '</a></p>';
      var icon = new GIcon(G_DEFAULT_ICON, '/' + window.templatePath + 'images/' + window.pagegroupHost +'/' + 'maps_icon.png');
      
      icon.iconSize = new GSize(49, 50);
      icon.shadowSize = new GSize(49, 50);
      
      var marker = new GMarker(latlng, { icon:icon });
      
      marker.openInfoWindowHtml(html);
      
      GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
      map.addOverlay(marker);
      
      window.gdir = new GDirections(map, document.getElementById("route-desc"));
      
      window.setGRoute = function() {
        
        var from = document.getElementById('route-from');
        var to = document.getElementById('route-to');
        
        if(from && to)
          window.gdir.load("from: " + from.value + " to: " + to.value, { "locale": "de_DE" });
        
      };
      
      $('.gmaps.route').show();
      
    });
    
    $(window).unload(GUnload);
    
  }
  
});
