$(function(){

  //double up the email field
  $('#tdomf_form4').submit(function() {
    $("#customfields-tf-8-tf").val($('#autorespondemail_email').val());
  });

  //load audio
  $('#player-select').find('.player-track a').click(function(){
    loadaudio($(this).attr('href'));
    return false;
  });

  //open & load carousel slider
  /*
$('.single #toggle-slider, #toggle-slider2').click(function(){
    $('#slider-box').slideToggle('slow', function() {
      if ($(this).hasClass('inactive')){
        $('#polaroids-small').jcarousel({
          scroll: 2,
          visible: 2
        });
        $(this).removeClass('inactive');
      }
    });
    return false;
  });
*/

 $('#toggle-slider2').click(function(){
    $('#slider-box').slideToggle('slow', function() {
      if ($(this).hasClass('inactive')){
        $('#polaroids-small').jcarousel({
          scroll: 2,
          visible: 2
        });
        $(this).removeClass('inactive');
      }
    });
    return false;
  });



  
  //validate comment form
  $("#commentform").validate();

  $("#tdomf_form4").validate();

  //ie fix
  $('#tdomf_form4').find('.labelimg').click(function(){
    $('#' + $(this).attr('for')).focus();
    return false;
  });

  $('#tdomf_form4').find('.inputfield').focus(function() {
    $(this).siblings('.labelimg').animate({
      opacity: 0.07
    },{
      duration: 200,
      queue: false
    });
  });

  $('#tdomf_form4').find('.inputfield').blur(function(){
    if(!$(this).val()) {
      $(this).siblings('.labelimg').animate({
        opacity: 1
      },{
        duration: 200,
        queue: false
      });
    }
  });

  $('#tdomf_form4').find('.inputfield').each(function(){
    if($(this).val()){
      $(this).siblings('.labelimg').css({
        opacity:0.07
      });
    }
  });


  $('#resetform').click(function(){
    $('#tdomf_form4')[0].reset();
    $('#tdomf_form4').find('.inputfield').siblings('.labelimg').animate({
      opacity: 1
    },{
      duration: 200,
      queue: false
    });
    $('#tdomf_form4 label.error').css('display','none');

    return false;
  });


  $('#player-select .player-track a').click(function(){
    $('#player-select .player-track a').removeClass('active');
    $(this).addClass('active');
  })


});


//functions
function loadaudio(file){
  $("#jquery_jplayer_1").jPlayer("destroy");
  $('#jquery_jplayer_1').jPlayer({
    ready: function () {
      $(this).jPlayer("setMedia", {
        mp3:file
      }).jPlayer("play");
    },
   // swfPath: "/staging/coopers-demo/wp-content/themes/html5/libs/jplayer/js",
    swfPath: "/wp-content/themes/html5/libs/jplayer/js",
    supplied: "mp3"
  });
}



