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

    self.modify_room_image_ref = null;
    self.filename = "";
    self.initPage = function () {
        this.bindRoomImage();
    }
    /* 绑定用户头像 */
    self.bindRoomImage = function () {
        $(".c-big img:first").attr("src", "file:///" + this.modify_room_image_ref.getimagepath() + "?t=" + Math.random());
        $(".c-middle img:first").attr("src", "file:///" + this.modify_room_image_ref.getimagepath() + "?t=" + Math.random());
        $(".c-small img:first").attr("src", "file:///" + this.modify_room_image_ref.getimagepath() + "?t=" + Math.random());
    }

    self.initEvent = function(){
        var that = this;
        $(document).delegate(".file-btn", "click", function () {
            ResetImgSize();
            that.filename = that.modify_room_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_room_image_ref.btn_ok_click(1, that.filename, x, y, width, height, scale);
        });

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

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

        that.addCall("ResetImgSize", function () {
            var $imageEdit = $("#photoFrame");
            $imageEdit.height(100);
            $imageEdit.width(100);
        })
        that.sup().constructor(curData);
        that.modify_room_image_ref = curData;
        that.initPage();
        that.initEvent();
    });

});
//Audio.ModifyRoomImage = Audio.ModifyRoomImage || {
//    modify_room_image_ref: null,
//    filename: "",
//    initPage: function () {
//        this.bindRoomImage();
//    },/* 绑定用户头像 */
//    bindRoomImage: function () {
//        $(".c-big img:first").attr("src", "file:///" + this.modify_room_image_ref.getimagepath() + "?t=" + Math.random());
//        $(".c-middle img:first").attr("src", "file:///" + this.modify_room_image_ref.getimagepath() + "?t=" + Math.random());
//        $(".c-small img:first").attr("src", "file:///" + this.modify_room_image_ref.getimagepath() + "?t=" + Math.random());
//    }
//};
/* 图片缩放*/
// function AutoResizeImage(maxWidth,maxHeight,objImg){
//     var img = new Image();
//     img.src = objImg.src;
//     var hRatio;
//     var wRatio;
//     var Ratio = 1;
//     var w = img.width;
//     var h = img.height;
//     wRatio = maxWidth / w;
//     hRatio = maxHeight / h;
//     if (maxWidth ==0 && maxHeight==0){
//         Ratio = 1;
//     }else if (maxWidth==0){
//     if (
//         hRatio<1) Ratio = hRatio;
//     }else if (maxHeight==0){
//     if (
//         wRatio<1) Ratio = wRatio;
//     }else if (wRatio<1 || hRatio<1){
//         Ratio = (wRatio<=hRatio?wRatio:hRatio);
//     }
//     if (Ratio<1){
//         w = w * Ratio;
//         h = h * Ratio;
//     }
//     objImg.height = h;
//     objImg.width = w;
// }

///* loading-mask 控制*/
//function on_show_loading(bshow) {
//    if(bshow == true) {
//        $(".loading-mask").show();
//        Audio.ModifyRoomImage.modify_room_image_ref.enable_view = false;
//    } else {
//        $(".loading-mask").hide();
//        Audio.ModifyRoomImage.modify_room_image_ref.enable_view = true;
//    }
//}
//
//function ResetImgSize() {
//    var $imageEdit = $("#photoFrame");
//    $imageEdit.height(100);
//    $imageEdit.width(100);
//}
//(function () {
//    $(document).delegate(".file-btn", "click", function () {
//        ResetImgSize();
//        Audio.ModifyRoomImage.filename = Audio.ModifyRoomImage.modify_room_image_ref.btn_select_file();
//        if (Audio.ModifyRoomImage.filename) {
//            imageEdit.setDataSource(Audio.ModifyRoomImage.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.ModifyRoomImage.modify_room_image_ref.btn_ok_click(1, Audio.ModifyRoomImage.filename, x, y, width, height, scale);
//    });
//
//    $(document).delegate(".btn-box button:eq(1)", "click", function () {
//        Audio.ModifyRoomImage.modify_room_image_ref.btn_cancel_click();
//    });
//})();

//window.onload = function () { Audio.ModifyRoomImage.modify_room_image_ref = changeimage; Audio.ModifyRoomImage.initPage(); }