$(document).ready(function(){
  
  //easySlider
  $("#slides").easySlider({
  		auto: true,
  		continuous: true,
  		speed: 1200,
  		pause: 3000,
  		controlsShow: false,
  		orientation: 'horizontal'
  	});
  
  //datepicker form de cadastro
  $("#nasc, #diagnostico").datepicker({
    changeMonth: true,
    changeYear: true,
    yearRange: '-100:+0',
    showOtherMonths: true,
    showMonthAfterYear: true,
	  maxDate: '0D',
	  dateFormat: 'dd/mm/yy',
	  monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
    monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
    dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'],
    dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab']
  });
  
  //insere medicamentos
  $('.add').live('click', function(){
    var repeat = $('.repeat').clone().removeClass('repeat');

    $('table tr:last').after(repeat);
    $('table tr:last #medicamento').val('');

    return false;
  })
  
  //styling select fields
  // $('.select').selectbox();
  //   $('.doses .selectbox-wrapper ul').addClass('small');
  //   $('.selectbox-wrapper ul li:first').addClass('first-child');
  //   $('.selectbox-wrapper ul.small li:first').addClass('first-child');
  //   $('p.glicosimetro .selectbox-wrapper ul li:first').addClass('first-child');
  //   $('p.glicUnid .selectbox-wrapper ul li:first').addClass('first-child');
  //   $('p.estado .selectbox-wrapper ul li:first').addClass('first-child');
  //   $('p.pais .selectbox-wrapper ul li:first').addClass('first-child');
  //   $('p.medicamentos .selectbox-wrapper ul li:first').addClass('first-child');
  
  //faq
  $('dd').hide();
  $('dt').click(function(){
    $('dd').slideUp();
    $(this).next('dd').slideDown();
  });
  
  //phone fields
  $(".phone").setMask();
  
  //indicar
  $('.indique').bind('click',function(event){
    $('#indicar').dialog('open');
    event.preventDefault();
  });
  
  $('#indicar').dialog({
    autoOpen: false,
		width: 450,
		height: 320,
		modal: false,
		resizable: false,
		title: 'Indique o Glicemias Online',
  });
  
  $('form#friends').submit(function(submit){
    submit.preventDefault();
    $.post("./actions/indicar", $("form#friends").serialize(), function(){
      $(':input','#friends')
       .not(':button, :submit, :reset, :hidden, #mensagem')
       .val('')
       .removeAttr('checked')
       .removeAttr('selected');
      $('#indicar').dialog('close');
    });
  });
  
})
