$(document).ready(function() {

var sc_base_url = base_url.replace("eurotax", "");

  function contact_submit(type) {
    text = $('#cf_text'+type).val();
	  name = $('#cf_name'+type).val();
	  phone = $('#cf_phone'+type).val();
	  email = $('#cf_email'+type).val();
	  subject = $('#cf_subject'+type).val();
	  url = $('#cf_url'+type).val();
	  
    var msg = '';
    if(!name) { 
      msg = msg + 'Musíte zadat Vaše jméno\n';
    }
    if(!email) { 
      msg = msg + 'Musíte zadat Váš email\n';
    }
    if(!text) { 
      msg = msg + 'Musíte zadat text dotazu\n';
    }
    if(msg) {
      alert(msg);
      return false;
    }
    
    $.get(sc_base_url + 'jquery_php/contact_form_send_email.php', 
      {text: text, name: name, phone: phone, email: email, subject: subject, url: url },
      function(data) {       
        
         if(data) {
           $('#ok_row'+type).show();          
           $('#cf_text'+type).val('');
           $('#cf_contact_form_ext'+type).hide();
           $('#contact_form_content' + type + ' .submit_cover').hide();
         //  $('#cf_text').hide();
         }
	    } 
    );
  }
  //contact_submit
	
  $('#contact_submit').click(function(event) { 
    contact_submit('');
    return false;
	}); //#contact_submit
	
	
  $('#contact_submit_footer').click(function(event) { 
      contact_submit('_footer');
      return false;
  }); //#contact_submit2
	
	$('#cf_send_again').click(function(event) { 
	    $('#ok_row').hide();
      $('#cf_contact_form_ext').show();  
	    $('#contact_form_content .submit_cover').show();
	    return false;
	});
	
	$('#cf_send_again_footer').click(function(event) { 
	    $('#ok_row_footer').hide();
      $('#cf_contact_form_ext_footer').show();  
	    $('#contact_form_content_footer .submit_cover').show();
	    return false;
	});
	
	$('#cms_send_email').click(function(event) { 
	    $('#form_email2friend').toggle();  
	    /*
      if(!$('#contact_form_content').is(":visible") ) {       
        $('#contact_form_content').show();  
        $('#form_email2friend').show();  
      } 
      */
	    return false;
		});
		
	$('#cf_title_toggle').click(function(event) { 
	    $('#contact_form_content').toggle();  
	    return false;
		});
		
	$('#e2f_send_again').click(function(event) { 
	    $('#e2f_cover').show();  
	    $('#ok_row_e2f').hide();
	    return false;
		});
	
	$('#email2friend_submit').click(function(event) { 
	  name = $('#e2f_name').val();
	  email = $('#e2f_email').val();
	  name_recip = $('#e2f_name_recipient').val();
	  email_recip = $('#e2f_email_recipient').val();
	  subject = $('#e2f_subject').val();
	  url = $('#e2f_url').val();
	  
	  var msg = '';
    if(!name) { 
      msg = msg + 'Musíte zadat Vaše jméno\n';
    }
    if(!email) { 
      msg = msg + 'Musíte zadat Váš email\n';
    }
    if(!name_recip) { 
      msg = msg + 'Musíte zadat jméno příjemce\n';
    }
    if(!email_recip) { 
      msg = msg + 'Musíte zadat email příjemce\n';
    }
    if(msg) {
      alert(msg);
      return false;
    }
    
    
    $.get(sc_base_url + 'jquery_php/email2friend_send.php', 
      {name: name, email: email, name_recip: name_recip, email_recip:email_recip, subject: subject, url: url },
      function(data) {              
         if(data) {
           $('#e2f_cover').hide();          
           $('#e2f_name_recipient').val('');
           $('#e2f_email_recipient').val('');
           $('#ok_row_e2f').show();
         }
	    } 
    );
    
    return false;
	});
	
	

	
	$('.cp_jquery_save').change(function(event) { 
	   name = $(this).attr('name');
	   value = $(this).val();
	   id = $('#id').val();
	   
     $.get(sc_base_url + 'jquery_php/online_jquery_save.php', 
      {id:id, name: name, value: value, table: 'ti_data', step: 4},
      function(data) {              
	      
      } 
    );
   
  });
  
  $('.cp_jquery_ch_save').click(function(event) { 
    if($(this).is(":checked")) {
      value = 1;
    } else {
      value = 0;
    }
    name = $(this).attr('name');
    id = $('#id').val();
    $.get(sc_base_url + 'jquery_php/online_jquery_save.php', 
      {id:id, name: name, value: value, table: 'ti_data', step: 4},
      function(data) {              
	    } 
    );
    
  });
  

  $('#dl_count').change(function(event) { 
    var dl_count = $(this).val();
    //if(!$('#dl_castka').val()) {
      var dl_course = $('#dl_course').val();
      var dl_castka = dl_count * dl_course;
      dl_castka = Math.ceil(dl_castka);
      $('#dl_castka').val(dl_castka);
    //}
  });
  
  
  $('#dl_castka').change(function(event) { 
     var dl_castka = $(this).val();
     var dl_course = $('#dl_course').val();
     
     if(dl_castka) {
      var dl_count = dl_castka / dl_course;
    
      var dl_count_top = Math.ceil(dl_count);
      var dl_count_bottom = Math.floor(dl_count);
     } else {
       $('#dl_count_vyber').hide();
       $('#dl_count').show();
     }
     

     if(dl_count_top > dl_count_bottom) {
       $('#dl_count').hide();
       $('#dl_count_vyber').show();
       
       $('#l_dl_count_t').html(dl_count_top);
       $('#dl_count_t').val(dl_count_top);
       
       $('#l_dl_count_b').html(dl_count_bottom);
       $('#dl_count_b').val(dl_count_bottom);
     } else {
       $('#dl_count').val(dl_count_top);
     }
   
     /*
     $.get(sc_base_url + 'jquery_php/obligation.php', 
      {dl_castka: $(this).val(), action: 'get_dl_count'},
      function(data) {              
	      alert(data);
      } 
    );
    */
  });
  
  //prepinac subjektu - dluhopisovy formular
  $('#dl_subjekt').change(function(event) { 
    if($(this).val() == 2) {
      $('.dl_osoba_cover').hide();
      $('.dl_firma_cover').show();
    } else {
      $('.dl_osoba_cover').show();
      $('.dl_firma_cover').hide();
    }
  });
  
  
  
  //prepinac subjektu
  $('#subject').change(function(event) { 
    if($(this).val() == 'po') {
      $('#fo_cover').hide();
      $('#po_cover').show();
    } else {
      $('#fo_cover').show();
      $('#po_cover').hide();
    }
  });
  
  // END CP -----------
	
  $('.show_dialog_box_help').click(function(event) { 
      var a_title = $(this).attr('title');
      $("#dialog_box_help").dialog({title: a_title, modal: true, width: 600, closeOnEscape: true});
      return false;
  });
  
  $(".product-scroll .bw_pz_box").hover(
    function () {
      product_wide_box_ins_change($(this),'left');
      
    }, 
    function () {}
  );
  $(".product-scroll .bw_pz_box_active").hover(
    function () {
      product_wide_box_ins_change($(this),'left');   
    }, 
    function () {}
  );
  
  $('.switcher').click(function(event) { 
      var id2show = $(this).attr('id');    
      $('.switcher').removeClass('switcher_act');  
      $(this).addClass('switcher_act');  
      $('.switcher_covs').hide();
      $('#'+id2show+'_cov').show();
      return false;
  });
  
  $('a.minus').click(function(event) { 
    minus_plus_click($(this).attr('id'));
    return false;
  });
  
  $('a.plus').click(function(event) { 
    minus_plus_click($(this).attr('id'));
    return false;
  });
  
  function minus_plus_click(id) {
     $('#'+id+'_cov').toggle();
     var curr_class = $('#'+id).attr('class');
 
     var new_class = 'minus';
     if(curr_class == 'minus') { var new_class = 'plus'; }
     $('#'+id).removeClass(curr_class).addClass(new_class);
  }
  
  $('#g_input').click(function(event) { 
    if($('#g_input').val() == 'Zde zadejte hledaný text') {
      $('#g_input').val('');
    }
  });
  $('#g_input').blur(function(event) { 
    if($('#g_input').val() == '') {
      $('#g_input').val('Zde zadejte hledaný text');
    }
  });
  
  
  $('#ef_group').change(function(event) { 
    if($(this).val() == '') return false;
    window.location = $(this).val();
  });
  
  
/*
  $('#products_slider_right').click(function(event) { 
    $(".box_wide_products_zone").hide();
	  $(".box_wide_products_zone2").show();
	  $(".count_nav").html('5-8 z 8');
  });
  $('#products_slider_left').click(function(event) { 
    $(".box_wide_products_zone2").hide();
	  $(".box_wide_products_zone").show();
	  $(".count_nav").html('1-4 z 8');
	  
  });
*/
	
  //kalendar JQuery UI
	  $('#datumPrvniRegistrace').datepicker({
	     showOn: 'button',
			 buttonImage: '/images/icons/calendar-green.jpg',
			 buttonImageOnly: true,
				monthNames: ['Leden','Únor','Březen','Duben','Květen','Červen',
			'Červenec','Srpen','Září','Říjen','Listopad','Prosinec'],
			dayNames: ['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'],
			dayNamesMin: ['Ne','Po','Ut','St','Čt','Pa','So'],
			numberOfMonths: 2,
	    firstDay: 1
	   });
	  
	   $('#first_registration').datepicker({
	     showOn: 'button',
			 buttonImage: '/images/icons/calendar-green.jpg',
			 buttonImageOnly: true,
				monthNames: ['Leden','Únor','Březen','Duben','Květen','Červen',
			'Červenec','Srpen','Září','Říjen','Listopad','Prosinec'],
			dayNames: ['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'],
			dayNamesMin: ['Ne','Po','Ut','St','Čt','Pa','So'],
			yearRange: '1900:2013',
			numberOfMonths: 2,
	    firstDay: 1
	   });
	   
	   $('input:text.datum').datepicker({
	     showOn: 'button',
			 buttonImage: '/images/icons/calendar-green.jpg',
			 buttonImageOnly: true,
			 changeYear: true,
				monthNames: ['Leden','Únor','Březen','Duben','Květen','Červen',
			'Červenec','Srpen','Září','Říjen','Listopad','Prosinec'],
			dayNames: ['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'],
			dayNamesMin: ['Ne','Po','Ut','St','Čt','Pa','So'],
	    firstDay: 1,
	    numberOfMonths: 2,
	    yearRange: '1920:2013'
	   });
	   
	   
	   var day = new Date();
	   day.setDate(day.getDate()+1);
	   var den_tyden = day.getDay();
	   if(den_tyden == 6) {
	     day.setDate(day.getDate()+2);
	   } else if(den_tyden == 0) {
	     day.setDate(day.getDate()+1);
	   }
	   $('#pocatek').datepicker({
	     showOn: 'button',
			 buttonImage: '/images/icons/calendar-green.jpg',
			 buttonImageOnly: true,
				monthNames: ['Leden','Únor','Březen','Duben','Květen','Červen',
			'Červenec','Srpen','Září','Říjen','Listopad','Prosinec'],
			dayNames: ['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'],
			dayNamesMin: ['Ne','Po','Ut','St','Čt','Pa','So'],
	    firstDay: 1,
	    numberOfMonths: 2,
	    minDate: day
	   });
	   //$('#datumPrvniRegistrace').datepicker('option', {minDate: day});
	  //-----------------
    
    
  //PRODUCTY H SCROLL
  $('.product-scroll').each(function(){
        var $this = $(this)
        var scroll = {
            el: $('ul', this)
            ,elWidth: function(){return scroll.el.width();}
            ,elScroll: function(){return scroll.el[0].scrollWidth;}
            ,elScrollL: function(){return scroll.el[0].scrollLeft;}
            ,itemWidth: function(){return $('li', scroll.el).width();}
            ,coef: 1
            ,hover: function(e){
                e = e || window.event;
                if(e.type == 'mouseenter'){
                    $(e.target).addClass('hover');
                }
                else if(e.type == 'mouseleave'){
                    $(e.target).removeClass('hover');
                }   
            }
            ,controlN: function(){
                  if(left + scroll.elWidth() >= scroll.elScroll()){
                      $('.next', $this).fadeTo("fast", 0.33).addClass('disable').removeClass('hover').unbind();
                  }
                  if($('.prev', $this).is('.disable') && left > 0){
                      $('.prev', $this).fadeTo("fast", 1).removeClass('disable').click(scroll.prev).bind('mouseenter mouseleave', scroll.hover);
                  }
            }
            ,controlP: function(){
                if(left <= 0){
                    $('.prev', $this).fadeTo("fast", 0.33).addClass('disable').removeClass('hover').unbind();
                }
                if($('.next', $this).is('.disable') && left + scroll.elWidth() < scroll.elScroll()){
                    $('.next', $this).fadeTo("fast", 1).removeClass('disable').click(scroll.next).bind('mouseenter mouseleave', scroll.hover);
                }
            }
            ,next: function(){
                scroll.el.stop();
                var length = scroll.itemWidth() * 5 * scroll.coef;
                left = left + length;
                scroll.controlN();
                scroll.el.animate({
                    scrollLeft: left +'px'
                }, 300*scroll.coef);        
            }
            ,prev: function(){
                scroll.el.stop();
                var length = scroll.itemWidth() * 5 * scroll.coef;
                left = left - length;
                scroll.controlP();
                scroll.el.animate({
                    scrollLeft: left +'px'
                }, 300*scroll.coef);        
            }
        };
        if(scroll.elWidth() < scroll.elScroll() ){
            $this.append('<span class="prev"></span><span class="next"></span>');
            var left = scroll.elScrollL();
            scroll.el.css('overflow-x', 'hidden');
            scroll.controlN();
            scroll.controlP();
            $('.next:not(.disable)', this).click(scroll.next).bind('mouseenter mouseleave', scroll.hover);
            $('.prev:not(.disable)', this).click(scroll.prev).bind('mouseenter mouseleave', scroll.hover);
        }
        else{
            $('.product-list-mini-scroll').addClass('no-scroll').removeClass('product-list-mini-scroll');
        }
    });
    /* END producty HP SCROLL */
    
})



setInterval( "test_timer()", 5000 );
function product_wide_box_ins_change(curr_id,type) {
  //if(curr_id.attr('class') == 'bw_pz_box_active') { return false; }
  var id2show = curr_id.attr('id').substring(3);
  
  //var id2hide = $(".product_box_wide_"+type+" .bw_pz_box_active").attr('id').substring(3);
  

  $(".bw_pz_box_active .bw_pz_box_sipka").hide();
  $(".bw_pz_box_active").attr('class','bw_pz_box');
  curr_id.attr('class','bw_pz_box_active');
    
  $(".bw_pz_box_active .bw_pz_box_sipka").show();
  
  if($("#"+id2show)) {
    $(".ins_box").hide();
    $("#"+id2show).show();
  }
}

function test_timer(){
  if($('#companies_logos_1').css('display') == 'none') {
    $('#companies_logos_2').hide();
    $('#companies_logos_1').show(1000);
  } else {
    $('#companies_logos_1').hide();
    $('#companies_logos_2').show(1000);
  }
}




 

