$(document).ready(function(){
      
      /* cufon START */
      if (Cufon && Cufon.replace) {
            Cufon.replace('div#discussion-box-in a, a#motto-more, a#motto-more-news, div#motto-box h2, div#news-in h2, div#news-content div.item div.calendar strong, div#footer div.contacts span, div.consultation .item_in h3, #login p#school');
            /* -- all the changes? -- */
      }
      /* cufon END */

      
      /* login-form */
      /*
      if($('#frmloginForm-login').val() != ''){
            $('#frmloginForm-login').prev().hide();
      }
      if($('#frmloginForm-pswd').val() != ''){
            $('#frmloginForm-pswd').prev().hide();
      }
      
      $('#frmloginForm-login').focus(function(){  
            if($(this).val() == ''){
                  $(this).prev().hide();
            }
      }) 
      $('#frmloginForm-login').blur(function(){
            if($(this).val() == ''){
                  $(this).prev().show();
            }
      })  

      $('#frmloginForm-pswd').focus(function(){
            if($(this).val() == ''){
                  $(this).prev().hide();
            }
      }) 
      $('#frmloginForm-pswd').blur(function(){
            if($(this).val() == ''){
                  $(this).prev().show();
            }
      })  
      
      $('input[name=email]').focus(function(){ 
            if($(this).val() == ''){
                  $(this).val('@');
            }
      })
      */
      
      $('input.uppercaseAlert').keypress(function(e) {
            var cc=e.charCode;
            if (typeof cc=='undefined'){
                  cc=e.keyCode;
            }
            var character=String.fromCharCode(cc);
            if ((/^[A-Z]$/.test(character) && !e.shiftKey) || (/^[a-z]$/.test(character) && e.shiftKey)){
                  alert("Vypněte si prosím CapsLock.");
            }
      });
      
      $('select[func=onchangeSubmit]').change(function(){ 
            $('body').append('<div title="Prosím čekejte" class="dlg-app"><span class="commonSpinner">...</div>');   
            dialog = $('.dlg-app').dialog({modal: true});
            dialog.dialog('open');
            this.form.submit();
      })
      $('input[func=onblurSubmit]').blur(function(){ 
            $('body').append('<div title="Prosím čekejte" class="dlg-app"><span class="commonSpinner">...</div>');   
            dialog = $('.dlg-app').dialog({modal: true});
            dialog.dialog('open');
            this.form.submit();
      })
      

      $('.gallery-thumbs a, .thumbnail').colorbox({
            transition: 'elastic',
            fixed: true,

            current: 'obrázek č. {current} z {total}',

            slideshow: false,
            slideshowSpeed: 3000,
            slideshowAuto: false,
      })
      
      
      $('.h2_toggle h2').each(function(){
            $(this).next().hide();
      })
      $('.h2_toggle h2:first').addClass("act").next().show();
      $('.h2_toggle h2').click(function(){
            if($(this).next().is(":visible")){  
                  $(this).next().slideUp();
                  $(this).removeClass("act");            
            }else{
                  $(this).next().slideDown();
                  $(this).addClass("act");
            }
      })
      
      
      /*********** header spinner ************/
      function spinTo(index){
            if($('#hp_banner_nav a[class=act]').attr('href').replace('#', '') == index){ // if is the same, do nothing
                  return;
            }
            $('#hp_banner_wheeler .item').hide();
            $('#hp_banner_wheeler .item.item'+index).fadeIn(2000);
            $('#hp_banner_nav a').removeClass('act');                      
            $('#hp_banner_nav a[href=#'+index+']').addClass('act');
            $('.consultation .spiner').css('left', 0);
            
      }
      
      $('#hp_banner_nav a').click(function(){
            spinTo($(this).attr('href').replace('#', ''));
      })
      
      f = function(){
            index = $('#hp_banner_nav a[class=act]').attr('href').replace('#', '');
            ++index;
            if(index > 3){
                  index = 1;
            }
            if($('#hp_banner_photo').attr('data-fixed') != 1){
                  spinTo(index);
                  setTimeout(f, 10000);   
            }
      }
      setTimeout(f, 10000); 
      
      $('#hp_banner_photo').click(function(){
            $(this).attr('data-fixed', 1);
      })

      
      /***************** header list slider *************/
      
      //('#consultation .spinner')
      
      
      function moveBoxLeft(){
            left = $('.consultation .spiner').css('left').replace('px', '');
            if(left < 0){
                  $('.consultation .spiner').animate({
                        left: (left <= '398' ? '0'  :'+=398px'), 
                  }, 1000)   
            }else{
                  max = ((398 * 2) + (398 / 3));  
                  $('.consultation .spiner').animate({
                        left: '-'+max+'px', 
                  }, 1000)  
            }
      };  
      $('.consultation .consultation_left').bind('click', function(){ 
            moveBoxLeft();
      });
      
      
      function moveBoxRight(){
            left = $('.consultation .spiner').css('left').replace('px', ''); 
            max = -((398 * 2) + (398 / 3));
            if((left - 398) < max){ 
                  move = (max - 398 - (left - 398)) * -1;
            }else{
                  move = 398;
            }       
            move = move.toInt();
            if(move > 1){
                  $('.consultation .spiner').animate({
                        left: ('-='+move+'px'),
                  }, 1000)
            }else{
          $('.consultation .spiner').animate({
                        left: ('0px'),
                  }, 1000)
            }
      };
      $('.consultation .consultation_right').bind('click', function(){ 
            moveBoxRight();
      });
                 
      
      

});
