/*
#define BFCCFG_VERSION			 _T("\"cfg_version\":")
#define BFCCFG_SHOWBAR			 _T("\"cfg_showbar\":")
#define BFCCFG_AUTORUN			 _T("\"cfg_autorun\":")
#define BFCCFG_ISSHOWXAPP		 _T("\"cfg_isshowxapp\":")
#define BFCCFG_MINITOTRAY		 _T("\"cfg_minitotray\":")
#define BFCCFG_CACHEDIR			 _T("\"cfg_cachedir\":")
#define BFCCFG_DISKLEFTSIEZE	 _T("\"cfg_diskleftsize\":")
#define BFCCFG_RUNAFTERDOWN		 _T("\"cfg_runafterdown\":")
#define BFCCFG_ISBOSSKEY		 _T("\"cfg_isbosskey\":")
#define BFCCFG_BOSSKEYVALUE		 _T("\"cfg_bosskeyvalue\":")
#define BFCCFG_DWBOSSKEYVALUE		 _T("\"cfg_dwbosskeyvalue\":")*/
if(!Array.prototype.indexOf){
    Array.prototype.indexOf = function(val){
        var value = this;
        for(var i =0; i < value.length; i++){
            if(value[i] == val) return i;
        }
        return -1;
    };
}
function proxy(func, context) {
    var len = arguments.length;
    var arg = arguments;

    return function () {
        arguments[0]['element'] = this;
        arguments[0]['args'] = [];
        for (var i = 2; i < len; i++) {
            arguments[0]['args'].push(arg[i]);
        }
        if (typeof(context) == 'undefined') {
            context = this;
        }
        func.apply(context, arguments);
    }
}
function keyDown(){
	//屏蔽shift、ctrl、atl+其它按键；以及单独非shift、ctrl、atl按键
	if ((event.keyCode != 16 && event.keyCode != 17 && event.keyCode != 18)
	     || (!event.shiftKey && !event.ctrlKey && !event.altKey && event.keyCode != 0))
	{
  	event.keyCode = 0; 
  	event.cancelBubble = true; 
		return false; 
	}	
}
//更新设置窗口配置
function updateConfigData()
{
	option.init_config();
	option._menu._render_currnt_index();
}

//选择当前菜单项
function selectMenuItem(i)
{
	option._menu.select(i);
}

//客户端调用判断是否处于快捷键设置的焦点（已废弃）
var globalisHotkeyFocus = false;
function isHotkeyFocus(val){
	return globalisHotkeyFocus;
}

$.fn.check = function (checked) {
    if (checked === 2) {
        this.attr('disabled', 'disabled');
    } else {
        this.attr('checked', checked);
    }
    return this;
}

var option = {
    _twOption: function (id, isWrite, int1, str1, str2) {
        try {
            id = id | 0;
            g_lValue = int1 | 0 || 0, g_bstrValue1 = str1 + '' || '', g_bstrValue2 = str2 + '' || '';
            return DoOption(id, isWrite);
            // else return g_lValue || g_bstrValue1 || g_bstrValue2;
        } catch (e) {
            return false;
        }
    },
    init: function () {
        document.onkeydown = keyDown;
        option._menu = new option.menu();
        for (var i = 0; i < option.config.length; i++) {
            var cfg = option.config[i];
            option._menu.add_item(cfg['title'], cfg['items']);
        }
		
				this.init_config();
        this.init_page(); // 初始化页面
    },
    hash: {
        'hight=homepage': [0, 1],
        'hight=searchengine': [0, 3]
    },
    init_page: function () {
        var page = [null, null];
		//alert("var page = [null, null]");
        for (var pattern in this.hash) { // 如果匹配了高亮页
            if (document.location.hash.match(new RegExp(pattern))) {
                page = this.hash[pattern];
                break;
            }
        }
        if (page[0] === null) {
            for (var i = 0; i < option.config.length; i++) {
                if (document.location.hash.match(new RegExp("hight=" + option.config[i]['name']))) {
                    page[0] = i;
                    break;
                }
            }
        }
        if (page[0] === null) { // 默认使用已经保存的页Index
            page[0] = 0; // 首次定位在第一页
        }
			//alert(window.location.hash);
		if(window.location.hash){window.location.hash = '';}
		option._menu.select(page[0],true);
    },
    module: {
        seperator: {
            init: function () {
            },
            render: function (target) {
                target.append('<div class="item seperator"></div>')
            },
            recoverdefault: function () {
            }
        }
    },
/*    run: function (index, code) {
        try {
            DoAction(index, code);
        } catch (e) {
        }
    },
    // 选择路径
    path: function (index, code) {
        var value = '', state = -1;
        try {
            state = DoActionEx(index, code, value);
        } catch (e) {
        }
        if (state == 0) {
            return true;
        }
        return false;
    },*/
    // 读配置
	init_config:function()	{
		try{
			var cfgTem = window.top.bfccfg.getAllConfig();
			eval('var cfgDataTem = {'+cfgTem+'}');
			this.cfgData = cfgDataTem;
			//alert("d版本号："+cfgDataTem["cfg_version"]);
		}
		catch(e)
		{
			alert("init config data error");
		}
		//alert("init_config");
	},
	getCfgValue:function (cfg_name) {
		//alert(this.cfgData[cfg_name]);
		return this.cfgData[cfg_name];
	},
    // 存配置
	setCfgValue:function(cfg_name, value) {
		/*if (typeof(value) == "boolean"){
			this.cfgData[cfg_name] 
		}*/
		this.cfgData[cfg_name]=value;
	}
};
