//var useNav=true;
//var o_nav='';
var navUtils1={//导航工具类
	init:function(data){
		this.navData=data;
		this.navView=true;
		this.navDataMap={};
		this.currentNav={width:671,height:549};
		for(var i=0;i<data.length;i++){
			this.navDataMap[data[i].id]=i;
		}
	},
	getWidth:function(){
		return this.currentNav.width;
	},
	getHeight:function(){
		return this.currentNav.height;
	},
	getHtml:function(id){//产生导航图的html代码
		var pos=0;
		if(id)pos=this.navDataMap[id];
		var nav=this.navData[pos];
		if(!nav) return o_nav;

		this.currentNav.id=nav.id;

		var htmlStr='';
		htmlStr+=this.getImageHtml(nav);
		htmlStr+=this.getMapHtml(nav);
		htmlStr+=o_nav;

		return htmlStr;
	},
	getImageHtml:function(nav){//产生导航图的图片
		var width=671;
		var height=549;
		if(nav.width) width=nav.width;
		if(nav.height) height=nav.height;

		this.currentNav.width=width;
		this.currentNav.height=height;

		var src=nav.image;
		var htmlStr='<img src="http://'+domain_config.image+src+'" border="0" width="'+width+'" height="'+height+'" usemap="#Map" />';
		if(this.getFileExt(src)=='png'){
			htmlStr='<div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://'+domain_config.image+src+');width:'+width+'px;height:'+height+'px;"></div><img id="navBlankImg" src="images/map/nav/nav_t.gif" style="position:absolute;left:0px;top:0px;z-index:2" usemap="#Map" >';
		}
		else{
		}
		return htmlStr;
	},
	getMapHtml:function(nav){//产生导航图的Map
		var anchorArr=nav.anchors;
		var htmlStr='<map id="Map" name="Map">\n';
		for(var i=0;i<anchorArr.length;i++){
			var anchor=anchorArr[i];
			htmlStr+='<area shape="poly" coords="'+anchor.coords+'" href="#" onclick="navUtils1.enterByNav('+anchor.params+');return false;" title="'+anchor.name+'" />\n';
		}
		htmlStr+='</map>\n';
		return htmlStr;
	},
	loadNav:function(id){//加载导航图
		var htmlStr=this.getHtml(id);
		$('divMapNavContent').innerHTML=htmlStr;
		this.switchNavView(true);
	},
	switchNavView:function(flag){//切换导航图
		if(typeof(flag)=='undefined'){
			if($('divMapNav').style.display=='none'){
				$('divMapNav').style.display='';
				this.navView=true;
				if(!this.navTimer)this.navTimer=setInterval(this.openNav.bind(this),10);
			}
			else{
				this.navView=false;
				if(!this.navTimer)this.navTimer=setInterval(this.closeNav.bind(this),10);
			}
		}
		else{
			if(flag){
				if($('divMapNav').style.display=='') return;
				this.navView=true;
				$('divMapNav').style.display='';
				if(!this.navTimer)this.navTimer=setInterval(this.openNav.bind(this),10);
			}
			else{
				if($('divMapNav').style.display=='none') return;
				this.navView=false;
				if(!this.navTimer)this.navTimer=setInterval(this.closeNav.bind(this),10);
			}
		}
		//this.down1();
	},
	openNav:function(){//打开导航图
		var divMapHeight=$('mapDiv').offsetHeight;//
		var h=$('divMapNav').offsetHeight;
		var step=45;
		if(h<divMapHeight){
			if(h+step<=divMapHeight)$('divMapNav').style.height=h+step+'px';
			else $('divMapNav').style.height=divMapHeight+'px';
		}
		else{
			clearInterval(this.navTimer);
			this.navTimer=null;
		}
	},
	closeNav:function(){//关闭导航图
		var h=$('divMapNav').offsetHeight;
		var step=45;
		if(h>step){
			$('divMapNav').style.height=h-step+'px';
		}
		else{switchObjView('loading',false);
			$('divMapNav').style.display='none';
			clearInterval(this.navTimer);
			this.navTimer=null;
		}
	},
	writeNav:function(){//将导航图写入界面
		var htmlStr=this.getHtml();
		if(useNav&&htmlStr)document.write(htmlStr);
		else{
			$('divMapNav').style.display='none';
			$('navMenuDiv').style.display='none';
		}
		if(o__customValue.nav)this.navMainMenuClick();
	},
	getFileExt:function(file){
		var index=file.lastIndexOf('.');
		var ext=file.substring(index+1,file.length);
		return ext.toLowerCase();
	},
	enterByNav:function(id,type,p2){//进入
		type=type||1;
		if(this.getNavStatus()) this.navMainMenuClick();
		else return;
		if(type==3){
			showStationById(id);
		}
		else showResult(id,type);
	},
	getNavStatus:function(){
		if($('divMapNav').style.display=='')
			return true;
		else 
			return false;
	},
	switchNavViewOut:function(flag){
		var id=this.currentNav.id;
		var menuObj=MainMenu.getMenuItemById('nav_'+id);
		if(!menuObj) return;
		if(typeof flag=='undefined'){
			if(menuObj.isCheck) flag=false;
			else flag=true;
		}		
		if(flag){
			menuObj.select();
			this.switchNavView(true);
		}
		else{
			menuObj.unSelect();
			this.switchNavView(false);
		}
	},
	getMenu:function(){//创建导航图的菜单
		var menu=[];
		menu.push({id:'nav',name:'导航',option:{clickFun:this.navMainMenuClick.bind(this)}});
		var child=this.getMenuData();
		menu[0]['menu']=menuUtil.getMenuDataFromDb(child);

		var mainMenu=new MainMenu();
		for(var i=0;i<menu.length;i++){
			var m=menu[i];
			var mainMenuItem=mainMenu.addItem(new MainMenuItem(m,m.option));
			if(m.menu)mainMenuItem.setChildMenu(menuUtil.getChildMenu(m.menu,{width:100}));
		}
		return mainMenu;
	},
	navMainMenuClick:function(o){//导航图主菜单的点击事件
		//alert(o.id);
		this.switchNavViewOut();
	},
	navMenuClick:function(o){//导航图的子菜单点击事件
		//alert(o.data.dbid);
		if(o.isCheck){
			this.loadNav(o.data.dbid);
		}
		else{
			this.switchNavView(false);
		}
	},
	getMenuData:function(){
		var data=[];
		var navData=this.navData;
		for(var i=0;i<navData.length;i++){
			var item=navData[i];
			var o={};
			o.id='nav_'+item.id;
			o.dbid=item.id;
			o.name=item.name;
			o.option={type:'radio',clickFun:this.navMenuClick.bind(this)};
			data.push(o);
		}
		return data;
	}
};

//navUtils.init([{"id":16,"anchors":[{"id":171,"coords":"378,232,458,234,459,216,405,216,403,198,392,189,370,202,373,224","name":"广州市工商行政管理局","params":"889"},{"id":173,"coords":"430,309,489,309,489,298,487,292,471,259,442,275,452,295,431,293","name":"天河区政府","params":"7938"},{"id":159,"coords":"213,109,223,103,223,88,216,83,214,74,178,74,178,87,202,87","name":"广州市旅游局","params":"4545"},{"id":160,"coords":"225,142,237,148,245,142,244,123,238,112,208,112,206,122,226,124","name":"广州市公安局","params":"4084"},{"id":165,"coords":"247,151,260,159,272,153,273,140,284,138,282,131,248,130,247,139","name":"广州市地方税务局","params":"5585"},{"id":163,"coords":"235,109,249,102,251,87,321,89,324,75,229,75,226,90,228,108","name":"广州市劳动和社会保障局","params":"11083"},{"id":158,"coords":"136,127,195,125,203,120,203,106,183,89,175,95,173,112,138,114","name":"荔湾区政府","params":"5865"},{"id":162,"coords":"154,194,214,194,214,183,200,180,202,174,200,154,186,148,179,160,178,180,156,183","name":"海珠区政府","params":"37521"},{"id":172,"coords":"328,268,391,269,390,254,372,253,370,221,358,213,345,220,346,251,327,253","name":"广州市国家税务局","params":"8167"},{"id":164,"coords":"244,114,265,128,277,118,295,112,296,100,254,99","name":"广州市人民政府","params":"10691"},{"id":167,"coords":"319,106,376,107,377,96,363,93,340,74,333,86,318,94","name":"白云区政府","params":"12022"},{"id":170,"coords":"248,209,350,210,351,200,328,196,319,175,309,174,305,195,250,196","name":"广州市疾病预防控制中心","params":"12891"},{"id":168,"coords":"300,143,367,143,366,133,315,132,315,108,302,102,299,113","name":"广州市中级人民法院","params":"15124"},{"id":161,"coords":"208,165,241,163,239,153,224,152,222,134,207,126,202,129,201,150","name":"广州民政局","params":"4163"},{"id":166,"coords":"233,186,267,186,269,163,248,154,245,169,231,174","name":"广州市教育局","params":"83488"},{"id":169,"coords":"280,169,290,173,304,168,346,165,347,153,305,153,299,143,291,138,282,149","name":"越秀区政府","params":"5639"}],"height":549,"name":"政府","width":671,"image":"/upload/nav/1/3355440.gif"},{"id":18,"anchors":[],"height":549,"name":"默认·","width":671,"image":"/upload/nav/1/9622438.gif"}],1);