$(function() {

  /* ----------------------------------------------------------------
    Browsers and versions
  ---------------------------------------------------------------- */
  var isIE = ($.browser.msie);
  var isOpera = ($.browser.opera);
  var isWebkit = ($.browser.webkit);
  var isFirefox = ($.browser.mozilla);

  // add styles for browsers
  if (isOpera) {
    $('head').append('<link rel="stylesheet" type="text/css" href="css/screen-opera.css" media="screen,projection" />');
  }
  if (isWebkit) {
    $('head').append('<link rel="stylesheet" type="text/css" href="css/screen-webkit.css" media="screen,projection" />');
  }


  /* ----------------------------------------------------------------
    Corners
  ---------------------------------------------------------------- */
  if (isFirefox || isWebkit) {
    $('.button, .pagination a, .pagination strong').corner('4px');
    $('nav a').corner('8px');
  }
  if (isIE || isOpera) {
    $('.button, .pagination a, .pagination strong').corner('5px');
  }


  /* ----------------------------------------------------------------
    external links
  ---------------------------------------------------------------- */
  $("a[href^=http]").each(function() {
    if(this.href.indexOf(location.hostname) == -1) {
      $(this)
        .addClass('external')
        .click(function() {
          window.open(this.href);
          return false;
        });
    }
  });
  $("a[href$=pdf]").click(function() {
    window.open(this.href);
    return false;
  });


  /* ----------------------------------------------------------------
    files
  ---------------------------------------------------------------- */
  /*$('a[href$=.pdf], a[href$=.jpg], a[href$=.gif], a[href$=.png], a[href$=.txt], a[href$=.docx], a[href$=.doc]').addClass('file');
  $('a[href$=.jpg], a[href$=.gif], a[href$=.png]').addClass('img');
  $('a[href$=.pdf]').addClass('pdf');
  $('a[href$=.docx], a[href$=.doc]').addClass('word');*/
  
  
  /* ----------------------------------------------------------------
    striped tables
  ---------------------------------------------------------------- */
  /*$('table tr:odd').addClass('odd');
  $('table thead .odd, table tfoot .odd').removeClass('odd');*/
  
  
  /* ----------------------------------------------------------------
    print page
  ---------------------------------------------------------------- */
  $('footer .up').before('<a href="#" class="print">Vytisknout</a>').siblings('.print').click(function() {
    window.print();
    return false;
  });


  /* ----------------------------------------------------------------
    scrollTop
  ---------------------------------------------------------------- */
  $('footer .up').click(function() {
    $(window).scrollTo( 0, 500, {easing: 'easeInOutQuart'} );
    return false;
  });



  /* ----------------------------------------------------------------
  	search
  ---------------------------------------------------------------- */
  var $searchInput = $('#ctl00_TextBoxSearch'),
      $searchLabel = $('#search label'),
      defaultValue = $searchLabel.text();
  $searchLabel.hide();
  $searchInput.val(defaultValue);
  $searchInput
    .focus(function () {
      // remove text
      if (this.value === defaultValue) {
        $(this).val('');
      }
    })
    .blur(function() {
      // add text
      if ($.trim(this.value) == '') {
        $(this).val(defaultValue);
      }
    });


  /* ----------------------------------------------------------------
  	hAccordion
  ---------------------------------------------------------------- */
  $('#haccordion').hAccordion();
  
  
  /* ----------------------------------------------------------------
    Maps
  ---------------------------------------------------------------- */
  $('#regions').maps();
  
  
  /* ----------------------------------------------------------------
    Survey
  ---------------------------------------------------------------- */
  var $survey = $('#questions'),
      $submit = $('a.button', $survey);

  disableSubmit()
  $survey.delegate(':checkbox', 'change', function() {
    disableThirdCheckbox();
    disableSubmit();
  });
  function disableThirdCheckbox() {
    if ($(':checkbox:checked', $survey).size() > 1) {
      $(':checkbox:not(:checked)', $survey).attr('disabled', true);
    } else {
      $(':checkbox:disabled', $survey).attr('disabled', false);
    }
  }
  function disableSubmit() {
    if ($(':checkbox:checked', $survey).size() < 1) {
      $submit.addClass('disabled').bind('click.survey', function() {
        return false;
      });
    } else {
      $submit.removeClass('disabled').unbind('click.survey');
    }
  }
  
  
  /* ----------------------------------------------------------------
    Product changer
  ---------------------------------------------------------------- */
  $('#img-pum').hide();
  $('#emulze-bez').wrapInner('<a href="#" />').click(function() {
    $('#img-bez').show();
    $('#img-pum').hide();
    return false;
  });
  $('#emulze-pum').wrapInner('<a href="#" />').click(function() {
    $('#img-pum').show();
    $('#img-bez').hide();
    return false;
  });

});

function clickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

