<mt:setvar name="page_title" value="<__trans phrase="Edit Asset">">
<mt:setvar name="position_actions_bottom" value="1">
<mt:setvar name="edit_screen" value="1">

<mt:setvarblock name="system_msg">
<mt:if name="error">
  <mtapp:statusmsg
     id="generic-error"
     class="error"
     can_close="0">
    <mt:var name="error">
  </mtapp:statusmsg>
</mt:if>
<mt:if name="saved">
  <mt:if name="can_rebuild">
  <mtapp:statusmsg
     id="saved"
     class="success"
     rebuild="all"
     can_close="0">
    <__trans phrase="Your changes have been saved.">
  </mtapp:statusmsg>
  <mt:else>
  <mtapp:statusmsg
     id="saved"
     class="success">
    <__trans phrase="Your changes have been saved.">
  </mtapp:statusmsg>
  </mt:if>
</mt:if>
</mt:setvarblock>

<mt:setvarblock name="related_content">
<mtapp:widget
   id="asset-stats-widget"
   class="stats-widget"
   label="<__trans phrase="Stats">">
  <ul class="object-stats">
    <li><__trans phrase="[_1] - Created by [_2]" params="<$mt:date ts="$created_on_ts" relative="1" _default="$created_on_formatted" format="%b %e %Y"$>%%<$mt:var name="created_by" escape="html" escape="html"$>"></li>
  <mt:if name="modified_by">
    <li><__trans phrase="[_1] - Modified by [_2]" params="<$mt:date ts="$modified_on_ts" relative="1" _default="$modified_on_formatted" format="%b %e %Y"$>%%<$mt:var name="modified_by" escape="html" escape="html"$>"></li>
  </mt:if>
  </ul>
</mtapp:widget>

<mt:if name="show_appears_in_widget">
<mtapp:widget
   id="appears-in"
   label="<__trans phrase="Appears in...">">
  <ul>
  <mt:loop name="appears_in">
    <li><a href="<mt:var name="script_url">?__mode=view&amp;_type=<mt:var name="class">&amp;blog_id=<mt:var name="blog_id" escape="url">&amp;id=<mt:var name="id" escape="url">" class="icon-left icon-<mt:var name="class" lower_case="1">"><mt:var name="title" escape="html" default="..."></a></li>
  </mt:loop>
  </ul>
  <mt:if name="appears_in_uneditables">
    <span class="hint"><__trans phrase="This asset has been used by other users."></span>
  </mt:if>
</mtapp:widget>
</mt:if>

<mt:if name="related">
  <mtapp:widget
     id="related-assets"
     label="<__trans phrase="Related Assets">">
  <mt:loop name="related">
    <div class="asset asset-type-<mt:var name="asset_type" escape="html" lower_case="1">">
      <div class="asset-thumb thumbnail picture small<mt:if name="file_is_missing"> asset-type-icon missing</mt:if><mt:unless name="has_thumbnail"> asset-type-icon</mt:unless>">
        <a href="<$mt:var name="script_url"$>?__mode=view&amp;_type=<mt:var name="object_type">&amp;id=<$mt:var name="id" escape="url"$>&amp;blog_id=<$mt:var name="blog_id" escape="url"$>" title="<$mt:var name="file_name" escape="html"$>">
        <mt:if name="has_thumbnail">
          <mt:unless name="file_is_missing"> 
          <img src="<mt:var name="thumbnail_url" escape="html">?ts=<mt:var name="modified_on" escape="url">" width="<mt:var name="thumbnail_width" escape="html">" height="<mt:var name="thumbnail_height" escape="html">"<mt:if name="thumbnail_width"> style="padding: <$mt:var name="thumbnail_height_offset"$>px <$mt:var name="thumbnail_width_offset"$>px"</mt:if> />
          <mt:else>
          <img src="<mt:var name="static_uri">images/asset/<mt:var name="asset_type" escape="html" lower_case="1">-warning-45.png" class="asset-type-icon asset-type-<mt:var name="asset_type" escape="html" lower_case="1"> missing" />
          </mt:unless>
        <mt:else>
          <img src="<mt:var name="static_uri">images/asset/<mt:var name="asset_type" escape="html" lower_case="1">-45.png" class="asset-type-icon asset-type-<mt:var name="asset_type" escape="html" lower_case="1">" />
        </mt:if>
        </a>
      </div>
      <div class="asset-metadata">
        <ul class="metadata">
          <li class="metadata-item asset-label"><a href="<$mt:var name="script_url"$>?__mode=view&amp;_type=<mt:var name="object_type">&amp;id=<$mt:var name="id" escape="url"$>&amp;blog_id=<$mt:var name="blog_id"$>" title="<$mt:var name="file_name" escape="html"$>"><mt:var name="label" escape="html"></a></li>
          <li class="metadata-item asset-size"><mt:if name="class" eq="image"><mt:var name="image_width" escape="html"> &times; <mt:var name="image_height" escape="html"> - </mt:if><mt:var name="file_size_formatted" escape="html"></li>
          <li class="metadata-item datetime"><mt:var name="created_on_formatted"></li>
          <!-- <mt:if var="is_parent">(parent)</mt:if><mt:if var="is_child">(child)</mt:if><mt:if var="is_sibling">(sibling)</mt:if> -->
        </ul>
      </div>
    </div>
  </mt:loop>
  </mtapp:widget>
</mt:if>
  <mtApp:PageActions>
</mt:setvarblock>

<mt:setvarblock name="object_nav">
<ul class="object-nav">
  <li id="previous-link"><mt:if name="previous_entry_id"><a href="<mt:var name="script_url">?__mode=view&amp;_type=asset&amp;id=<mt:var name="previous_entry_id" escape="url">&amp;blog_id=<mt:var name="blog_id" escape="url">">&lsaquo; <__trans phrase="Prev"></a><mt:else><span>&lsaquo; <__trans phrase="Prev"></span></mt:if></li>
  <li id="next-link"><mt:if name="next_entry_id"><a href="<mt:var name="script_url">?__mode=view&amp;_type=asset&amp;id=<mt:var name="next_entry_id" escape="url">&amp;blog_id=<mt:var name="blog_id" escape="url">"><__trans phrase="Next"> &rsaquo;</a><mt:else><span><__trans phrase="Next"> &rsaquo;</span></mt:if></li>
</ul>
</mt:setvarblock>

<mt:setvarblock name="html_head" append="1">
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/focus.js"></script>
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/tagcomplete.js"></script>
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/client.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
var tag_delim = '<mt:var name="auth_pref_tag_delim">';

// array of tag names
var tagList;

function tagSplit(str) {
    var delim = RegExp.escape(tag_delim);
    var delim_scan = new RegExp('^((([\'"])(.*?)\\3[^' + delim + ']*?|.*?)(' + delim + '\\s*|$))', '');
    str = str.replace(/(^\s+|\s+$)/g, '');
    var tags = [];
    while (str.length && str.match(delim_scan)) {
        str = str.substr(RegExp.$1.length);
        var tag = RegExp.$4 ? RegExp.$4 : RegExp.$2;
        tag = tag.replace(/(^\s+|\s+$)/g, '');
        tag = tag.replace(/\s+/g, ' ');
        if (tag != '') tags.push(tag);
    }
    return tags;
}

var autoTag;
<mt:if name="tags_js">
tagList = <mt:var name="tags_js">;
</mt:if>

function init()
{
    <mt:if name="tags_js">initTags();</mt:if>
}

var tagPos = 0;
function initTags() {
    var t = getByID('tags-cache');
    if ( t ) {
        log('tag cache:'+t.value);
        var v = getByID('tags');
        if ( t.value )
            v.value = t.value;
        DOM.addEventListener( v, "change", function() { log('caching tags'); t.value = v.value; } );
    }
    if (!tagList || tagList.length == 0) return;

    autoTag = new TC.TagComplete("tags", tagList);
    autoTag.delimiter = tag_delim;
}

TC.attachLoadEvent( init );
/* ]]> */
</script>
</mt:setvarblock>

<mt:include name="include/header.tmpl">

<div id="asset" class="status-<mt:if name="file_is_missing">missing<mt:else>publish</mt:if><mt:unless name="file_is_missing"> <mt:if name="has_thumbnail">asset-thumbnail<mt:else>asset-no-thumbnail</mt:if></mt:unless>">
  <form id="edit_asset" method="post" action="<mt:var name="script_url">">
    <input type="hidden" name="blog_id" value="<mt:var name="blog_id">" />
    <input type="hidden" name="__mode" value="save" />
    <input type="hidden" name="_type" value="<mt:var name="object_type">" />
    <input type="hidden" name="id" value="<mt:var name="id" escape="html">" />
    <input type="hidden" name="return_args" value="<mt:var name="return_args" escape="html">" />
    <input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />
    <input type="hidden" name="asset_type" value="<mt:var name="asset_type" escape="html">" />

    <div class="asset-preview asset-type-<mt:var name="asset_type" escape="html" lower_case="1"> line">
    <mt:if name="file_is_missing">
      <mtapp:statusmsg
         id="file-missing-error"
         class="error"
         can_close="0">
        <__trans phrase="[_1] is missing" params="<mt:var name="asset_class_label" escape="html">">
      </mtapp:statusmsg>
    <mt:else>
      <mt:if name="has_thumbnail">
      <div class="asset-preview-thumb picture small">
        <div class="thumbnail">
          <img src="<mt:var name="thumbnail_url" escape="html">" width="<mt:var name="thumbnail_width" escape="html">" height="<mt:var name="thumbnail_height" escape="html">" />
        </div>
      </div>
      </mt:if>
    </mt:if>
    <div class="asset-metadata">
      <ul class="metadata">
        <li class="metadata-item asset-name"><strong><__trans phrase="File Name">:</strong><mt:var name="file_name" escape="html"></li>
        <li class="metadata-item asset-type"><strong><__trans phrase="Type">:</strong><mt:var name="asset_class_label" escape="html"></li>
        <li class="metadata-item asset-size">
          <strong><__trans phrase="Dimensions">:</strong>
        <mt:if name="class" eq="image">
          <mt:var name="image_width" escape="html"> &times; <mt:var name="image_height" escape="html"><mt:if name="file_size_formatted"> - </mt:if>
        </mt:if>
          <mt:var name="file_size_formatted" escape="html">
        </li>
      </ul>
    </div>
    </div>

    <div class="asset-info">
      <mtapp:setting
         id="label"
         label="<__trans phrase="Label">"
         label_class="top-label"
         help_page="assets"
         help_section="asset_label">
        <input type="text" name="label" id="label" class="text full" value="<mt:var name="label" escape="html">" />
      </mtapp:setting>

      <mtapp:setting
         id="description"
         label="<__trans phrase="Description">"
         label_class="top-label">
        <textarea name="description" id="description" class="text full low"><mt:var name="description" escape="html"></textarea>
      </mtapp:setting>

      <mtapp:setting
         id="tags"
         label_class="text-top"
         label="<__trans phrase="Tags">"
         label_class="top-label">
        <input type="text" name="tags" id="tags" class="text full" value="<$mt:var name="tags" escape="html"$>" />
        <input type="hidden" name="_ignore_tags" id="tags-cache" value="<$mt:var name="tags" escape="html"$>" />
        <div id="tags-suggestion">
          <div id="tags_completion"></div>
        </div>
      </mtapp:setting>

      <mt:unless name="file_is_missing">
        <mtapp:setting
           id="asset-url"
           label_class="top-label"
           label="<__trans phrase="Embed Asset">">
          <input type="text" readonly="readonly" name="asset-url" id="asset-url" class="text full readonly" value="<mt:var name="url" escape="html">" />
        </mtapp:setting>
      </mt:unless>
    </div>

    <mt:setvarblock name="action_buttons">
      <button
         type="submit"
         accesskey="s"
         title="<__trans phrase="Save changes to this asset (s)">"
         class="save action primary button">
        <__trans phrase="Save Changes">
      </button>
    </mt:setvarblock>
    <mt:include name="include/actions_bar.tmpl" bar_position="bottom" hide_pager="1">
  </form>
</div>

<mt:setvarblock name="jq_js_include" append="1">
    jQuery('#edit_asset').validate({
        rules: {
            label: 'required'
        },
        messages: {
            label: '<__trans phrase="You must specify a name for the asset." escape="singlequotes">'
        },
        errorClass: "msg-error",
        errorPlacement: function(error, element) {
            element.parents('div.field').addClass('error-field');
            error.removeAttr('generated').insertAfter(element);
        }
    });
</mt:setvarblock>

<mt:include name="include/footer.tmpl">
