// $.fn.cycle.debug = true
               $
( function()
  { $('body').removeClass('js_off').addClass('js_on')
  ; $('form.check') // validace formulare
    .submit
    ( function()
      {
        var returnVal = true;
        $(this).find('.check').each(
          function ()
          {
            // not empty
            if ($(this).hasClass('not-empty')) {
              if ($(this).val() == '') {
                $(this).css('border','2px red solid');
                returnVal = false;
              }
              else $(this).css('border','2px green solid');
            }
            // email
            if ($(this).hasClass('email')) {
              var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
              if (!emailPattern.test($(this).val())) {
                $(this).css('border','2px red solid');
                returnVal = false;
              }
              else $(this).css('border','2px green solid');
            }
            // number
            if ($(this).hasClass('number')) {
              var value = '' + $(this).val() + '';
              value = value.replace(/[\s\+]/g,'');
              var emailPattern = /^[0-9]+$/;
              if ((value.length < 9) || !emailPattern.test(value)) {
                $(this).css('border','2px red solid');
                returnVal = false;
              }
              else $(this).css('border','2px green solid');
            }
          }
        );
        if (!returnVal) alert('Nebyla vyplnena vsechna povinna pole formulare nebo byla vyplnena spatne!');
        return returnVal;
      }
    )
  ; $('.external a').attr('target','_blank') // externí odkazy
  ; $('table.evenodd').each(function(){ // obarveni radku tabulek (bere v potaz vice tabulek na strance)
      $(this).find('tr:odd').addClass('odd');
      $(this).find('tr:even').addClass('even');
    })
  ; $('#hp-banner-switch') // Homepage: prolínání (automatické / hover)
    .cycle // @see http://jquery.malsup.com/cycle/options.html
    ( { fx
        : 'fade'
      , slideExpr
        : '.cycle-item'
      , pager
        : '#hp-banner-switch-buttons > p'
      , pagerEvent
        : 'mouseover'
      , pagerAnchorBuilder
        : function(i){return '<span>'+(++i)+'</span>'}
      , activePagerClass
        : 'selected'
      , pause // "pause on hover"
        : true
      , timeout // jak dlouho pic "visí"
        : 9000
      , speed  // jak dlouho trvá prolnutí
        : 600
      , cleartypeNoBg //
        : true
      }
    )
  ; $('ul.specification li.closed div')
    .css('display','none')
  ; $('ul.specification li span')
    .click
    ( function ()
      { $(this).parent().toggleClass('closed');
        $(this).parent().children('div').slideToggle();
      }
    )
  ; $('.award-folder ul.specification li span')
    .click
    ( function ()
      { $(this).parent().toggleClass('closed');
        $(this).parent().parent().parent().children('div.more').slideToggle();
      }
    )
  ; $('.career-folder ul.specification li span.addMore')
    .click
    ( function ()
      { $(this).css('display','none');
        $(this).parent().parent().children('p.addMore').slideDown();
      }
    )
  ; $('#products') // Homepage: slidy produktů (click)
    .cycle // @see http://jquery.malsup.com/cycle/options.html
    ( { fx
        : 'scrollHorz'
      , slideExpr
        : '.product'
      , prev
        : '.prev'
      , next
        : '.next'
      , timeout
        : 0
      , cleartypeNoBg
        : true
      }
    )
  ; $('.product-folder .slide')
    .resize
    ( function ()
      { var nh = $(this).height();
        if (nh > 369) $(this).parent().css('height',nh+'px');
      }
    )
  ; $('.product-folder .slider .major') // Sortiment: slidy produktů (click)
    .cycle // @see http://jquery.malsup.com/cycle/options.html
    ( { fx
        : 'scrollHorz'
      , width
        : '635px'
      , after
        : function (ind, el) {
            $(this).css('overflow','');
            $(this).css('height','');
            //$(this).css('min-height','360px');
            $(this).parent().css('overflow','');
            $(this).parent().css('height','370px');
            //$(this).parent().css('min-height','360px');
            var loc = $('.slider .minor ul li.selected a').attr('href');
            if (typeof loc != 'undefined') {
              $('#sendlink').attr('href','mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html'+$('.slider .minor ul li.selected a').attr('href'));
              document.location.hash = $('.slider .minor ul li.selected a').attr('href');
            }
          }
      , pager
        : '.slider .minor ul'
      , pagerAnchorBuilder
        : function (ind, el) {
            var op =  [
                        '<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#svetly-lezak\';document.location.hash=\'svetly-lezak\'" href="#svetly-lezak">Budweiser Budvar Czech Premium Lager</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#svetle-vycepni-pivo\';document.location.hash=\'svetle-vycepni-pivo\'" href="#svetle-vycepni-pivo">Budějovický Budvar Pale Beer</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#tmavy-lezak\';document.location.hash=\'tmavy-lezak\'" href="#tmavy-lezak">Budweiser Budvar Premium Dark Lager</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#nealkoholicke-pivo\';document.location.hash=\'nealkoholicke-pivo\'" href="#nealkoholicke-pivo">Budweiser Budvar Non-alcoholic beer</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#krouzkovany-lezak\';document.location.hash=\'krouzkovany-lezak\'" href="#krouzkovany-lezak">Budweiser Budvar Krausened Lager</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#bud\';document.location.hash=\'bud\'" href="#bud">Bud Premier Select Special beer</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#pardal-echt\';document.location.hash=\'pardal-echt\'" href="#pardal-echt">Pardál Echt Pale Lager</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/o-spolecnosti/produkty/sortiment.html#pardal\';document.location.hash=\'pardal\'" href="#pardal">Pardál Pale Beer</a></li>'                      ];
            return ''+op[++ind]+'';
          }
      , pagerEvent
        : 'click.cycle'
      , activePagerClass
        : 'selected'
      , rev
        : 1
      , containerResize
        : 1
      , slideExpr
        : '.slide'
      , next
        : '.switch-slide'
      , timeout
        : 0
      , cleartypeNoBg
        : true
      }
    )
    ; $(document).ready( function() { // podpora odkazu primo na konkretni produkt nebo budvarku
      if (document.location.hash.length > 1) {
        var index = document.location.hash.substring(1);
        // var i = parseInt(index);
        var i = 0;
        switch(index) {
              case 'svetle-vycepni-pivo': i = 0; break;
                          case 'tmavy-lezak': i = 1; break;
                          case 'nealkoholicke-pivo': i = 2; break;
                          case 'krouzkovany-lezak': i = 3; break;
                          case 'bud': i = 4; break;
                          case 'pardal-echt': i = 5; break;
                          case 'pardal': i = 6; break;
                                        case 'ceske-budejovice': i = 0; break;
                            case 'praha': i = 1; break;
                            case 'litomerice': i = 2; break;
                            case 'tabor': i = 3; break;
                            case 'hodonin': i = 4; break;
                            case 'kolin': i = 5; break;
                    }
        $('.slider .major').cycle(i);
      }
    })
  ; $('.beerhouse-folder .slide') // Budvarky: slidy Budvarek (click)
    .resize
    ( function ()
      { var nh = $(this).height();
        if (nh > 519) $(this).parent().css('height',nh+'px');
      }
    )
  ; $('.beerhouse-folder .slider .major') // Budvarky: slidy Budvarek (click)
    .cycle // @see http://jquery.malsup.com/cycle/options.html
    ( { fx
        : 'scrollHorz'
      , width
        : '635px'
      , after
        : function (ind, el) {
            $(this).css('overflow','');
            $(this).css('height','');
            //$(this).css('min-height','360px');
            $(this).parent().css('overflow','');
            $(this).parent().css('height','520px');
            //$(this).parent().css('min-height','360px');
            var loc = $('.slider .minor ul li.selected a').attr('href');
            if (typeof loc != 'undefined') {
              $('#sendlink').attr('href','mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/restaurace/original-pivnice-budvarka.html'+$('.slider .minor ul li.selected a').attr('href'));
              document.location.hash = $('.slider .minor ul li.selected a').attr('href');
            }
          }
      , pager
        : '.slider .minor ul'
      , pagerAnchorBuilder
        : function (ind, el) {
            var op =  [
                        '<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/restaurace/original-pivnice-budvarka.html#ceske-budejovice\';document.location.hash=\'ceske-budejovice\'" href="#ceske-budejovice">Budvarka České Budějovice</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/restaurace/original-pivnice-budvarka.html#praha\';document.location.hash=\'praha\'" href="#praha">Budvarka Praha - Dejvice</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/restaurace/original-pivnice-budvarka.html#litomerice\';document.location.hash=\'litomerice\'" href="#litomerice">Budvarka Litoměřice</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/restaurace/original-pivnice-budvarka.html#tabor\';document.location.hash=\'tabor\'" href="#tabor">Budvarka Tábor</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/restaurace/original-pivnice-budvarka.html#hodonin\';document.location.hash=\'hodonin\'" href="#hodonin">Budvarka Hodonín</a></li>','<li><a onclick="document.getElementById(\'sendlink\').href=\'mailto:?subject=Budvar%20-%20Koukni%20na%20to&body=http://www.budejovickybudvar.cz/restaurace/original-pivnice-budvarka.html#kolin\';document.location.hash=\'kolin\'" href="#kolin">Budvarka Kolín</a></li>'                      ];
            return ''+op[ind]+'';
          }
      , pagerEvent
        : 'click.cycle'
      , activePagerClass
        : 'selected'
      , rev
        : 1
      , containerResize
        : 1
      , slideExpr
        : '.slide'
      , next
        : '.switch-slide'
      , timeout
        : 0
      , cleartypeNoBg
        : true
      }
    )
  ; $('#mini-gallery') // Podstránka: prolínání galerie "vpravo nahoře"
    .cycle // @see http://jquery.malsup.com/cycle/options.html
    ( { fx
        : 'fade'
      , slideExpr
        : '.gallery'
      , pager
        : '.switch'
      , pagerEvent
        : 'mouseover'
      , pagerAnchorBuilder
        : function(i){return '<span>'+(++i)+'</span>'}
      , activePagerClass
        : 'selected'
      , pause
        : true // "pause on hover"
      , timeout
        : 4000
      , speed
        : 600
      , cleartypeNoBg
        : true
      }
    )
  ; $('#gallery-list') // Homepage: slidy produktů (click)
    .cycle // @see http://jquery.malsup.com/cycle/options.html
    ( { fx
        : 'scrollUp'
      , after
        : function (currSlideElement, nextSlideElement, options, forwardFlag)
          { if ( options.currSlide == 0 ) $('.gallery-list-switch .prev').css('display','none');
              else $('.gallery-list-switch .prev').css('display','inline');
            if ( (options.currSlide + 1) == options.slideCount) $('.gallery-list-switch .next').css('display','none');
              else $('.gallery-list-switch .next').css('display','inline');
            $(this).parent().css('overflow','');
          }
      , slideExpr
        : '.gallery-list'
      , prev
        : '.prev'
      , next
        : '.next'
      , timeout
        : 0
      , cleartypeNoBg
        : true
      }
    )
  ; $('#gallery-list-switch span.next')
    .click
    ( function ()
      { $('#gallery-list-switch span.prev').css('display','inline');
        $('#gallery-list ul').animate
        ( { "top": "-=66px"
          }
        , 600
        );
        var topVal = $('#gallery-list ul').position().top;
        var heightVal = $('#gallery-list ul').height();
        if (132 > (heightVal + topVal)) $('#gallery-list-switch span.next').css('display','none');
      }
    )
  ; $('#gallery-list-switch span.prev')
    .click
    ( function ()
      { $('#gallery-list-switch span.next').css('display','inline');
        $('#gallery-list ul').animate
        ( { "top": "+=66px"
          }
        , 600
        );
        var topVal = $('#gallery-list ul').position().top;
        if (topVal >= -66) $('#gallery-list-switch span.prev').css('display','none');
      }
    )
  ; $('#mini-gallery .gallery a.mini-gallery') // page: proklik na fullsize
    .colorbox // @see http://colorpowered.com/colorbox/
    ( { transition
        : 'elastic'
      , opacity
        : 0.8
      , onOpen
        : function() { $('#mini-gallery').cycle('toggle') } // 'pause' mi nevím proč nefunguje jak bych čekal
      , onClosed
        : function() { $('#mini-gallery').cycle('resume', true) }
      /*, title
        : function()
          { return $('.title',this.parentNode).text()
          }*/
      , rel
        : 'mini-gallery'
      , initialWidth
        : 50  // dávám málo, aby se dostavil "nafukovací" efekt
      , initialHeight
        : 50
      , maxWidth
        : '90%'
      , maxHeight
        : '90%'
      , current
        : '{current}/{total}'   // ve stávajícím designu se stejně nezobrazí
      }
    )
  ; $("a.colorbox") // galerie: proklik na fullsize
    .colorbox // @see http://colorpowered.com/colorbox/
    ( { transition
        : 'elastic'
      , opacity
        : 0.8
      , initialWidth
        : 160  // dávám málo, aby se dostavil "nafukovací" efekt
      , initialHeight
        : 160
      , maxWidth
        : '90%'
      , maxHeight
        : '90%'
      , current
        : '{current}/{total}'
      }
    )
  ; $("a.colorbox-vt") // galerie: proklik na fullsize
    .colorbox // @see http://colorpowered.com/colorbox/
    ( { html
        : function() {
          var html =  '<div style="width: 950px; height: 390px; overflow: hidden;">' + "\n";
              html += '<!--[if !IE]> -->' + "\n";
              html += '<object width="950" height="390" data="' + $(this).attr('href') + '" type="application/x-shockwave-flash">' + "\n";
              html += '<!-- <![endif]-->' + "\n";
              html += '<!--[if IE]>' + "\n";
              html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="//download.macromedia.com/pub/shockwave/cabs/global_flash/swglobal_flash.cab#version=8,0,0,0" width="950" height="390">' + "\n";
              html += '<param name="movie" value="' + $(this).attr('href') + '" />' + "\n";
              html += '<!-->' + "\n";
              html += '<!--dgx-->' + "\n";
              html += '<param value="true" name="loop">' + "\n";
              html += '<param value="false" name="menu">' + "\n";
              html += '<param name="wmode" value="opaque">' + "\n";
              html += '<!-- <![endif]-->' + "\n";
              html += '</object>' + "\n";
              html += '</div>' + "\n";
          return html;
        }
      , width
        : 960
      , title
        : 'For 360° view, move the mouse cursor on the picture'
      , height
        : 420
      , current
        : '{current}/{total}'
      }
    )
  ; $('.previews a.img') // galerie: proklik na fullsize
    .colorbox // @see http://colorpowered.com/colorbox/
    ( { transition
        : 'elastic'
      , opacity
        : 0.8
      /*, title
        : function()
          { return $('.title',this.parentNode).text()
          }  */
      , rel
        : 'gallery'
      , initialWidth
        : 160  // dávám málo, aby se dostavil "nafukovací" efekt
      , initialHeight
        : 160
      , maxWidth
        : '90%'
      , maxHeight
        : '90%'
      , current
        : '{current}/{total}'
      }
    )
  ; $(".photo a, a.lightbox") // galerie pro oceneni a kontakty: proklik na fullsize
    .colorbox // @see http://colorpowered.com/colorbox/
    ( { transition
        : 'elastic'
      , opacity
        : 0.8
      , initialWidth
        : 160
      , initialHeight
        : 160
      , maxWidth
        : '90%'
      , maxHeight
        : '90%'
      , current
        : '{current}/{total}'
      }
    )
  ; $("a.google") // iframe pro google mapky
    .each
    ( function()
      {
        this.href = this.href + '?iframe=true';
      }
    )
  ; $("a.google") // iframe s google mapkami
    .colorbox // @see http://colorpowered.com/colorbox/
    ( {
      iframe
        : true
      , innerWidth
        : 660
      , innerHeight
        : 500
      , title
        : function()
          { return '<strong>' + $(this).attr('title') + '</strong>'
          }
      , current
        : '{current}/{total}'
      }
    )
  ; $('#mainMenu li ul').css('display','none')  // příprava dropdownu
  ; $('#mainMenu li').hover  // dropdown
    ( function( )
      { var $ul = $('> ul', this)
      ; if( $ul.is(':animated') )      // ještě probíhá fadeOut
        { $ul.stop(true,true).show(0) // cancel + show
        }
        else
        { $ul.slideDown(200)
        }
      }
    , function( )
      { var $ul = $('> ul', this)
      ; $ul.css('display','block').fadeOut(500,'swing')
      }
    )
  ; $('#award-type-switch ul li a')
    .click
    ( function ()
      { $('.award-type').css('display','none');
        $('#award-type-switch ul li a').removeClass('selected');
        $(this).addClass('selected');
        var id = '#award-type-' + $(this).attr('href').substr(1);
        if($.browser.msie)
        { $(id).css('display','block')
          return false;
        }
        else
        { $(id).fadeIn();
        }
      }
    )
  ; $('.full #year-list-switch span.right') // letopocty posun - prave tlacitko
    .click
    ( function ()
      { $('#year-list-switch span.left').css('display','block')
      ; $('#year-list ul').animate
        ( { "left": "-=320px"
          }
        , 600
        )
      ; var leftVal = $('#year-list ul').position().left
      ; var widthVal = $('#year-list ul').width()
      ; if (840 > (widthVal + leftVal)) $('#year-list-switch span.right').css('display','none')
      }
    )
  ; $('.full #year-list-switch span.left') // letopocty posun - leve tlacitko
    .click
    ( function ()
      { $('#year-list-switch span.right').css('display','block')
      ; $('#year-list ul').animate
        ( { "left": "+=320px"
          }
        , 600
        )
      ; var leftVal = $('#year-list ul').position().left
      ; if (leftVal >= -320) $('#year-list-switch span.left').css('display','none')
      }
    )
  ; $('.major #year-list-switch span.right') // letopocty posun - prave tlacitko
    .click
    ( function ()
      { $('#year-list-switch span.left').css('display','block')
      ; $('#year-list ul').animate
        ( { "left": "-=160px"
          }
        , 600
        )
      ; var leftVal = $('#year-list ul').position().left
      ; var widthVal = $('#year-list ul').width()
      ; if (480 > (widthVal + leftVal)) $('#year-list-switch span.right').css('display','none')
      }
    )
  ; $('.major #year-list-switch span.left') // letopocty posun - leve tlacitko
    .click
    ( function ()
      { $('#year-list-switch span.right').css('display','block')
      ; $('#year-list ul').animate
        ( { "left": "+=160px"
          }
        , 600
        )
      ; var leftVal = $('#year-list ul').position().left
      ; if (leftVal >= -160) $('#year-list-switch span.left').css('display','none')
      }
    )
  ; $('a.popupWindow') // popup okno pro kontakty [http://swip.codylindley.com/popupWindowDemo.html]
    .popupWindow({
      centerScreen:1, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
   height:570, // sets the height in pixels of the window.
   location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
   menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
   status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
   width:490, // sets the width in pixels of the window.
   toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
    })
  ; $('.major #year-list').ready // letopocty posun - tlacitka
    ( function ()
      { var widthVal = $('#year-list ul').width();
        if (480 > widthVal) $('#year-list-switch span.right').css('display','none');
      }
    )
  ; $('.full #year-list').ready // letopocty posun - tlacitka
    ( function ()
      { var widthVal = $('#year-list ul').width();
        if (840 > widthVal) $('#year-list-switch span.right').css('display','none');
      }
    )
  ; $('.full #year-list ul li a').hover // letopocty posun - tlacitka
    ( function ()
      { var leftVal = $('#year-list ul').position().left;
        var widthVal = $('#year-list ul').width();
        if (839 < (widthVal + leftVal)) {
          $('#year-list').css('width','880px');
          $('#year-list-switch span.right').css('right','5px');
        }
      }
    )
  ; $('#year-list ul li a').mouseout // letopocty posun - tlacitka
    ( function ()
      { $('#year-list').css('width','840px');
        $('#year-list-switch span.right').css('right','30px');
      }
    )
  ; $('.full #year-list').ready // letopocty posun na aktualni rok
    ( function ()
      { var widthVal = $('#year-list ul').width();
        if ( widthVal > 839 ) {
          var offset = 0;
          var end = false;
          var current = $('#year-list ul li a.selected').parent();
          while (!end) {
            if ( current.prev().length != 0 ) {
              current = current.prev();
              offset += 40;
            }
            else end = true;
          }
          var moveLeft = "-="+offset+"px";
          $('#year-list ul').animate({"left": moveLeft}, 600);
          if (offset > 0) $('#year-list-switch span.left').css('display','block');
        }
      }
    )
  ; $('a[href^="#:"]').each
    ( function(i)
      { this.href = ':otliam'.split('').reverse().join('') 
        + decodeURI
        ( this.href.split('#:')[1].replace(/%0A/gi,'¶¶¶¶')
        )
        .replace
        ( /\(zavin\u00E1\u010D\)/g
        , String.fromCharCode(30+30+4) 
        )
        .replace(/¶¶¶¶/g,'%0A')
      ; this.innerHTML = this.innerHTML
        .replace
        ( /\(zavin\u00E1\u010D\)/g
        , String.fromCharCode(30+30+4) 
        )
      }
    )     
  }
);
