define(function(require, exports, module) {
	var global = require("../../js/global");
	var jGlobal = require("./oneUpgradeGlobal");
	global.configMgrIns.writeConfig('upgradeNoWarn', false); //第一次进入升级页面显示升级警告，之后不再显示。在这里赋值好像不太好。。
	
	function init() {
		initDom();
		initGlobalEvent();
		initEvent();
		
		function initDom() {
			$('#upgradeWarnModal').modal({
				backdrop: 'static',
				show: false
            });

			///////////////////////////////////TODO//////////////////////////////////////
            if (jGlobal.oneUpgrade.curPage == null || jGlobal.oneUpgrade.curPage == "oneUpgrade") {
                // $('#oneUpgrade').addClass('curSelectItem');
                $('#acUpgrade').addClass('curSelectItem');
            } else if (jGlobal.oneUpgrade.curPage == "acUpgrade") {
                $('#acUpgrade').addClass('curSelectItem');
            } else if (jGlobal.oneUpgrade.curPage == "fatApUpgrade") {
                $('#fatApUpgrade').addClass('curSelectItem');
            }
            ///////////////////////////////////TODO//////////////////////////////////////
		}
		function initEvent() {
			//显示升级警告			
			//if (global.configMgrIns.readConfig('upgradeNoWarn') == false || global.configMgrIns.readConfig('upgradeNoWarn') == undefined) {
			//	$("#upgradeWarnModal").modal('show');
			//}
			$("#upgradeWarnModal .btn-confirm").click(function() {
				if ($("#knowRisk").is(':checked') == true) {
					global.configMgrIns.writeConfig('upgradeNoWarn', $("#noWarn").is(':checked'));
					$("#upgradeWarnModal").modal('hide');
				}
			});			
//			$("#noWarn").change(function() {
//		        global.configMgrIns.writeConfig('upgradeNoWarn', $("#noWarn").is(':checked'));
//		    });

            ///////////////////////////////////TODO//////////////////////////////////////
			//根据当前选中的菜单加载页面
			var curElement = ".selectDeviceContent";			
			if (jGlobal.oneUpgrade.curPage == null || jGlobal.oneUpgrade.curPage == "oneUpgrade") {
				// var nextPageUrl = "./oneUpgrade/html/selectDevice.html";
                var nextPageUrl = "./oneUpgrade/html/acSelectDevice.html";
			} else if (jGlobal.oneUpgrade.curPage == "acUpgrade") {
				var nextPageUrl = "./oneUpgrade/html/acSelectDevice.html";
			} else if (jGlobal.oneUpgrade.curPage == "fatApUpgrade") {
                var nextPageUrl = "./oneUpgrade/html/fatApDiscover.html";
            }
			global.enterPageCallback(curElement, nextPageUrl);
            ///////////////////////////////////TODO//////////////////////////////////////

			//注册菜单切换事件
		    $(".faultDiagItem").on("click", function() {
				$(".faultDiagItem").removeClass("curSelectItem");
				$(this).addClass("curSelectItem");
			});
		    
		    $("#oneUpgrade").click(function() {
		    	jGlobal.oneUpgrade.curPage = "oneUpgrade";
				var curElement = ".selectDeviceContent", nextPageUrl = "./oneUpgrade/html/selectDevice.html";
				global.enterPageCallback(curElement, nextPageUrl);
			});
			
			$("#acUpgrade").click(function() {
				jGlobal.oneUpgrade.curPage = "acUpgrade";
				var curElement = ".selectDeviceContent", nextPageUrl = "./oneUpgrade/html/aCselectDevice.html";
				global.enterPageCallback(curElement, nextPageUrl);
			});

            $("#fatApUpgrade").click(function() {
                jGlobal.oneUpgrade.curPage = "fatApUpgrade";
                var curElement = ".selectDeviceContent", nextPageUrl = "./oneUpgrade/html/fatApDiscover.html";
                global.enterPageCallback(curElement, nextPageUrl);
            });
		    
		    $("#upgradeLegend").click(function() {
				var curElement = ".selectDeviceContent", nextPageUrl = "./oneUpgrade/html/upgradeLegend.html";
				global.enterPageCallback(curElement, nextPageUrl);
			});
		}
		function initGlobalEvent() {
			global.exitPageCallback.exitFun = function () {
				return true;
			}
		}
	}
	exports.init = init;
});