$(function() {

  /* ----------------------------------------------------------------
    Debugging
  ---------------------------------------------------------------- */
  $.fn.log = function (msg) {
    if (window.console && window.console.log) {
      if (msg) {
        window.console.log('[schlecker] %s: %o', msg, this);
      } else {
        window.console.log('[schlecker] ' + this);
      }
    }
    return this;
  };

  function log(variable, msg) {
    if (window.console && window.console.log) {
      if (msg) {
        window.console.log('[schlecker] %s: %o', msg, variable);
      } else {
        window.console.log('[schlecker] ' + variable);
      }
    }
  }


  /* ----------------------------------------------------------------
    Browsers and versions
  ---------------------------------------------------------------- */
  var isIE = ($.browser.msie);
  var isOpera = ($.browser.opera);

  // add styles for Opera browser
  if (isOpera) {
    $('head').append('<link rel="stylesheet" type="text/css" href="css/screen-opera.css" media="screen,projection" />');
  }


  /* ----------------------------------------------------------------
    Tabs
  ---------------------------------------------------------------- */
  var tabContainers = $('div.tabs > div');
  tabContainers.hide().filter(':first').show();

  $('div.tabs ul.tabNavigation a').click(function () {
    tabContainers.hide();
    tabContainers.filter(this.hash).show();
    $('div.tabs ul.tabNavigation a').removeClass('selected');
    $(this).addClass('selected');
    return false;
  }).filter(':first').click();

  // if we are in section pharmacy (body class) - display second tab
  $('.pharmacy div.tabs ul.tabNavigation li.second a').click();
    

  /* ----------------------------------------------------------------
    Corners
  ---------------------------------------------------------------- */
  if (isIE || isOpera) {
    $('a.button, #ver-program').corners({
      debug: true
    });
    $('input[type=submit]').corners({
      wrap: true,
      display: 'inline-block',
      debug: true
    });
    $('.tabNavigation a').corners({
      bottomLeft: false,
      bottomRight: false,
      debug: true
    });
    $('a.button3, .box, #letter-box').corners({
      width: '7px',
      height: '7px',
      debug: true
    });
  }


  /* ----------------------------------------------------------------
    Vlozeni odkazu pro tisk do paticky
  ---------------------------------------------------------------- */
  $('#footer-top').prepend('<p id="print"><a href="javascript:window.print();">Vytisknout</a></p>');


  /* ----------------------------------------------------------------
    Fancybox
  ---------------------------------------------------------------- */
  $("a.text-box").fancybox({
    'padding': 3,
    'hideOnContentClick': false,
    'overlayShow': false,
    'frameWidth': 500,
    'frameHeight': 500
  });
  $("a.flash-box").fancybox({
    'padding': 3,
    'hideOnContentClick': false,
    'centerOnScroll': false,
    'overlayShow': true,
    'frameWidth': 900,
    'frameHeight': 595
  });
  $("a.flash-coupon-box").fancybox({
    'padding': 3,
    'hideOnContentClick': false,
    'centerOnScroll': false,
    'overlayShow': true,
    'frameWidth': 1024,
    'frameHeight': 345
  });
  // fancy text box corners
  $('#fancy_bg').append('<span class="cs tl"></span><span class="cs bl"></span><span class="cs br"></span>');


  /* ----------------------------------------------------------------
    Maps
  ---------------------------------------------------------------- */
  $('#map-small, #regions').maps();
  $('#map-small-green').maps({
    height: 101
  });
  
});
