
var control = {
    iconItem: {
        value: 1,
        next: function(){
            return this.value++;
        }
    },

    contextMenuZIndex: {
        value: 10000,
        next: function(){
            return this.value++;
        }
    },

    softMap: new YMap(),

    addApp: function(app){
        this.softMap.put(app.id, app);
    },

    resetApp: function(iconId, flag){
        var sets = this.softMap.valueSet();
        for(var index in sets){					
            var DIcon = sets[index];
            if(DIcon){
                if(iconId){
                    if(flag){
                        if(iconId === DIcon.id){
                            DIcon.reset();
                            break;
                        }
                    } else if(iconId !== DIcon.id){
                        DIcon.reset();
                    }														
                } else {
                    DIcon.reset();
                }
            }		
        }
    },

    orderApp: function(iconId, flag){
        var sets = this.softMap.valueSet();
        for(var index in sets){					
            var DIcon = sets[index];
            if(DIcon){
                if(iconId){
                    if(flag){
                        if(iconId === DIcon.id){
                            DIcon.excuteOrder();
                            DIcon.reset();
                            break;
                        }
                    } else if(iconId !== DIcon.id){
                        DIcon.excuteOrder();
                        DIcon.reset();
                    }														
                } else {
                    DIcon.excuteOrder();
                    DIcon.reset();
                }
            }		
        }
    }
};

function SoftItem(options){
    this.body = $('<yx id="" class="soft-item"><yx class="body"></yx></yx>');
    // 应用ID
    this.appId = options.id || utils.UUID(20);
    // ID
    this.id = "soft-" + this.appId;
    this.parentId = utils.getOptionValue(options, 'parentId', 'app', 'Number');
    this.body.attr('id', this.id);    
    this.body.data('id', this.appId);
    this.width = 70;
    this.height = 70;
    // app 、url、dir
    this.type = utils.getOptionValue(options, 'type', 'app', 'String');
    this.icon = utils.getOptionValue(options, 'icon', 'icons/app.png', 'String');
    this.title = utils.getOptionValue(options, 'title', '应用程序', 'String');
    this.order = utils.getOptionValue(options, 'order', 0, 'Number');   
    this.setting = utils.getOptionValue(options, 'setting', '', 'String');
    this.desc = utils.getOptionValue(options, 'desc', '', 'String');
    this.init();
}

SoftItem.prototype = {
    init: function(){
        var self = this;
        self.excuteOrder();

        self.body.css({
            "width": self.width,
            "min-height": self.minHeight || self.height,
            "left": self.X,
            "top": self.Y,
            "z-index": self.index || 0
        });

        if(self.type != "app" && self.desc){
            self.body.attr("title", self.desc);
        }

        var $body = self.body.find('.body');
        
        var iconHtml = '<img src="{0}" onerror="this.src=\'icons/app.png\'"/>',
            titleHtml = '<yx class="title blur">{0}</yx>';
        
        $body.append(utils.format(iconHtml, self.icon));
        $body.append(utils.format(titleHtml, self.title));
        
        self.bindEvent();
    },

    bindEvent: function(){
        var self = this,
            self_title = self.body.find('.title');
        self.body.on('mousedown', function(e){
            self.body.addClass('press');
            
            self.index = control.iconItem.next();
            self.body.css({
                "z-index": self.index
            });
            
            if(e.button == 0){
                window.selected = self; 
            }            

            e.stopPropagation();
            e.preventDefault();
        });

        self.body.on('mouseup', function(e){
            self.body.removeClass('press');            
            control.resetApp(self.id, false);
            
            if(window.selected && window.selected.id != self.id){
                if(self.setting == "sys" || window.selected.setting == "sys"){
                    if(self.parentId != window.selected.parentId){
                        self.excuteOrder();
                        self.reset();
                        window.selected.excuteOrder();
                        window.selected.reset();
                        return;
                    }
                }
                var order = window.selected.order;
                    window.selected.order = self.order;
                    self.order = order;
                    self.excuteOrder();
                    self.reset();
                    window.selected.excuteOrder();
                    window.selected.reset();                    
                    SendSoftMessage("softOrder", JSON.stringify({
                        "pid": self.appId,
                        "fid": window.selected.appId,
                        "ppid": self.parentId,
                        "pfid": window.selected.parentId
                    }));
                    if(self.parentId != window.selected.parentId){
                        desktop.remove(self.appId);
                        desktop.addApp(window.selected);
                    }
            }

            window.selected = null;
            if(window.selectSoft){
                window.selectSoft.remove();
                window.selectSoft = null;
            }
            
            utils.stopEvent(e);
        });        
        
        // 单击
        self.body.on('click', function(e){
            self.body.addClass('active');
            self_title.removeClass('blur');
            if(!!OwlConfig.clickrun){
                SendSoftMessage("runApp", self.appId);
            }  
            utils.stopEvent(e);
        });
        
        // 双击打开软件
        self.body.on('dblclick', function(e){
            // 打开软件
            if(!OwlConfig.clickrun){
                SendSoftMessage("runApp", self.appId);
            }            
            
            utils.stopEvent(e);
        }).on('mouseup', function(e){
            if(e.button == 2){ // 右键点击
                self.body.addClass('active');
                self_title.removeClass('blur');
                self.showContextMenu(e.clientX, e.clientY);
            }
            
            window.selected = null;
            if(window.selectSoft){
                window.selectSoft.remove();
                window.selectSoft = null;
            }

            utils.stopEvent(e);
        });
    },

    copy: function(x, y){
        var h = this.body.html();
        var cx = $('<yx id="copy" class="soft-item">'+h+'</yx>');
        $("body").append(cx);
        cx.hide();
        return cx;
    },

    excuteOrder: function(){
        var self = this;
        var sw = utils.screenWidth();
        var i = self.order + 1;
        var num =  Math.floor(sw/(self.width + 7));
        var orderX = self.order % num;
        var orderY = Math.floor(self.order/num);
        self.X = orderX * self.width + (orderX + 1) * 5;		
        self.Y = orderY * self.height + (orderY + 1) * 5;
    },

    reset: function(){
        var self = this,
            self_title = self.body.find('.title');;
        self.body.removeClass('active');
        self_title.addClass('blur');
        self.body.css({
            "left": self.X,
            "top": self.Y
        });
    },

    initContextMenu: function(x, y){
        var self = this;
        self.contextMenu = new YXContextMenu({
            cssClass: 'window-context-menu',
            container: window.desktop
        });
        var menus = [];
        if(self.type == 'app'){
            menus.push({
                icon: 'icon-play',
                cssClass: 'run',
                title: '运行',
                click: function(){
                    SendSoftMessage("runApp", self.appId);
                }
            });
            /*menus.push({
                icon: 'icon-ok',
                cssClass: 'admin',
                title: '管理员权限运行',
                click: function(){
                    SendSoftMessage("adminRun", self.appId);
                }
            });*/
            menus.push({
                icon: 'icon-folder-open',
                cssClass: 'dir',
                title: '打开软件目录',
                click: function(){
                    SendSoftMessage("openDir", self.appId);
                }
            });
            menus.push({
                icon: 'icon-copy',
                cssClass: 'copy',
                title: '复制程序完整路径',
                click: function(){
                    SendSoftMessage("copyPath", self.appId);
                }
            });
            /*menus.push({
                icon: 'icon-window',
                cssClass: 'menu',
                title: '资源管理器菜单',
                click: function(){
                    SendSoftMessage("showExplorerMenu", self.appId);
                }
            });*/
        } else if(self.type == 'dir'){
            menus.push({
                icon: 'icon-folder-close-alt',
                cssClass: 'open',
                title: '打开',
                click: function(){
                    SendSoftMessage("runApp", self.appId);
                }
            });
            menus.push({
                icon: 'icon-copy',
                cssClass: 'copy',
                title: '复制完整路径',
                click: function(){
                    SendSoftMessage("copyPath", self.appId);
                }
            });
        } else if(self.type == 'url'){
            menus.push({
                icon: 'icon-chrome',
                cssClass: 'visit',
                title: '访问',
                click: function(){
                    SendSoftMessage("runApp", self.appId);
                }
            });
            menus.push({
                icon: 'icon-copy',
                cssClass: 'copy',
                title: '复制URL',
                click: function(){
                    SendSoftMessage("copyUrl", self.appId);
                }
            });
        };
        if(self.setting != "sys"){
            menus.push({
                icon: 'icon-file-o',
                cssClass: 'split',
                title: '--'
            });
            menus.push({
                icon: 'icon-edit',
                cssClass: 'edit',
                title: '编辑',
                click: function(){
                    SendSoftMessage("editSoft", self.appId);
                }
            });
            menus.push({
                icon: 'icon-trash',
                cssClass: 'delete',
                title: '删除',
                click: function(){
                    SendSoftMessage("delSoft", self.appId);
                }
            });
        }
        self.contextMenu.addItem(menus);
        self.contextMenu.disableItem('split', true);
        self.contextMenu.show(x, y);
    },
    
    showContextMenu: function(x, y){
        var self = this;
        
        if(self.contextMenu == null){
            self.initContextMenu(x, y);
        } else {
            self.contextMenu.show(x, y);
        }
    },
    
    hideContextMenu: function(){
        var self = this;
        if(self.contextMenu){
            self.contextMenu.hide();
        }
    }

};

+ function($, win){
    win.YXDesktop = function($body){
        this.body = $body;
		this.loading = $('<div id="soft-desktop-loading" class="soft-desktop-loading"><div class="spinner"></div></div>');
		
		this.wallpaperStore = [
			"back1.jpg",
		];
		
		this.contextMenu = null;
		
        this.contextMenuStore = {};
        
        this.bindEvent();
    };

    win.YXDesktop.prototype = {

        bindEvent: function(){
			var self = this;
			self.body.on('mouseup', function(e){
				var buttons = e.button;
				if(buttons == 2){ // 右键菜单
					if(self.contextMenu == null){
						self.initContextMenu(e.clientX, e.clientY);
					} else {
						self.showContextMenu(e.clientX, e.clientY);
					}					
                }

                if(window.selected && window.selected.parentId != currSecondId){
                    if(window.selected.setting != "sys"){
                        window.selected.excuteOrder();
                        window.selected.reset();
                        SendSoftMessage("softMove", JSON.stringify({
                            "id": window.selected.appId,
                            "pid": currSecondId
                        }));
                    }
                }

                window.selected = null;
                if(window.selectSoft){
                    window.selectSoft.remove();
                    window.selectSoft = null;
                }      
                
                SysBox.hideOtherContextMenu();
                topBox.hideOtherContextMenu();
                leftBox.hideOtherContextMenu();
            });            
            
			// 桌面被左键点击时
			self.body.on('click', function(e){
				control.resetApp(); // 重置桌面图标
				self.hideOtherContextMenu(); // 隐藏桌面菜单
				topBox.hideOtherContextMenu();
                leftBox.hideOtherContextMenu();
                SysBox.hideOtherContextMenu();
				utils.stopEvent(e);
			});
			
			self.body.on('blur', function(e){
				
			});
			
			return self;
        },

        addApp: function(yxDIcon){
			control.addApp(yxDIcon);
			this.body.append(yxDIcon.body);
		},
		
		initContextMenu: function(x, y){
			var self = this;
			self.contextMenu = new YXContextMenu({
                cssClass: 'desktop-context-menu',
                container: self
			});
			
			self.contextMenu.addItem([
				{
					icon: 'icon-plus',
					title: '新建项目',
					click: function(){
						SendSoftMessage("newItem", "");
					}
				},
				{
					icon: 'icon-reply',
					title: '从桌面快捷方式导入',
					click: function(){
                        SendSoftMessage("import", "desktop-lnk");
                        showImportWait(true);
					}
				},
				{
					icon: 'icon-list-ol',
					title: '按使用频率排序',
					click: function(){
						SendSoftMessage("sortUse", "");
					}
                },
                {
                    icon: 'icon-refresh',
                    cssClass: "reload",
					title: '重新载入',
					click: function(){
						SendSoftMessage("reload", "");
					}
				}
			]);
			
			self.contextMenu.show(x, y);
		},

        addContextMenu: function(cmenu){
			var self = this;
			if(!cmenu.parent){
				self.contextMenuStore[cmenu.id] = cmenu;
				self.body.append(cmenu.body);
			}
		},
		
		showContextMenu: function(x, y){
			var self = this;
			if(self.contextMenu){
				self.contextMenu.show(x, y);
			} else {
				self.initContextMenu(x, y);
			}
		},
		
		hideContextMenu: function(){
			var self = this;
			if(self.contextMenu){
				self.contextMenu.hide();
			}
		},
		
		hideOtherContextMenu: function(cid){
			var self = this;
			for(var id in self.contextMenuStore){
				if(id != cid){
					self.contextMenuStore[id].hide();
				}
			}
		},

        width: function(){
            return this.body.width();
        },

        height: function(){
            return this.body.height();
        },

        clear: function(){
            control.softMap.removeAll();
			this.body.find(".soft-item").remove();
        },

        remove: function(id){
            if(id){
                control.softMap.remove(id);
                $("#soft-" + id).remove();
            }            
        }
    };

}(jQuery, window);

/** */
+ function($, win){
    win.PanelMenu = function(ops){
        this.body = ops.body;
        this.type = ops.type;
		this.contextMenu = null;		
        this.contextMenuStore = {};
        this.groupId = 0;
        this.setting = "";
        this.bindEvent();
    };

    win.PanelMenu.prototype = {

        bindEvent: function(){
			var self = this;
			self.body.on('mouseup', function(e){
				var buttons = e.button;
                if(buttons == 2){ // 右键菜单
                    self.groupId = $(e.target).data("id");
                    self.setting = $(e.target).data("set");
					if(self.contextMenu == null){
						self.initContextMenu(e.clientX + 90, e.clientY + 30);
					} else {
						self.showContextMenu(e.clientX + 90, e.clientY + 30);
					}					
                }
                if(self.type == "f"){
                    topBox.hideOtherContextMenu();
                } else {
                    leftBox.hideOtherContextMenu();
                }
                SysBox.hideOtherContextMenu();
                desktop.hideOtherContextMenu();
            });
            
			// 桌面被左键点击时
			self.body.on('click', function(e){
				topBox.hideOtherContextMenu();
                leftBox.hideOtherContextMenu();
                desktop.hideOtherContextMenu();
                SysBox.hideOtherContextMenu();
				utils.stopEvent(e);
			});
			
			return self;
        },
		
		initContextMenu: function(x, y, id){
			var self = this;
			self.contextMenu = new YXContextMenu({
                cssClass: 'panel-context-menu',
                container: self
			});
			
			self.contextMenu.addItem([
				{
                    icon: 'icon-plus',
                    cssClass: "newGroup",
					title: '创建分组',
					click: function(){
						SendSoftMessage("newGroup", JSON.stringify({
                            "id": self.groupId,
                            "type": self.type
                        }));
					}
				},
				{
                    icon: 'icon-edit',
                    cssClass: "edit",
					title: '编辑',
					click: function(){
						SendSoftMessage("editGroup", JSON.stringify({
                            "id": self.groupId,
                            "type": self.type
                        }));
					}
				},
				{
                    icon: 'icon-trash',
                    cssClass: "del",
					title: '删除',
					click: function(){
						SendSoftMessage("delGroup", JSON.stringify({
                            "id": self.groupId,
                            "type": self.type
                        }));
					}
				}
			]);
            
            if(self.setting == "sys" || self.groupId < 50){
                self.contextMenu.disableItem("edit", true);
                self.contextMenu.disableItem("del", true);
            } else {
                self.contextMenu.disableItem("edit", !self.groupId);
                self.contextMenu.disableItem("del", !self.groupId);
            }            
			self.contextMenu.show(x, y);
		},

        addContextMenu: function(cmenu){
			var self = this;
			if(!cmenu.parent){
				self.contextMenuStore[cmenu.id] = cmenu;
				$("body").append(cmenu.body);
			}
		},
		
		showContextMenu: function(x, y){
			var self = this;
			if(self.contextMenu){
                if(self.setting == "sys" || self.groupId < 50){
                    self.contextMenu.disableItem("edit", true);
                    self.contextMenu.disableItem("del", true);
                } else {
                    self.contextMenu.disableItem("edit", !self.groupId);
                    self.contextMenu.disableItem("del", !self.groupId);
                }
				self.contextMenu.show(x, y);
			} else {
				self.initContextMenu(x, y);
			}
		},
		
		hideContextMenu: function(){
			var self = this;
			if(self.contextMenu){
				self.contextMenu.hide();
			}
		},
		
		hideOtherContextMenu: function(cid){
			var self = this;
			for(var id in self.contextMenuStore){
				if(id != cid){
					self.contextMenuStore[id].hide();
				}
			}
		},

        width: function(){
            return $(window).width();
        },

        height: function(){
            return $(window).height();
        }
    };

}(jQuery, window);

/** */
+ function($, win){
    win.SysMenu = function(ops){
        this.body = ops.body;
        this.contextMenu = null;		
        this.contextMenuStore = {};
        this.bindEvent();
    };

    win.SysMenu.prototype = {

        bindEvent: function(){
			var self = this;
			// 桌面被左键点击时
			self.body.on('click', function(e){
                var r = this.getBoundingClientRect();
                if(self.contextMenu == null){
                    self.initContextMenu(r.left - 50, r.top + 60);
                } else {
                    self.showContextMenu(r.left - 50, r.top + 60);
                }

				topBox.hideOtherContextMenu();
                leftBox.hideOtherContextMenu();
                desktop.hideOtherContextMenu();
				utils.stopEvent(e);
			});
			
			return self;
        },
		
		initContextMenu: function(x, y, id){
			var self = this;
			self.contextMenu = new YXContextMenu({
                cssClass: 'sys-context-menu',
                container: self
            });

            if(window['user']){
                self.contextMenu.addItem([{
                    icon: 'icon-user',
                    cssClass: "login",
                    title: user.account,
                    click: function(){},
                    subItem: [{
                        icon: 'icon-diamond',
                        cssClass: "vip",
                        title: 'VIP服务',
                        click: function(){
                            SendSoftMessage("vip", "");
                        }
                    },{
                        icon: 'icon-edit',
                        cssClass: "edit",
                        title: '修改密码',
                        click: function(){
                            SendSoftMessage("changePwd", "");
                        }
                    }
                    ,{
                        icon: 'icon-signout',
                        cssClass: "exit",
                        title: '退出登录',
                        click: function(){
                            SendSoftMessage("exit", "");
                        }
                    }
                    ]
                }]);
            } else {
                self.contextMenu.addItem([{
                    icon: 'icon-user',
                    cssClass: "login",
                    title: '登录',
                    click: function(){
                        SendSoftMessage("login", "");
                    }
                }]);
            }
            
			
			self.contextMenu.addItem([
                {
                    icon: '',
                    cssClass: "",
					title: '--',
					click: function(){}
				},
				{
                    icon: 'icon-cog',
                    cssClass: "setting",
					title: '设置',
					click: function(){
						SendSoftMessage("setting", "");
					}
                },
                {
                    icon: 'icon-phone',
                    cssClass: "feedback",
					title: '问题反馈',
					click: function(){
						SendSoftMessage("feedback", "");
					}
				},
				{
                    icon: 'icon-question-sign',
                    cssClass: "help",
					title: '帮助说明',
					click: function(){},
                    subItem: [{
                        icon: 'icon-chrome',
                        cssClass: "visitwww",
                        title: '官网',
                        click: function(){
                            SendSoftMessage("visitwww", "");
                        }
                    },{
                        icon: 'icon-refresh',
                        cssClass: "update",
                        title: '检测更新',
                        click: function(){
                            SendSoftMessage("update", "");
                        }
                    },{
                        icon: 'icon-info',
                        cssClass: "about",
                        title: '关于',
                        click: function(){
                            SendSoftMessage("about", "");
                        }
                    }]
                },
                {
                    icon: '',
                    cssClass: "",
					title: '--',
					click: function(){}
				},
				{
                    icon: 'icon-refresh',
                    cssClass: "reload",
					title: '重新载入',
					click: function(){
						SendSoftMessage("reload", "");
					}
				},
				{
                    icon: 'icon-off',
                    cssClass: "over",
					title: '退出程序',
					click: function(){
						SendSoftMessage("over", "");
					}
				}
			]);
        
			self.contextMenu.show(x, y);
		},

        addContextMenu: function(cmenu){
			var self = this;
			if(!cmenu.parent){
                self.contextMenuStore[cmenu.id] = cmenu;
				$("body").append(cmenu.body);
			}
		},
		
		showContextMenu: function(x, y){
			var self = this;
			if(self.contextMenu){
				self.contextMenu.show(x, y);
			} else {
				self.initContextMenu(x, y);
			}
		},
		
		hideContextMenu: function(){
			var self = this;
			if(self.contextMenu){
				self.contextMenu.hide();
			}
		},
		
		hideOtherContextMenu: function(cid){
			var self = this;
			for(var id in self.contextMenuStore){
				if(id != cid){
					self.contextMenuStore[id].hide();
				}
			}
		},

        width: function(){
            return $(window).width();
        },

        height: function(){
            return $(window).height();
        }
    };

}(jQuery, window);

/**
 * ==============================================
 * ContextMenu.js
 * ==============================================
 */
+ function($, win){
	var ul_html = '<ul class="soft-context-menu {cssClass}" id="{id}"></ul>',
		li_html = '<li class="soft-context-menu-item {cssClass}"><i class="icon {icon}"></i> {title}</li>',
		li_line = '<li class="soft-context-menu-line {cssClass}"><hr/></li>';
	
    win.YXContextMenu = function(ops){
		ops = $.extend({
			cssClass: '',
			id: "cmenu-" + utils.UUID(20)
		}, ops);
		this.id = ops.id;
        this.parent = ops.parent;
        this.container = ops.container;
		this.body = $(utils.formatByJson(ul_html, ops));
		this.cssClass = ops.cssClass;
		this.init();
	};
	
	win.YXContextMenu.prototype = {
		
		init: function(){
			var self = this;
			self.body.css({
				"z-index": control.contextMenuZIndex.next()
            });
			self.container.addContextMenu(self);
		},
		
		addItem: function(){
			var items = arg = arguments[0];
			var self = this;
			if(Object.prototype.toString.call(arg) === "[object Object]"){
				items = [arg];
			}
			var createItem = function(menu, item){
				var $li, subMenu, it;
                if(item.subItem && item.subItem.length){ // 有子集
                    if(item.title == "--"){
                        $li = $(utils.formatByJson(li_line, item));
                    } else {
                        $li = $(utils.formatByJson(li_html, item));
                    }					
					$li.addClass('soft-has-submenu');
					subMenu = new YXContextMenu({
                        cssClass: 'soft-context-submenu',
                        container: self.container,
						parent: menu
					});
					$li.append(subMenu.body);
					$li.on('click', function(e){
						if(!$li.hasClass('disabled')){
							item.click && item.click.call(self, e);
							self.hide();
						}
						utils.stopEvent(e);
					}).on('mousedown', function(e){
						if(!$li.hasClass('disabled')){
							item.mousedown && item.mousedown.call(self, e);
						}
						utils.stopEvent(e);
					}).on('mouseup', function(e){
						if(!$li.hasClass('disabled')){
							item.mouseup && item.mouseup.call(self, e);
							self.hide();
						}
						utils.stopEvent(e);
					});
					menu.body.append($li);
					
					subMenu.addItem(item.subItem);
				} else {
                    if(item.title == "--"){
                        $li = $(utils.formatByJson(li_line, item));
                    } else {
                        $li = $(utils.formatByJson(li_html, item));
                    }
					$li.on('click', function(e){
						if(!$li.hasClass('disabled')){
							item.click && item.click.call(self, e);
							self.hide();
						}
						utils.stopEvent(e);
					}).on('mousedown', function(e){
						if(!$li.hasClass('disabled')){
							item.mousedown && item.mousedown.call(self, e);
						}
						utils.stopEvent(e);
					}).on('mouseup', function(e){
						if(!$li.hasClass('disabled')){
							item.mouseup && item.mouseup.call(self, e);
							self.hide();
						}
						utils.stopEvent(e);
					});
					menu.body.append($li);
				}
			};
			if(items){
				var item = null;
				for(var i = 0; i < items.length; i++){
					item = new YXContextMenu.ContextMenuItem(items[i]);
					createItem(self, item);
				}
			}
		},
		
		height: function(){
			var self = this;
			return self.body.height();
		},
		
		width: function(){
			var self = this;
			return self.body.width();
		},
		
		show: function(x, y){
			var self = this,
				screenWidth = self.container.width(),
				screenHeight = self.container.height(),
				height = self.height() + 15,
                width = self.width();
            x = x - 90;
            y = y - 30;
			if(x + width >= screenWidth){
				x = x - width;
			};
			if(y + height >= screenHeight){
				y = y - height;
			};
			self.body.css({
				left: x,
				top: y,
				display: 'inline-block'
			});
	
			self.container.hideOtherContextMenu(self.id);
		},
		
		hide: function(){
			var self = this;
			if(self.parent){
				self.parent.hide();
			} else {
				self.body.css({
					display: 'none'
				});
			}			
		},
		
		disableItem: function(css, is){
			var self = this,
				$item = self.body.find('.soft-context-menu-item.' + css);
			if($item.length){
				$item.attr('disabled', is === true);
				if(is === true){
					$item.addClass('disabled');
				} else {
					$item.removeClass('disabled');
				}
			}
		},
		
		showItem: function(css, is){
			var self = this,
				$item = self.body.find('.soft-context-menu-item.' + css);
			if($item.length){
				if(is === true){
					$item.show();
				} else {
					$item.hide();
				}
			}
		}
		
	};
	
	win.YXContextMenu.ContextMenuItem = function(ops){
		this.icon = utils.getOptionValue(ops, 'icon', 'icon-angle-right', 'String');
		this.title = utils.getOptionValue(ops, 'title', '', 'String');
		this.cssClass = utils.getOptionValue(ops, 'cssClass', '', 'String');
		this.click = utils.getOptionValue(ops, 'click', $.noop, 'Function');
		this.mousedown = utils.getOptionValue(ops, 'mousedown', $.noop, 'Function');
		this.mouseup = utils.getOptionValue(ops, 'mouseup', $.noop, 'Function');
		this.subItem = utils.getOptionValue(ops, 'subItem', [], 'Array');
        this.parent = null;
        return this;
	};
	
	
}(jQuery, window);