<script>
jQuery(function($) {
  var $ = jQuery;
  
  $('.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 ( attachment.sizes.thumbnail ) {
        jQuery("#" + target + "-thumb").attr("src", attachment.sizes.thumbnail.url);
      } else {
        jQuery("#" + target + "-thumb").attr("src", attachment.url);
      }

      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();
      }
    });
  }); 

  $(".colorsettings").hide();  
  $(".imagesettings").hide();
  $(".videosettings").hide();
  $(".okvideosettings").hide();
  $(".parallaxsettings").hide();
  $('.fullimagesettings').hide();

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

    $(".colorsettings").hide();
    $(".imagesettings").hide();
    $(".videosettings").hide();
    $(".okvideosettings").hide();

    switch(type) {
      case "color":
        $(".colorsettings").show();
        break;
      case "image":
        $(".imagesettings").show();
        $('.fullimagesettings').show();
        break;
      case "video":
        $(".videosettings").show();
        break;
      case "webvideo":
        $(".okvideosettings").show();
        break;
      default:
        $(".colorsettings").hide();
        $(".imagesettings").hide();
        $(".videosettings").hide();
        $(".okvideosettings").hide();
        break;
    }
  });

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

    $(".parallaxsettings").hide();
    $('.fullimagesettings').hide();

    switch(type) {
      case "parallax":
        $(".parallaxsettings").show();
        break;
      case 'full':
        $('.fullimagesettings').show();
        break;
      default:
        $(".parallaxsettings").hide();
        break;
    }
  });

});
</script>