/**
 * Created with JetBrains WebStorm.
 * User: dfwang
 * Date: 14-6-24
 * Time: 下午1:43
 * To change this template use File | Settings | File Templates.
 */
define(function (require, exports) {
    var AppContext = require('../../../share/assert/js/appcontext').AppContext;
    var PagesThumb = function(){

        this.css = {"background-color":"#ffffff",
            "-webkit-box-shadow": "0px 1px 2px #000",
            "border":"1px solid #000",
            "margin":"15px 0 0 10px",
            "width":DEFAULT_STAGE.twidth+2+"px",
            "height":DEFAULT_STAGE.theight+2+"px"
        }
        //已经创建的内容
        this.content = null;
        this.canvas=null;
    }
    PagesThumb.prototype = {
        getContext:function(){
//            return this.canvas[0].getContext('2d');
            return this.content.find('a>img');
        },
        on:function(){
            var _that = this;
            this.content.on('click',function(e){
                if(!Global.CurrentSlide || !Global.CurrentSlide.c) return;
                Global.CurrentSlide.c._canvas.deactivateAll();
                EventBase.fireEvent('ClickThumb',{e:_that,type:'sel'});
            });
            this.content.on('mouseup',function(e){
                Global.CurrentSlide.c._canvas.deactivateAll();
                Global.CurrentSlide.c._canvas.renderAll();
                if (e.which === 3) {
                    if(e.ctrlKey){    //ctrl+右键
                        if(!Global.CurrentSlide || !Global.CurrentSlide.c) return;
                        EventBase.fireEvent('ClickThumb',{e:_that});
                        return;
                    }
                    //右键复制
                    var slideName = this.id.replace("_Thumb","");
                    if(Global.selSlides.length > 1 && Global.selSlides.indexOf(_that) > -1){    //若为多选状态
                        Global.curSelStatus = "slides";
                        $("#rightBtnCopy").hide();
                    }
                    else{
                        EventBase.fireEvent('ClickThumb',{e:_that,type:'sel'});
                        $("#rightBtnCopy").show();
                    }
                    AppContext.rightClicked = {type: "slide", slideName: slideName, obj: {slideName:slideName}};
                    if(AppContext.selectedCopyTarget && Global.curSelStatus === "slides"){
                        $("#rightBtnPaste").show();
                    }else{
                        $("#rightBtnPaste").hide();
                    }
//                    $("#rightBtnCopy").show();
                    $("#rightBtnCut").hide();
                    $("#rightBtnExport").hide();
                    $("#rightBtnDelete").show();
                    $("#contextMenu").css({left: e.pageX, top: e.pageY});
                    $("#contextMenu").show();
                }
            })
        },
        create: function (pageid) {
            var _p = $('<li id="'+pageid+'">'+
                '<span class="order_tip">'+($('#pageArea_list>li').length+1)+'</span>'+
                '<a href="javascript:void(0);" class="page_link">'+
//                    '<canvas width="'+DEFAULT_STAGE.twidth+'" height="'+DEFAULT_STAGE.theight+'" id="'+(pageid+"_stage")+'"></canvas>'+
                      '<img src="" width="'+DEFAULT_STAGE.twidth+'" height="'+DEFAULT_STAGE.theight+'" id="'+(pageid+"_stage")+'">'+
//                    '<img src="editor/assert/images/page_list_img.jpg" alt="01"/>'+
                '</a>'+
            '</li>');
//            var _p = $('<div id="'+pageid+'"><canvas width="'+DEFAULT_STAGE.twidth+'" height="'+DEFAULT_STAGE.theight+'" id="'+(pageid+"_stage")+'"></canvas></div>');
            //_p.css(this.css);
            this.content = _p;
            this.canvas = _p.find('a>img');
        },
        updateSort:function(){
            var _index = '1';
            this.content.find('span').text(_index);
        },
        add:function(_stage,type){
            if(type===1)
            {
                _stage.append(this.content);
            }else
            {
                this.content.insertAfter(_stage);
            }
            if(this.on) this.on();
        }
    }
    exports.PagesThumb = PagesThumb;
})