@model int
@{
    var clientId = "picture" + new Random().Next();
    var pictureService = EngineContext.Current.Resolve<Nop.Services.Media.IPictureService>();
    var picture = pictureService.GetPictureById(Model);
}
<div id="@(clientId + "value")">
    @Html.HiddenFor(x => x)
</div>
<div id="@(clientId + "image")">
    <img src="@(pictureService.GetPictureUrl(Model, 100, true))" />
</div>
@if(picture != null){
    <span id="@(clientId + "remove")" class="t-button">@T("Admin.Picture.RemovePicture")</span>
}
else
{
    <span id="@(clientId + "remove")" class="t-button" style="display:none;">@T("Admin.Picture.RemovePicture")</span>
}
<br />
<input type="file" id="@clientId"/>
<script type="text/javascript">
    $(function () {
        $(function () {

            var authToken = '@(this.Context.Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value)';

            $("#@clientId").uploadify({
                "uploader": "@(Url.Content("~/Content/Flash/uploadify.swf"))",
                "script": "@(Url.Content("~/Admin/Picture/AsyncUpload"))",
                "scriptData": { authToken: authToken },
                "multi": "false",
                "auto": true,
                "buttonText": "Upload",
                "cancelImg": "@Url.Content("~/Administration/Content/images/cancel-uploading.png")",
                "onComplete": function (event, ID, fileObj, response, data) {
                    var json = jQuery.parseJSON(response);
                    $("#@(clientId + "image")").html("<img src='" + json.imageUrl + "'/>");
                    $("#@(clientId + "value") input").val(json.pictureId);
                    $("#@(clientId + "remove")").show();
                }
            });

            $("#@(clientId + "remove")").click(function(e){
                $("#@(clientId + "image")").html("<img src='@pictureService.GetDefaultPictureUrl()'/>");
                $("#@(clientId + "value") input").val(0);
                $(this).hide();
            });

        });
    });
</script>
