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

		$(".htmlsettings").hide();
		$(".iframesettings").hide();

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

			$(".htmlsettings").hide();
			$(".iframesettings").hide();
			$(".imagesettings").hide();

			switch(type) {
				case "html":
					$(".htmlsettings").show();
					break;
				 case "iframe":
					$(".iframesettings").show();
					break;
				 case "image":
					$(".imagesettings").show();
					break;
			}
		});

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

		$("#content_type").children().attr('disabled','disabled');

		switch(type) {
			case "colorbox":
			case "magnificpopup":
			case "prettyphoto":
				$("#content_type").children().removeAttr('disabled');
			break;
			default:
				$("#content_type").children('[value="image"]').removeAttr('disabled');
				$("#content_type").val('image');
				$("#content_type").change();
			break;
		}
		});
	});
</script>