// kontaktni formular

function contact_send(){
   
   $.ajax({
      type: "POST",
      url: "/cs/ajax/contact-send",
      data: {
        name: $("#c_name").val(),
        company: $("#c_company").val(),
        phone: $("#c_phone").val(),
        mail: $("#c_mail").val(),
        text: $("#c_text").val(),
        copy: $("#c_copy").attr('checked')
      },
      success: function(msg){
        contact_send_result(msg);
      }
   });
   
}

function contact_send_result(resp){
   if(resp == 'error_01'){
      $.slideNotice(lang_contact_send_result_error_01, { type: 'bad' });
   }
   else if(resp == 'error_02'){
      $.slideNotice(lang_contact_send_result_error_02, { type: 'bad' });
   }
   else if(resp == 'ok'){
      document.forms['contact'].reset();
      $.slideNotice(lang_contact_send_result_ok, { type: 'good' });
   }
}

// header switcher

var switch_visible = 1;
var switch_timer;
var switch_duration = 800;
var switch_timeout = 8000;

$(document).ready(function(){
   
   if($("#switch_images .img_box").length > 1){
      
      var width = parseInt($("#switch_images").width());
      
      $("#switch_images")
         .css({
            position: 'relative',
            overflow: 'hidden'
         })
         .find(".img_box:not(:first)")
            .css({ left: width+'px', display: 'block' });
      
      switch_timer = setTimeout(function(){ switch_move_in(); }, switch_timeout);
      
   }
   
});

function switch_move_in(id){
   
   clearTimeout(switch_timer);
   
   // nic, pokud se pozadovane id rovna aktualnimu
   
   if(id != switch_visible){
   
      // zjisteni dalsiho ve fronte (pozadovany parametrem id / dalsi ve fronte)
      
      var switch_next = (id) ? id : (switch_visible + 1);
      if($("#header_img_"+switch_next).length != 1) switch_next = 1;
      
      // nic, pokud se jeste animuje predchozi
      
      if(!$("#header_img_"+switch_visible).is(":animated")){
         
         // zobrazeni noveho
         
         $("#header_img_"+switch_next)
            .animate({ left: '0px' }, switch_duration);
      
         // skryti stareho a zobrazeni noveho popisu
         
         $("#header_desc_"+switch_visible).fadeOut(switch_duration / 2 + 20);
         setTimeout(function(){
            $("#header_desc_"+switch_next).fadeIn(switch_duration / 2);
         }, switch_duration / 2);
          
         // odznaceni stareho a oznaceni noveho buttonku
         
         $("#header_link_"+switch_visible).parent('li').removeClass('slc');
         setTimeout(function(){
            $("#header_link_"+switch_next).parent('li').addClass('slc');
         }, switch_duration);
         
         // odsunuti aktualniho a nastaveni noveho
         
         switch_move_out();
         
         switch_visible = switch_next;
         
      }
   
   }
   
   switch_timer = setTimeout(function(){ switch_move_in(); }, switch_timeout);
   
}

function switch_move_out(){
   
   // odsunuti vlevo do skryte oblasti a nasledne vraceni zpet do zasobniku
   
   $("#header_img_"+switch_visible)
      .animate({ left: '-'+$("#switch_images .img_box").outerWidth()+'px' }, switch_duration)
      .animate({ left: $("#switch_images .img_box").outerWidth()+'px' }, 1);
   
}
