var planesjson;
window.onload = function() {
$(document).ready(function() {

	//step3:启动监控程序
	wowpStart();
	monitorStart();
	$("#begin").remove();
	$("#planes").load("..\\..\\dossier\\planes.json",function(data){
		planesjson=JSON.parse(data);
	});
	$("#configbutton").click(function(){
		configPage();
		//customPath();
	});
	$("#battlestatbutton").click(function(){
		if(!$("#battlestatbutton").parent().hasClass("active")){
			battlePage();
			showRecentBattles();
			setInterval(showRecentBattles, 10000);
		}
	});
	$("#playerbutton").click(function(){
		playerPage();
	});
	
	$("#msgbutton").click(function(){
		msgPage();
	});
	$('#search').click(function(){
		console.log($('#searchbar').val());
		console.log($('#searchzone').val());
		if ($('#searchbar').val().trim()!=''){
			var name=$('#searchbar').val();
			var zone='';
			if($(this).text()=='北区'){
				zone='1';
			}else {
				zone='2';
			}
			window.open("http://rank.kongzhong.com/wowpweb/index.html?name="+encodeURI(encodeURI(name))+"&zone="+zone,'_blank');
		}
	});
	$('.dropdown-menu').children('li').children('a').click(function(){
		$(this).parent().parent().parent().children('button:first').text($(this).text());
	});
	$("#woticon").click(function(){
		changeApp("..\\index.html","wot",false);
	});
	window.setTimeout(function() { 
		if(!$("#battlestatbutton").parent().hasClass("active")){
			battlePage();
			showRecentBattles();
			setInterval(showRecentBattles, 10000);
		}
	}, 3000); 
	$("#minibutton").click(function(){min2tray();});
	$("body").append('<iframe style="display: none;" src="http://rank.kongzhong.com/pwsbindex.html"></iframe>');

    var version=new Config("version.db");
    if(!checkERROR(version.get('wowp'))){
        document.title='战争沙盘'+version.get('wowp');
    }
});
}

//实时效率页面
function battlePage(){
	changePage();
	$("#battlepage").show();
	$("#battlestatbutton").parent().addClass("active");
}

//效率分析页面
function playerPage(){
	changePage();
	playerlist();
	$("#playerbutton").parent().addClass("active");
}

//消息盒子页面
function msgPage(){
	changePage();
	$("#messagepage").show();
	readedmessage=message;
	updateMsgbadge();//util.js
}
//配置页面
function configPage(){
	changePage();
	refreshConfig();
	$("#configbutton").parent().addClass("active");
}


//切换页面的预动作
function changePage(){
	$(".index").hide();
	$(".active").removeClass("active");
	clearInterval(showRecentBattles);
}
