<mt:include name="dialog/header.tmpl">
<mt:setvarblock name="insert_script" id="insert_script">
window.parent.app.insertHTML( '<mt:var name="upload_html" escape="js">', '<mt:var name="edit_field" escape="js">' );
</mt:setvarblock>
<script type="text/javascript">
/* <![CDATA[ */

// do the following first... asset manager stuff is ONLY for edit entry
<mt:if name="upload_html">
    <mt:var name="insert_script">
</mt:if>

// remove the no assets text if it's there
var Node = window.parent.document.getElementById("empty-asset-list");
if (Node) {
    Node.parentNode.removeChild(Node);
} 

// make sure asset list is present in an entry edit page
var AssetList = window.parent.document.getElementById("asset-list");

if (AssetList) {
    // make sure the asset isn't there already and that we're in the edit entry page
    var Asset = window.parent.document.getElementById("list-asset-<mt:AssetID>");

    if (Asset) {
        // do nothing
    }
    else {
        // add the asset's id to the include_asset_ids hidden input
        var asset_ids = window.parent.document.getElementById("include_asset_ids").value;
        if ( asset_ids.length > 0 ) {
            asset_ids += ',';
        }
        window.parent.document.getElementById("include_asset_ids").value = asset_ids + "<mt:AssetID>";

        // create the link to the asset page with asset name as label
        var myAssetLink = window.document.createElement('a');
        myAssetLink.setAttribute('href', '<mt:CGIPath><mt:AdminScript>?__mode=view&_type=asset&blog_id=<mt:var name="blog_id">&id=<mt:AssetID>');
        myAssetLink.setAttribute('class', 'asset-title');
        myAssetLink.appendChild(document.createTextNode('<mt:AssetFileName encode_js="1">'));

        // create the remove link for this asset
        var myRemoveLink = window.document.createElement('a');
        myRemoveLink.setAttribute('href', 'javascript:removeAssetFromList(<mt:AssetID>)');
        myRemoveLink.setAttribute('class', 'remove-asset');

        // create the asset list item
        var myElement = window.document.createElement('li');
        myElement.setAttribute('id', 'list-asset-<mt:AssetID>');
        myElement.setAttribute('class', 'asset-type-<mt:AssetProperty property="class"$>');
        <mt:If tag="AssetType" eq="image">
            myElement.setAttribute('onmouseover', 'show(\'list-image-<mt:AssetID>\', window.parent.document)');
            myElement.setAttribute('onmouseout','hide(\'list-image-<mt:AssetID>\', window.parent.document)');
        </mt:If>
        myElement.appendChild(myAssetLink);
        myElement.appendChild(myRemoveLink);

        // I HATE IE!
        if (document.attachEvent) {
            var oldLis = window.parent.document.getElementById("asset-list").innerHTML;
            var newLi  = '<li id="list-asset-<mt:AssetID>" onmouseover="show(\'list-image-<mt:AssetID>\', window.parent.document)" onmouseout="hide(\'list-image-<mt:AssetID>\', window.parent.document)">' + myElement.innerHTML + '</li>';
            window.parent.document.getElementById("asset-list").innerHTML = oldLis + newLi;
        } 
        else {
            window.parent.document.getElementById("asset-list").appendChild(myElement);
        }

        // create the image thumbnail if it exists
        <mt:If tag="AssetType" eq="image">
            var myImageElement = window.document.createElement('img');
            myImageElement.setAttribute('id', 'list-image-<mt:AssetID>');
            myImageElement.setAttribute('src', '<mt:AssetThumbnailURL width="100" encode_js="1">');
            myImageElement.setAttribute('class', 'list-image hidden');
            myElement.appendChild(myImageElement);
        </mt:If>
    }
}
<mt:unless name="extension_message">
    parent.jQuery.fn.mtDialog.close();
</mt:unless>
/* ]]> */
</script>

<mt:if name="extension_message">
    <mtapp:statusmsg
        id="extension-changed"
        class="success">
        <mt:var name="extension_message">
    </mtapp:statusmsg>

    <div class="actions-bar-inner pkg actions">
        <form action="" method="get" onsubmit="return false">
            <button
                type="submit"
                accesskey="x"
                class="cancel mt-close-dialog"
                title="<__trans phrase="Close (x)">"
                ><__trans phrase="Close"></button>
        </form>
    </div>
</mt:if>

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