<script>
  jQuery(function($) {
    var $ = jQuery;
    
    // Uploading files
      $('.upload_image_button').live('click', function( event ){
        event.preventDefault();
        var target = $(this).data('target-id');

        window.parent.loadImageFrame($(this), function(attachment) {
          jQuery("#" + target).val(attachment.id);

          if ( $('#preview-content').length > 0 ) {
            $('#preview').click();
          }
        });
    });

    $('.upload_video_button').live('click', function( event ){
        event.preventDefault();
        var target = $(this).data('target-id');

        window.parent.loadVideoFrame($(this), function(attachment) {
          jQuery("#" + target).val(attachment.id);

          if ( $('#preview-content').length > 0 ) {
            $('#preview').click();
          }
        });
    });

    $(".wpsettings").hide();
    $(".videosettings").hide();
    $(".youtubesettings").hide();
    $(".vimeosettings").hide();


    $("#video_type").change(function() {
      var type = $(this).val();

      $(".wpsettings").hide();
      $(".videosettings").hide();
      $(".youtubesettings").hide();
      $(".vimeosettings").hide();

      switch(type) {
        case "wordpress":
          $(".wpsettings").show();
          break;
        case "bliptv":
        case "collegehumor":
        case "dailymotion":
        case "flickr":
        case "funnyordie":
        case "hulu":
        case "revision3":
        case "screenr":
        case "ted":
        case "viddler":
        case "wordpresstv":
          $(".videosettings").show();
          break;
        case "vimeo":
          $(".videosettings").show();
          $(".vimeosettings").show();
          break;
        case "youtube":
          $(".videosettings").show();
          $(".youtubesettings").show();
          break;
        case "vevo":
          $(".videosettings").show();
          $('.vevosettings').show();
          break;
        default:
          $(".wpsettings").hide();
          $(".videosettings").hide();
          break;
      }
    });
  });
</script>