﻿mapnav=new Array();
mapnav[0]=new Array("left",["0","综合","all"]);
mapnav[1]=new Array("left",["457","卡利姆多","kali"],[["141","泰达希尔","1"],["3525","秘血岛","2"],["3524","秘蓝岛","3"],["493","月光林地","4"],["148","黑海岸","5"],["361","费伍德森林","6"],["618","冬泉谷","7"],["331","灰谷","8"],["16","艾萨拉","9"],["406","石爪山脉","10"],["17","贫瘠之地","11"],["14","杜隆塔尔","12"],["405","凄凉之地","13"],["215","莫高雷","14"],["15","尘泥沼泽","15"],["357","菲拉斯","16"],["400","千针石林","17"],["1377","希利苏斯","18"],["490","安戈洛环行山","19"],["440","塔纳利斯","20"],["1637","奥格瑞码 [城市]","12"],["3557","艾索达 [城市]","3"],["1638","雷霆崖 [城市]","14"],["1657","达纳苏斯 [城市]","1"]]);
mapnav[2]=new Array("left",["-3","东部王国","dongbu"],[["4080","奎尔丹纳斯岛","1"],["3430","永歌森林","2"],["3433","幽魂之地","3"],["85","提瑞斯法林地","4"],["28","西瘟疫之地","5"],["139","东瘟疫之地","6"],["130","银松森林","7"],["36","奥特兰克山脉","8"],["47","辛特兰","9"],["267","希尔斯布莱德丘陵","10"],["45","阿拉希高地","11"],["11","湿地","12"],["1","丹莫罗","13"],["38","洛克莫丹","14"],["51","灼热峡谷","15"],["3","荒芜之地","16"],["46","燃烧平原","17"],["12","艾尔文森林","18"],["44","赤脊山","19"],["40","西部荒野","20"],["10","暮色森林","21"],["41","逆风小径","22"],["8","悲伤沼泽","23"],["33","荆棘谷","24"],["4","诅咒之地","25"],["3487","银月城 [城市]","2"],["1497","幽暗城 [城市]","4"],["1537","铁炉堡 [城市]","13"],["1519","暴风城 [城市]","18"]]);
mapnav[3]=new Array("left",["-2","外域","outland"],[["3523","虚空风暴","1"],["3522","刀锋山","2"],["3521","赞加沼泽","3"],["3518","纳格兰","4"],["3483","地狱火半岛","5"],["3519","泰罗卡森林","6"],["3520","影月谷","7"],["3703","沙塔斯城 [城市]","6"]]);
mapnav[4]=new Array("right",["-4","其他","other"],[["2597","奥特兰克山谷 [战场]","1"],["3358","阿拉希盆地 [战场]","2"],["3820","风暴之眼 [战场]","3"],["3277","战歌峡谷 [战场]","4"]]);

minimaparr=new Array("mini-all-back","mini-kalimdor-back","mini-dongbu-back","mini-outland-back");
iscreaturl=true;
tmpmapinfo=new Array();
mapdata=new Array();
urlstr=new Array("","","");
tiplistobj=new Object();
tipsobj=new Object();
isPinset=false;
isMouseOver=false;

ua=navigator.userAgent.toLowerCase();
isIE6=ua.indexOf("msie 6")>-1;

maptagcut=22;
function showtips(obj,text){
	isPinset=false;
	if(text!=""&&text!=null){
		$("#toolBox").html(text);
		tipobj=document.getElementById("tipdiv");
		tipX=(obj.offsetParent.offsetLeft+tipobj.offsetWidth+10)<mapw?(obj.offsetParent.offsetLeft+10):(mapw-tipobj.offsetWidth-(mapw-obj.offsetParent.offsetLeft)-9);
		tipY=(obj.offsetParent.offsetTop+tipobj.offsetHeight+20)<maph?(obj.offsetParent.offsetTop+4):(maph-tipobj.offsetHeight-(maph-obj.offsetParent.offsetTop)-9);
		//$("#tipshadow").css("width",tipobj.offsetWidth);$("#tipshadow").css("height",tipobj.offsetHeight);
		$("#tipdiv").css('left',tipX);
		$("#tipdiv").css('top',tipY);
		}
		}
function hidetips(obj,set){
	if((set==undefined)||(set==true)){isPinset=true;}
	try{$("#tipdiv").css('left',-1000);}catch(e){}
	}

function creaturl(maptag,mapid){
fetchHttpGetQuery=function(){
	slh=self.location.href;
    querystr=slh.indexOf('?')==-1?slh.split("#"):slh.split("?");
    if(querystr[1]){
        GETs = querystr[1].split( "&" );
        GET = new Object();
        for( i = 0 ; i < GETs.length ; i++ ) {
            tmp_arr = GETs[i].split( "=" );
            key = tmp_arr[0];
			tmp_arr_more=tmp_arr[1].split(":");
            GET[key] = tmp_arr_more;
        }
    }
    return querystr;
}
	if(iscreaturl){
		_=fetchHttpGetQuery();
		_id=mapid==undefined?tmpmapinfo[maptag][0]:mapid;
		self.location.href=_[0]+"#maps="+_id;
		//alert(GET["tid"])
	}
}
function getvalue(v){
	_=location.href.indexOf(v);
	if((_!= -1)&&(_!=location.href.length-1)){val=location.href.substr(_+v.length+1,location.href.length).split("&");}
	else val=null;
	return val;
}
function changemap(mtag,mid,mdata){
	showlefttiplist=function(x){
		if(document.getElementById("tiplist")){
			if(tiplistobj[x]){$('#tiplist').html(tiplistobj[x]);$('#tiplist').fadeIn(500);}
			else{$.xslt({xmlUrl:'xml/list_'+x+'.xml', xslUrl:'xsl/leftlist.xsl',callback:function(v){if(v){tiplistobj[x]=v;$('#tiplist').html(v);$('#tiplist').fadeIn(500);}}});}}
	}
	showdefpins=function(z){
		
		if((mdata==undefined)&&(z!=0)){
			if(!tipsobj[z])tipsobj[z]=new Object();
			if(tipsobj[z]["default"]){$("#pindiv").html(tipsobj[z]["default"]);showlefttiplist(z);}
			else{
				$.xslt({xmlUrl:"xml/"+z+".xml",xslUrl:"xsl/defaultpin.xsl",callback:function(v){
				tipsobj[z]["default"]=v;
				$("#pindiv").html(tipsobj[z]["default"]);
				showlefttiplist(z);
				//$("#debug").html("数量："+$("#pindiv span").length+"<br>");
				}
				});
			}
		}
		else {showlefttiplist(z);}
	}
	changepinstype=function(x){
		if(x=="0"){isPinset=false;gp.style.display="none";gt.style.display="none";}
		else{isPinset=true;gp.style.display="block";gt.style.display="block";}
	}
		
	if(mid!=undefined){
		try{$("#tagbtn_"+mtag+"%20.btnul").children().removeClass("navbtnacut");$("#tagbtn_"+mtag+"%20.btnul").children().eq(tmpmapinfo[mtag][2]-1).addClass("navbtnacut");}catch(e){}
		stripmap.childNodes[0].childNodes[mtag].innerHTML="<img src='http://images.warcraftchina.com/images_wow/info/maps/3005/"+maptype+"/"+mid+".jpg'/>";
		}
	try{uid=tmpmapinfo[mtag][0]}catch(e){uid=mapnav[mtag][1][0];};
	changepinstype(mtag);
	$('#slidemap').animate({left:(mtag*-700)+1},400,'easeOut');
	$('#minimap').animate({left:(mtag*-180)+1},400,'easeOut');
	
	try{$("#"+minimaparr[mtag]).css("background-position","0 -"+(tmpmapinfo[mtag][2]*300)+"px");}catch(e){};
	try{if($('#tiplist').css("display")!="none")$('#tiplist').fadeOut(300);setTimeout(function(){showdefpins(uid);},400);}catch(e){};
	try{$("#nav-txt").html("魔兽世界地图&nbsp;-&nbsp;"+mapnav[mtag][1][1]+(tmpmapinfo[mtag][1]==mapnav[mtag][1][1]?"":"&nbsp;-&nbsp;"+tmpmapinfo[mtag][1]));}catch(e){$("#nav-txt").html("魔兽世界地图&nbsp;-&nbsp;"+mapnav[mtag][1][1]);};
	$('#pindiv').html("");
	try{creaturl(mtag,uid);}catch(e){};
}

(function($){
$.fn.setmap=function(size,h,o){
	try {tagnum=mapnav.length;}catch(e){tagnum=1;}
	switch (size){case"middle":maptype=size;mapw=700;maph=466;break;case"small":maptype=size;mapw=576;maph=384;break;default:maptype="small";mapw=576;maph=384;break;}
	if(document.getElementById("stripnav")){$("#stripnav").setnav(mapnav);}
	return i(this,h,o);};
$.mxy={Pinshow:function(){},Pinset:function(){if(isPinset)addPin(mouseX,mouseY);},stop:function(){g_setTextNodes(gp,"");}};
var i=function(e,h,o){return e.each(function(){
	stripmap=g_stripmap();ae(this,stripmap);
	layoutdiv=ce("div");layoutdiv.id="layoutdiv";ae(this,layoutdiv);
	glowdiv=ce("div","width:"+mapw+"px;height:"+maph+"px;position:absolute;left:0px;top:0px;background:url(http://images.warcraftchina.com/images_wow/shared/pixel.gif);");			ae(this,glowdiv);
	gp=g_createGlow("(0.0, 0.0)","position:absolute;bottom:0px;left:56px;");ae(glowdiv,gp);
	gt=g_createGlow("隐藏地图注释","position:absolute;bottom:0px;right:68px;cursor:pointer");gt.onmouseover=function(){isPinset=false;};gt.onmouseout=function(){if(this.childNodes[9].innerHTML=="隐藏地图注释"){isPinset=true;}else{isPinset=false;}};gt.onclick=function(){if(this.childNodes[9].innerHTML=="隐藏地图注释"){g_setTextNodes(gt,"显示地图注释");$("#pindiv").css("visibility","hidden");isPinset=false;}else{g_setTextNodes(gt,"隐藏地图注释");$("#pindiv").css("visibility","visible");}};ae(glowdiv,gt);
	//gc=g_createGlow("清除地图注释","position:absolute;bottom:0px;right:178px;cursor:pointer");gc.onmouseover=function(){isPinset=false;};gc.onmouseout=function(){isPinset=true;};gc.onclick=function(){$("#pindiv").html("");};ae(glowdiv,gc);
	pindiv=ce("div","width:"+mapw+"px;height:"+maph+"px;position:absolute;left:0px;top:0px;");pindiv.id="pindiv";ae(this,pindiv);
	
	tipdiv=ce("div","position:absolute;z-index:999999;font:12px Arial, Helvetica, sans-serif;left:-1000px;width: auto;");tipdiv.innerHTML="<table><tbody><tr><td class='tl'></td><td class='t'></td><td class='tr'></td></tr><tr><td class='l'><q></q></td><td class='bg'><div id='toolBox'></div></td><td class='r'><q></q></td></tr><tr><td class='bl'></td><td class='b'></td><td class='br'></td></tr></tbody></table>";tipdiv.id="tipdiv";tipdiv.className="tooltip";ae(this,tipdiv);
	//tipshadow=ce("div","position:absolute;background:#160d03;filter:alpha(opacity=52);opacity:0.52;left:-1000px;");tipshadow.id="tipshadow";ae(this,tipshadow);
	//tipdiv=ce("div","position:absolute;border:#252525 1px solid;font:12px Arial, Helvetica, sans-serif;color:#fda061;padding:2px 4px;border-top:#6c6b6b 1px solid; border-left:#6c6b6b 1px solid;left:-1000px;");tipdiv.id="tipdiv";ae(this,tipdiv);
	
	e.bind('mousemove',{e:e},function(v){
		var d=v.data;E=d.e;
		M={W:f('width')||E[0].scrollWidth||0,H:f('height')||E[0].scrollHeight||0,pX:v.pageX,pY:v.pageY};
		$(E).mouseout($.mxy.stop);
		//.mousedown($.mxy.Pinshow).mouseup($.mxy.Pinset)
		mouseX=Math.floor(((M.pX-ac(this)[0])/M.W*1000))/10;
		mouseY=Math.floor(((M.pY-ac(this)[1])/M.H*1000))/10;
		g_setTextNodes(gp,"("+mouseX.toFixed(1)+", "+mouseY.toFixed(1)+")");
		return false;
 		});
	switch (maptype)
	{
		case "small":changemap(0,h==null?0:h,o);break;
		default:try{tmpmapinfo[mapdata[h][0]]=mapdata[h][1];maptagcut=document.getElementById("stripnav").childNodes[0].childNodes[mapdata[h][0]].offsetLeft+22;navarrowmove(maptagcut);changemap(mapdata[h][0],h,o);}catch(s){changemap(0,mapnav[0][1][0]);};break;
	}
	});},
f=function(k){return parseInt(E.css(k))||false;};
ac=function(z){var a=0,b=0;while(z){a+=z.offsetLeft;b+=z.offsetTop;z=z.offsetParent;}return [a,b];};
ce=function(z,c){var x=document.createElement(z);x.style.cssText=c;return x;};
ae=function(z,y){return z.appendChild(y);};
ct=function(z){return document.createTextNode(z);};
g_setTextNodes=function(n,nv){if(n.nodeType==3){n.nodeValue=nv;}else{for(var i=0;i<n.childNodes.length;++i){g_setTextNodes(n.childNodes[i],nv);}}}
g_createGlow=function(txt,cs){var s=ce("span","font:12px Arial, Helvetica, sans-serif;"+(cs!=null?cs:""));for(var i=-1;i<=1;++i){for(var j=-1;j<=1;++j){var d=ce("div","position:absolute;white-space:nowrap;left:"+i+"px;top:"+j+"px;font:12px Arial, Helvetica, sans-serif;");if(i==0&&j==0){d.style.color="#ffffff";d.style.zIndex=4;}else{d.style.color="#000000";d.style.zIndex=2;}ae(d,ct(txt));ae(s,d);}}s.className="glow";var ph=ce("span");ph.style.visibility="hidden";ae(ph,ct(txt));ae(s,ph);return s;};
g_stripmap=function(){var s=ce("div","position:absolute;overflow:hidden;width:"+mapw+"px;height:"+maph+"px;clear:both;left:0px;top:0px;");var p=ce("div","width:"+mapw*tagnum+"px;position:relative;left:0;top:0;");p.id="slidemap";for(var i=0;i<tagnum;i++){var panel=ce("div","float:left;position: relative;width:"+mapw+"px;height:"+maph+"px;");panel.innerHTML="<img src='http://images.warcraftchina.com/images_wow/info/maps/3005/"+maptype+"/"+mapnav[i][1][0]+".jpg'/>";ae(p,panel);};ae(s,p);return s;};
addPin=function(x,y){var cuspin=ce("span","display:block;position:absolute;left:"+x+"%;top:"+y+"%;");var cusa=ce("a");cusa.className="pin";cusa.onmouseover=function(){isPinset=false;};cusa.onmouseout=function(){isPinset=true;};cusa.onmouseup=function(){delPin(this)};ae(cuspin,cusa);ae(pindiv,cuspin);
urlstr[2]+=(x+" "+y)+",";
//$("#debug").html(urlstr[2]);
}
delPin=function(obj){
obj.parentNode.style.display="none";
xxxx=obj.parentNode.style.left.replace("%","");
yyyy=obj.parentNode.style.top.replace("%","");
u=xxxx+" "+yyyy;
urlstr[2]=urlstr[2].replace(u+",","");
//$("#debug").html(urlstr[2]);
}
})(jQuery);


(function($){
$.fn.setnav=function(navdata){
	return this.each(function(){
		var navarrow=ce("div","left:22px;");navarrow.id="navarrow";
		var s=ce("div","height:27px;width:100%;");
			taglength=navdata.length;
		for(var i=0;i<taglength;i++){
			mapdata[navdata[i][1][0]]=new Array(i,navdata[i][1]);
			ae(s,navbtndiv(navdata,i));
		}
		ae(s,navarrow);
		ae(this,s);
	});
};

navbtndiv=function(_d,_i){
	var navbtn=ce("div","float:"+_d[_i][0]+";width:115px; height:16px;padding:11px 0 0 0;position:relative; background:url(http://images.warcraftchina.com/images_wow/info/map/btn_stripnav.gif);");navbtn.id="tagbtn_"+(_i);
	navbtntxt=ce("div","width:115px;height:16px;text-align:center;color:#fde360;line-height:16px;font-family:Arial, Helvetica, sans-serif;font-size:12px;cursor:pointer;overflow:hidden;");navbtntxt.innerHTML=_d[_i][1][1];ae(navbtn,navbtntxt);
			try{
	btnlength=_d[_i][2].length;
	var btndiv=ce("div","padding:14px 0 4px 0;width:115px;");btndiv.className="btndiv";
	var shadowdiv=ce("div","width:115px; height:"+(btnlength*18+8)+"px;font-size:0;position:absolute;left:0;top:10px;border:#514c44 1px solid;");shadowdiv.className="shadow";ae(btndiv,shadowdiv);
	fright=isIE6?"14":"13";
	ae(btndiv,ce("div","background:url(http://images.warcraftchina.com/images_wow/info/map/nav_float_lt.gif);width:32px; height:16px;font-size:0;position:absolute;left:-11px;top:3px;"));
	ae(btndiv,ce("div","background:url(http://images.warcraftchina.com/images_wow/info/map/nav_float_rt.gif);width:32px; height:16px;font-size:0;position:absolute;right:-"+fright+"px;top:3px;"));
	ae(btndiv,ce("div","background:url(http://images.warcraftchina.com/images_wow/info/map/nav_float_lb.gif);width:32px; height:16px;font-size:0;position:absolute;left:-11px;bottom:-9px;"));
	ae(btndiv,ce("div","background:url(http://images.warcraftchina.com/images_wow/info/map/nav_float_rb.gif);width:32px; height:16px;font-size:0;position:absolute;right:-"+fright+"px;bottom:-9px;"));
	var btnul=ce("div","position:relative;top:0;padding:0;");btnul.className="btnul";
	for(var j=0;j<btnlength;j++){
		var linkdata=_d[_i][2][j];
		mapdata[linkdata[0]]=new Array(_i,linkdata);
		ae(btnul,navbtna(linkdata,_i));
		ae(btndiv,btnul);
		ae(navbtn,btndiv);
	}
			}catch(e){};
	navbtntxt.onclick=function(){
		maptagcut=this.parentNode.offsetLeft+22;
		if(stripmap.childNodes[0].childNodes[_i].innerHTML==""){changemap(_i,_d[_i][1][0]);}
		else{changemap(_i);}
		return false;
	};
	navbtn.onmouseover=function(){
		if(!isMouseOver){
			isMouseOver=true;
			navobj=this.childNodes[1];
			try{$(navobj).show();}catch(e){};
			navarrowmove(this.offsetLeft+22);
			//$("#debug").html($("#debug").html()+"打开-,");
			//$(this).siblings().children(".btndiv").hide();
			}
		}
	navbtn.onmouseout=function(event){
		try {
			e = event || window.event;
			o = e.relatedTarget||e.toElement;
			arrobj=document.getElementById("navarrow")!=o;
			while(o.parentNode&&o!=this){o=o.parentNode;}
			if((o!=this)&&(arrobj)){isMouseOver=false;
				try{
					$(this.childNodes[1]).animate({ height:'hide',opacity:'hide'},250);
					//$("#debug").html($("#debug").html()+"关闭-,<BR/>");
				}catch(e){};
			setTimeout(function(){if(!isMouseOver){navarrowmove(maptagcut);}},250);
				}
		}catch(e){}
		};	
	return navbtn;
};
navbtna=function(ld,ia){
	var btnli=ce("div","height:18px;margin:0;");
	var btna=ce("a");btna.className="navbtna";btna.href="#map="+ld[0];btna.innerHTML=ld[1];
	btnli.onclick=function(){isMouseOver=false;
		$(this.parentNode.parentNode).animate({ height:'hide', opacity:'hide'},250);
		maptagcut=this.parentNode.parentNode.parentNode.offsetLeft+22;
		tmpmapinfo[ia]=ld;
		changemap(ia,ld[0]);
		}
	btna.onclick=function(){return false;}
	ae(btnli,btna);
	return btnli;
};
navarrowmove=function(offsetleft){$("#navarrow").animate({left:offsetleft},250,'expoout');};
})(jQuery);
function mms(mtg,top,evt){
	minitipobj=document.getElementById('minitip');
	wxy=ac(document.getElementById('minimap'));
	tipX=evt.clientX-wxy[0]-document.getElementById('minitip').offsetWidth/2;
	tipY=evt.clientY-wxy[1]+(document.documentElement.scrollTop==0?document.body.scrollTop:document.documentElement.scrollTop);
	if((tipX+minitipobj.offsetWidth)>(Math.abs(document.getElementById('minimap').offsetLeft)+180))minitipX=Math.abs(document.getElementById('minimap').offsetLeft)+180-minitipobj.offsetWidth;
	else if((tipX)<(Math.abs(document.getElementById('minimap').offsetLeft)))minitipX=Math.abs(document.getElementById('minimap').offsetLeft);
	else minitipX=tipX;
	minitipY=tipY-30<10?tipY+20:tipY-40;
	minitipobj.style.left=minitipX+"px";
	minitipobj.style.top=minitipY+"px";
}
function mmi(mtg,top){
	mapinfoall=mapnav[mtg][2][top-1];
	document.getElementById('minitipBox').innerHTML=mapinfoall[1];
	$('#'+minimaparr[mtg]+' img').css("background-position","0 -"+(top*300)+"px");
}
function mmo(mtg){
	$('#'+minimaparr[mtg]+' img').css("background-position","0 0");
	document.getElementById('minitip').style.left="-1000px";
}
function mmp(mtg,top){
	mapinfoall=mapnav[mtg][2][top-1];
	tmpmapinfo[mtg]=mapinfoall;
	changemap(mtg,mapinfoall[0]);
}
function listover(obj){$(obj).addClass("cut");}
function listout(obj){$(obj).removeClass("cut");}
function showpins(objid,xmu,xsu,obj){
	$("#tiplist a").removeClass("selected");
	$(obj).addClass("selected");
	if(!tipsobj[xmu])tipsobj[xmu]=new Object();
	if(tipsobj[xmu][xsu]){$("#"+objid).html(tipsobj[xmu][xsu]);}
	else{
	$.xslt({xmlUrl:"xml/"+xmu+".xml",xslUrl:"xsl/"+xsu+".xsl",callback:function(v){
		tipsobj[xmu][xsu]=v;
		$("#"+objid).html(tipsobj[xmu][xsu]);
		}
	});
	}
}