﻿icon_24="http://wowimg.the9.com/images_wow/icons/24x24/";
icon_43="http://wowimg.the9.com/images_wow/icons/43x43/";
strdropRate=new Array("无","稀有","非常低","低","中","高","必定掉落");
xmlpatch="xml/";
strquality=new Array("grey","white","green","blue","purple","orange");
	$(document).ready(function(){
	getcss(getvalue("difficulty"));
	$("a#"+(getvalue("difficulty")==""?"normal":getvalue("difficulty"))+",#btn-tab a#btn-"+(getvalue("tag")==""?"all":getvalue("tag"))).addClass("cut");
	tab(getvalue("tag"));
	$("#btn-tab a,a#normal,a#hero").click(function(){$(this).siblings().removeClass("cut");$(this).addClass("cut");return false;});
	$("#boss a#normal,#boss a#hero").click(function(){
	getcss($(this).attr("id"));
	createTable($(this).attr("id"),getvalue("tag"));
	self.location.href=getlink("difficulty="+$(this).attr("href").substr(($(this).attr("href").indexOf("#")+1),$(this).attr("href").length));
			});
	$("#btn-tab a").click(function(){
		_d=$(this).attr("href");
		_d=_d.substr((_d.indexOf("#")+1),_d.length);
		createTable(getvalue("difficulty"),_d);
		tab(_d);
		self.location.href=getlink("tag="+_d);
		});
	$('a').focus(function(){$(this).blur();});
	importXML(xmlpatch+"d_"+dungeonid+".xml","GetObj");
	$("table.list tr.title td").mouseover(function(){$(this).addClass("cut");});
	$("table.list tr.title td").mouseout(function(){$(this).removeClass("cut");});
	});
function importXML(url,fun)
{
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = eval(fun);
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if(xmlDoc.readyState == 4)eval(fun+"()");
		};
 	}
	else
	{
		return;
	}
	xmlDoc.load(url);
}
function GetObj()
{
	xmlObj=xmlDoc.getElementsByTagName('boss');
	createTable(getvalue("difficulty"));
}
function createTable(d_type,d_tag,d_sort){
if(((d_tag==undefined)&&(getvalue("tag")=="boss"))||(d_tag=="boss"))d_tag="boss";
else d_tag="";
cid="c"+((d_type==null||d_type==""||d_type=="normal")?"-normal":"-hero")+((d_tag==null||d_tag=="")?"":"-"+d_tag)+((d_sort==null||d_sort=="")?"":"-"+d_sort);
d=new Array();
str_d="";
if(!document.getElementById(cid)){
	c="<div id='"+cid+"' class='table-list' style='display:none;'>";	
		for(i=0;i<xmlObj.length;i++){
			if(xmlObj[i].getElementsByTagName('object').length){obj=xmlObj[i].getElementsByTagName('object')[0];_dorp="宝箱掉落"}
				else {obj=xmlObj[i];_dorp="首领掉落"}
			if(d_type=="hero")_blv=xmlObj[i].getAttribute("herolv");
				else _blv=xmlObj[i].getAttribute("normallv");
			num=obj.getElementsByTagName('item').length;
			s="<div class='boss-hd'><div class='right'><div class='boss-dorp'>"+_dorp+"</div><span><p>位置:"+xmlDoc.getElementsByTagName('dungeon')[0].getAttribute("name")+"</p></span><span><p>等级:"+_blv+"</p></span></div><div class='left'><img src='http://wowimg.the9.com/images_wow/info/instance/icon_boss_"+xmlObj[i].getAttribute("id")+".png' class='png' /><span>"+xmlObj[i].getAttribute("name")+"</span></div></div>";
			n=0;
			if(num>0){
				if(d_tag=="boss")
				{s+="<table width='100%' border='0' cellspacing='0' cellpadding='0' class='tablesorter bt'><thead><tr><th>物品名称</th><th>物品等级</th><th>物品种类</th><th>掉落率</th></tr></thead><tbody>";
				for(j=0;j<num;j++){
				if(d_type=="hero"||(obj.getElementsByTagName('item')[j].getAttribute("difficulty")!="h")){
					row=n%2==0?"row":"rew";
					v_img=obj.getElementsByTagName('item')[j].getAttribute("icon");
					v_id=obj.getElementsByTagName('item')[j].getAttribute("id");
					v_name=obj.getElementsByTagName('item')[j].childNodes[0].nodeValue;
					v_lv=obj.getElementsByTagName('item')[j].getAttribute("level");
					v_type=obj.getElementsByTagName('item')[j].getAttribute('type');
					v_quality=strquality[eval(obj.getElementsByTagName('item')[j].getAttribute("quality"))];
					v_dropRate=obj.getElementsByTagName('item')[j].getAttribute("dropRate")==null?"未知":strdropRate[eval(obj.getElementsByTagName('item')[j].getAttribute("dropRate"))];
					v_hero=obj.getElementsByTagName('item')[j].getAttribute("difficulty")=="h"?"<span class='hero' title='英雄副本专有掉落'></span>":"";
					s+="<tr class='row'><td class='name'><div class='icon'>"+v_hero+"<img src='"+icon_43+v_img+".png' class='png' onmouseout='hideTip();' onmouseover='loadTooltip("+v_id+")' /></div><span><div class='"+v_quality+"'><div class='tl'>"+v_name+"</div><div class='l'>"+v_name+"</div><div class='fl'>"+v_name+"</div><div class='f'>"+v_name+"</div><div class='ct'><a href='#item="+v_id+"' onmouseout='hideTip();' onmouseover='loadTooltip("+v_id+")' onclick='return false'>"+v_name+"</a></div><div class='t'>"+v_name+"</div><div class='fr'>"+v_name+"</div><div class='r'>"+v_name+"</div><div class='tr'>"+v_name+"</div></span></td><td class='lv'>物品等级:"+v_lv+"</td><td class='type'>"+v_type+"</td><td class='dropRate'>掉落率:"+v_dropRate+"</td></tr>";
					n++;
				}}
			}
				else{
					s+="<table width='100%' border='0' cellspacing='0' cellpadding='0' class='list bt'>";
				for(j=0;j<num;j++){
				if(d_type=="hero"||(obj.getElementsByTagName('item')[j].getAttribute("difficulty")!="h")){
					row=n%4==0?"row":"rew";
					if(n%2==0){s+="<tr class='"+row+"'>";etr="";}
						else{etr="</tr>";}
					v_img=obj.getElementsByTagName('item')[j].getAttribute("icon");
					v_id=obj.getElementsByTagName('item')[j].getAttribute("id");
					v_name=obj.getElementsByTagName('item')[j].childNodes[0].nodeValue;
					v_lv=obj.getElementsByTagName('item')[j].getAttribute("level");
					v_type=obj.getElementsByTagName('item')[j].getAttribute('type');
					v_quality=strquality[eval(obj.getElementsByTagName('item')[j].getAttribute("quality"))];
					v_dropRate=obj.getElementsByTagName('item')[j].getAttribute("dropRate")==null?"未知":strdropRate[eval(obj.getElementsByTagName('item')[j].getAttribute("dropRate"))];
					v_hero=obj.getElementsByTagName('item')[j].getAttribute("difficulty")=="h"?"<span class='hero' title='英雄副本专有掉落'></span>":"";
					s+="<td><span class='icon'>"+v_hero+"<img src='"+icon_24+v_img+".png' class='png' onmouseout='hideTip();' onmouseover='loadTooltip("+v_id+")' /></span><span class='name'><div class='"+v_quality+"'><div class='tl'>"+v_name+"</div><div class='l'>"+v_name+"</div><div class='fl'>"+v_name+"</div><div class='f'>"+v_name+"</div><div class='ct'><a href='#item="+v_id+"' onmouseout='hideTip();' onmouseover='loadTooltip("+v_id+")' onclick='return false'>"+v_name+"</a></div><div class='t'>"+v_name+"</div><div class='fr'>"+v_name+"</div><div class='r'>"+v_name+"</div><div class='tr'>"+v_name+"</div></div></span><span class='lv'>物品等级:"+v_lv+"</span><span class='type'>"+v_type+"</span><span class='dropRate'>掉落率:"+v_dropRate+"</span></td>";
					s+=etr;
					n++;
				}
				}
			etr=n%2==0?"":"<td></td></tr>";
			s+=etr;}
			}
			else s+="<tr class='row'><td>对不起,暂时没有可提供数据</td></tr>";
			if(d_tag=="boss")s+="</tbody></table>";
				else s+="</table>";
			d[eval(xmlObj[i].getAttribute("id"))]=s;
			}
for(i=0;i<$("div#boss h1").length;i++){
	tid=$("div#boss h1")[i].id;
	_tid=tid.split("-");
	str_d+="<div class='"+tid+"'>"+d[eval(_tid[eval(_tid.length-1)])]+"</div>";
}
c+=str_d+"</div>";
$("#boss-list").prepend(c);
$("#"+cid).show();
$("#"+cid).siblings(".table-list").hide();
if(d_tag=="boss")$.getScript("/include_wow/script/jquery.tablesorter.pack.js", function(){$("#"+cid+" .tablesorter").tablesorter();});
}
else{
	$("#"+cid).prependTo("#boss-list");
	$("#"+cid).show();
	$("#"+cid).siblings(".table-list").hide();
}
}
function getlink(p_){
_=location.href.indexOf('#');
if((_!= -1)&&(_!=location.href.length-1)){t_=location.href.substr(_+1,location.href.length);lh_=location.href.substr(0,_);}
else {t_="";lh_=location.href;}
	if(typeof(p_)!="undefined"){
		__=p_.split("&");
		r_=t_;
		for(i=0;i<__.length;i++){
			rr=__[i].split("=");
			if(r_.indexOf(rr[0])!=-1){
				re=new RegExp(rr[0]+"=[A-Za-z0-9_]+","ig");
				r_=r_.replace(re, __[i]);
			}
			else r_=r_==""?r_+__[i]:r_+"&"+__[i];
		}
	}
	r_=lh_+"#"+r_;
	return r_;
}
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="".split("&");
	return val[0];
}
function tab(id){
		if(id=="all"||id==""){
			for(_i=1;_i<$("#btn-tab a").length;_i++){
				_id=new String($("#btn-tab a")[_i]);
				_id=_id.substr((_id.indexOf("#")+1),_id.length);
				$("#conter-main").children("#"+_id).appendTo("#conter-main");
				$("#conter-main").children().show();
			}}
		else{$("#conter-main").children("#"+id).prependTo("#conter-main");$("#conter-main").children("#"+id).show();$("#conter-main").children("#"+id).siblings().hide();}
}
function getcss(t){
	if(t){
	var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {a.disabled = true;
			if(a.getAttribute("title") == t)a.disabled = false;}
			}
}}
