Class(function(using, extend, self){
    extend("pages/page");
    using("lib/jquery.min.js");
    using("plugin/imageCut")

    self.modify_user_image_ref = null;
    self.filename = "";

    self.initPage = function () {
        this.bindUserImage();
    }
    // 绑定用户头像
    self.bindUserImage = function () {
        var my_local_info = this.modify_user_image_ref.get_img_type();
        if(my_local_info == 1) {
            $(".photo-Frame img:first").attr("src", "static/images/hall/circle-head-man.png");
        } else {
            $(".photo-Frame img:first").attr("src", "static/images/hall/circle-head.png");
        }
        $(".thumb-area img:first").attr("src", "file:///" + this.modify_user_image_ref.getimagepath() + "?t=" + Math.random());
    }

    self.initEvent = function(){
        var that = this;
        $(document).delegate(".file-btn", "click", function () {
            that.filename = that.modify_user_image_ref.btn_select_file();
            if (that.filename) {
                imageEdit.setDataSource(that.filename);
            }
        });

        $(document).delegate(".btn-box button:eq(0)", "click", function () {
            var x = imageEdit.getFramePosition().x;
            var y = imageEdit.getFramePosition().y;
            var width = imageEdit.getFrameSize().width;
            var height = imageEdit.getFrameSize().height;
            var scale = imageEdit.scale();
            if(width == 0 || height == 0) {
                alert("截图区域不为0");
                return;
            }
            that.modify_user_image_ref.btn_ok_click(1, that.filename, x, y, width, height, scale);
        });

        $(document).delegate(".btn-box button:eq(1)", "click", function () {
            that.modify_user_image_ref.btn_cancel_click();
        });
    }

    self.func(function(curData){
        var that = this;
        that.modify_user_image_ref = curData;
        that.sup().constructor(curData);
        /* 加载发生错误添加默认头像 */
        that.addCall("add_default_img", function() {
            var my_local_info = that.modify_user_image_ref.get_img_type();
            if(my_local_info == 1) {
                $(".thumb-area img:first").attr({ src: "static/images/hall/pic.png"});
            }
            else {
                $(".thumb-area img:first").attr({ src: "static/images/hall/female.png"});
            }
        });

        /* loading-mask 控制*/
        that.addCall("on_show_loading", function(bshow) {
            if(bshow == true) {
                $(".loading-mask").show();
                that.modify_user_image_ref.enable_view = false;
            } else {
                $(".loading-mask").hide();
                that.modify_user_image_ref.enable_view = true;
            }
        });

        that.initPage();
        that.initEvent();


    })
});

//Audio.ModifyUserImage = Audio.ModifyUserImage || {
//    modify_user_image_ref: null,
//    filename: "",
//    initPage: function () {
//        this.bindUserImage();
//    },/* 绑定用户头像 */
//    bindUserImage: function () {
//        var my_local_info = Audio.ModifyUserImage.modify_user_image_ref.get_img_type();
//        if(my_local_info == 1) {
//            $(".photo-Frame img:first").attr("src", "images/hall/circle-head-man.png");
//        } else {
//            $(".photo-Frame img:first").attr("src", "images/hall/circle-head.png");
//        }
//        $(".thumb-area img:first").attr("src", "file:///" + this.modify_user_image_ref.getimagepath() + "?t=" + Math.random());
//    }
//};
//
///* 加载发生错误添加默认头像 */
//function  add_default_img() {
//    var my_local_info = Audio.ModifyUserImage.modify_user_image_ref.get_img_type();
//    if(my_local_info == 1) {
//        $(".thumb-area img:first").attr({ src: "images/hall/pic.png"});
//    }
//    else {
//        $(".thumb-area img:first").attr({ src: "images/hall/female.png"});
//    }
//}
//
///* loading-mask 控制*/
//function on_show_loading(bshow) {
//    if(bshow == true) {
//        $(".loading-mask").show();
//        Audio.ModifyUserImage.modify_user_image_ref.enable_view = false;
//    } else {
//        $(".loading-mask").hide();
//        Audio.ModifyUserImage.modify_user_image_ref.enable_view = true;
//    }
//}

//(function () {
//    $(document).delegate(".file-btn", "click", function () {
//        Audio.ModifyUserImage.filename = Audio.ModifyUserImage.modify_user_image_ref.btn_select_file();
//        if (Audio.ModifyUserImage.filename) {
//            imageEdit.setDataSource(Audio.ModifyUserImage.filename);
//        }
//    });
//
//    $(document).delegate(".btn-box button:eq(0)", "click", function () {
//        var x = imageEdit.getFramePosition().x;
//        var y = imageEdit.getFramePosition().y;
//        var width = imageEdit.getFrameSize().width;
//        var height = imageEdit.getFrameSize().height;
//        var scale = imageEdit.scale();
//        if(width == 0 || height == 0) {
//            alert("截图区域不为0");
//            return;
//        }
//        Audio.ModifyUserImage.modify_user_image_ref.btn_ok_click(1, Audio.ModifyUserImage.filename, x, y, width, height, scale);
//    });
//
//    $(document).delegate(".btn-box button:eq(1)", "click", function () {
//        Audio.ModifyUserImage.modify_user_image_ref.btn_cancel_click();
//    });
//})();
//
//window.onload = function () { Audio.ModifyUserImage.modify_user_image_ref = changeimage; Audio.ModifyUserImage.initPage(); }