var flashImageView;

var flash_image_view = function(option, success) {
    flashImageView = new FlashImageView(option);
    flashImageView.createSuccess = success;
    return flashImageView;
}

function FlashImageView(option) {
    this.markControl = option.markControl;
    this.init();
    this.markControl.on('task.get.before', this, function(event, context, eventObject) {
        this.task = undefined;
    });
    this.markControl.on('task.get.success', this, function(event, context, eventObject) {
        this.task = context.task;
        this.imageCount = this.task.pictureUrls.length;
        this.imageServer = context.imageServer;
        //refreshPictureConfig(this.task.pictureConfig, this.task.pictureUrls, this.imageServer);
        getSwfObject('ImageViewer').setJson(this.task.pictureConfig);
    });
}

FlashImageView.prototype.init = function() {
    this.container = getDom(this.container_dom, this.markControl).appendTo(this.markControl.container.center);
    var path = this.markControl.context.staticServer + '/plugin/';
    var container = this.container;
    $.getScript(path + 'swfobject.js', function() {
        $.getScript(path + 'swfplugin.js', function() {
            initImageViewPluginDefault(path, "viewer", container.width(), container.height());
        });
    });
}

function refreshPictureConfig(config, urls, imageServer) {
    if (urls != undefined && urls.length > 0 && config != undefined && config != '') {
        for (var i = 0; i < urls.length; i++) {
            eval('config=config.replace(/\\{' + i + '\\}/, "' + (imageServer + urls[i]) + '")');
        }
        getSwfObject('ImageViewer').setJson(config);
    }
}

function creationComplete() {
    flashImageView.createSuccess();
}

function loadComplete() {}

FlashImageView.prototype.container_dom = '<div id="viewer"></div>';