function generateGoogleMap (searchString) {
  mapId   = 'google-map';
  mapX    = 49.991428;
  mapY    = 17.463074;
  mapZoom = 15;

  if (document.getElementById(mapId)) {
    if (GBrowserIsCompatible()) {
      var map = new GMap2(document.getElementById(mapId));
      var marker = new GMarker(new GLatLng(mapX, mapY));
      map.setCenter(new GLatLng(mapX, mapY),mapZoom);
      map.addOverlay(marker);
      var customUI = map.getDefaultUI();
      customUI.controls.scalecontrol = false;
      customUI.controls.largemapcontrol3d = false;
      customUI.controls.smallzoomcontrol3d = true;
      customUI.maptypes.physical = false;
      customUI.maptypes.normal = true;
      customUI.maptypes.hybrid = false;
      customUI.maptypes.satellite = true;
      map.setUI(customUI);
      if (searchString) {
        var directionsPanel;
        var directions = new GDirections(map, directionsPanel);
        directions.load("from: " + mapX + ", " + mapY + " to: " + searchString);
      }
    }
  }
}

jQuery.noConflict();

jQuery(document).ready(function($){

// upravení inputu pro vyhledávání
  $('#search-term').focus(function(){
    if ($(this).val() == $(this).attr('alt')) $(this).val('');
  });
  $('#search-term').blur(function(){
    if ($(this).val() == '') $(this).val($(this).attr('alt'));
  });

// generování google mapy
  generateGoogleMap();
  $('#from + button').click(function(){
    generateGoogleMap($('#from').val());
  });

// carousel v hlavičce
  $('#scrollable .nivo').nivoSlider({effect:'fade', pauseTime:5000});
  
// Obsluha kalendáře
  $('#news-actions .calendar table tbody a').parent('div').hover(
    function(){
      objectAnchor   = $(this).children('a');
      objectList     = objectAnchor.next('ul');
      objectCalendar = $(this).parents('.calendar');

      var listWidth     = objectList.outerWidth();
      var calendarWidth = objectCalendar.outerWidth();
      var anchorPositionLeft = Math.round(objectAnchor.position().left);
      var anchorPositionTop  = objectAnchor.position().top + 17;

      if (listWidth + anchorPositionLeft > calendarWidth) anchorPositionLeft = calendarWidth - listWidth;
      objectAnchor.addClass('selected');
      objectList.css({position:'absolute', left: anchorPositionLeft + 'px', top: anchorPositionTop + 'px'}).show();
    },
    function(){
      objectAnchor.removeClass('selected');
      objectList.attr('style', '');
      objectList.hide();
    }
  )
});
