function Table(id)
{
this.id=id;
this.data=eval('data'+this.id); //数据对象
this.length=this.data.length; //总长度
this.listNum=30; //每页的条数
this.f=0;
this.l=this.length;
if (this.nowTab()) {this.f=this._;}
if (this.f+this.listNum<this.length){this.l=this.f+this.listNum};
}//表格的属性



Table.prototype=
{
init:function(){
$('.sort').mouseover(function(){$(this).css('background-color','#fffff0')});
$('.sort').mouseout(function(){$(this).css('background-color','#f0f2e9')});
this.creat();
},//初始化


nowTab:function(){
if (location.hash.length > 1){
var _tab=location.hash.substr(1).split(":");
this._=parseInt(_tab[0],10);
if (_tab[1]){
	if (_tab[1]==this.id){return true;}else{return false;}
}else
{	return true;}
}else{
return false;
}
},//当前Tab


creat:function(){
$('#table'+this.id+' .tList').html(Table.templates(this));
if (this.nowTab()) {this.tabUrl();}
this.createPageBar();
},//建立

firstPage:function(){
this.f=0;
var _p=this.f+this.listNum;
if (_p<this.length){this.l=_p}else{this.l=this.length};
this.creat();
},//第一页

previousPage:function(){
var _p=this.f-this.listNum;
if (_p>=0){this.f=_p;};
_p=this.f+this.listNum;
if (_p<this.length){this.l=_p}else{this.l=this.length};
this.tabUrl();
this.creat();
},//向前翻

nextPage:function()
{
var _p=this.f+this.listNum;
if (_p<this.length){this.f=_p;}
_p=this.f+this.listNum;
if (_p<this.length){this.l=_p}else{this.l=this.length};
this.tabUrl();
this.creat();
},//向后翻

lastPage:function(){
this.f=Math.floor(this.length/this.listNum)*this.listNum;
var _p=this.f+this.listNum;

if (_p<this.length){this.l=_p}else{this.l=this.length};
this.creat();
},//最后一页


tabUrl:function()
{
var _url='#'+this.f+':'+this.id;
$($('#dbTab a').get(this.id)).attr("href",_url);
location.replace(_url);
},//写 当前页和当前Tab;


createPageBar:function(){
var _this=this;
var _t='#table'+this.id+' .pages';
var _bar = ' <span>' + (this.f + 1) + ' - ' + this.l + ' of ' + this.length + '</span> ';
var _ft='« 第一页';
var _f ='<a href="javascript:;" class="firs">'+_ft+'</a>';
var _pt='‹ 上一页 ';
var _p ='<a href="javascript:;" class="prev">'+_pt+'</a>';
var _nt='下一页 › ';
var _n ='<a href="javascript:;" class="next">'+_nt+'</a>';
var _lt='最后页 » ';
var _l ='<a href="javascript:;" class="last">'+_lt+'</a>';
var _str='';
if (this.l<this.length)
{
_str= " "+ _bar +" " + _n  +" ";
	if (this.f==0){	_str=" "+ _pt  + _str +" ";}else{	_str=" "+ _p  + _str  +" ";}
	}
	else
	{
	_str= " "+ _p + " "+ _bar +" " + _nt  +" ";
	}
$(_t).html(_str);
//$('.firs',$(_t)).bind('click',function(){_this.firstPage();});
$('.prev',$(_t)).bind('click',function(){_this.previousPage();});
$('.next',$(_t)).bind('click',function(){_this.nextPage();});
//$('.last',$(_t)).bind('click',function(){_this.lastPage();});
}//建立页码

}//表格的方法

function creatTable(str){
var _x=str.split(",");
var e='';
for(i=0;i<_x.length;i++){
x=parseInt(_x[i],10)
e +=('d'+x+'=new Table('+x+');d'+x+'.init();');
}
eval(e);
}

function sTab(x,y,id,_this)
{
var _data=eval("data"+id);
if (_this.className=='asc')
{
	if (y)
	{
	_data.sort(function(a,b){
		ax=(a[x]==null)?0:a[x]-0; 
		bx=(b[x]==null)?0:b[x]-0;
		return 	bx-ax;
			});
	}
	else
	{
	_data.sort(function(a,b){return b[x].localeCompare(a[x]);});
	}
_this.className='desc';
}
else
{
	if (y)
	{
	_data.sort(function(a,b){
		ax=(a[x]==null)?0:a[x]-0; 
		bx=(b[x]==null)?0:b[x]-0;
		return 	ax-bx;
		});
	}
	else
	{
	_data.sort(function(a,b){return a[x].localeCompare(b[x]);});
	}
_this.className='asc';
}
eval ('d'+id+'.creat()');
}

function tabShow(num){

if (num<0){num = $('#dbTab li')[0].id;}

$('#dbTab li').each(function(){ $(this).removeClass() });

$('#'+num).addClass('selected');

//$($('#dbTab li').get(num)).addClass('selected');

$('.dbTable').each(function(){ $(this).css("display","none") });

$('#table'+num).css("display","block");




}


function init(){
if (location.hash.length > 1){
var _tab=location.hash.substr(1).split(":");

if (_tab[1])
{
tabShow(_tab[1]);
}
else
{
tabShow(-1);
}
}
else
{
tabShow(-1);
}
}

$(function() {

$('#dbTab li').click( function (){ var _num= this.id; tabShow(_num);});

init();

});


//tips

function ge(z){return document.getElementById(z)}
function gE(z,y){return z.getElementsByTagName(y)}
function ce(z){return document.createElement(z)}
function de(z){z.parentNode.removeChild(z)}
function ct(z){return document.createTextNode(z)}
function rf(){return false}
function tb(){this.blur()}
function ac(z){var a=0,b=0;while(z){a+=z.offsetLeft;b+=z.offsetTop;z=z.offsetParent} return [a,b]}

var Browser = {
	ie:     !!(window.attachEvent && !window.opera),
	opera:  !!window.opera,
	safari: navigator.userAgent.indexOf('Safari') != -1,
	gecko:  navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('KHTML') == -1
};
Browser.ie6 = Browser.ie && navigator.userAgent.indexOf('MSIE 6.0') != -1;
navigator.userAgent.match(/Gecko\/([0-9]+)/);
Browser.geckoVersion = parseInt(RegExp.$1) | 0;

/////////////////////////////////////////////////
var Get={
windowSize:function()
{
	var width = 0, height = 0;
	if(typeof window.innerWidth == 'number') //Non-IE
	{
		width = window.innerWidth;
		height = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
  	{
		//IE 6+ in 'standards compliant mode'
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	}
 	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	return {w:width, h:height};
}
,

scroll:function()
{
	var x = 0, y = 0;
	if(typeof(window.pageYOffset) == 'number')
	{
		//Netscape compliant
		x = window.pageXOffset;
		y = window.pageYOffset;
	}
	else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
	{
		//DOM compliant
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		//IE6 standards compliant mode
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	return {x:x, y:y};
}
}




//////////////////////////////////////////////////////////
var Tooltip = {
	create: function(htmlTooltip)
	{
		var d = ce('div'), t = ce('table'), tb = ce('tbody'), tr = ce('tr'),  td = ce('td');
		d.className = 'tooltip';
		//th1.style.backgroundPosition = 'top right';
		//th2.style.backgroundPosition = 'bottom left';
		//th3.style.backgroundPosition = 'bottom right';

_html='<div class="b0 lt"><div class="b0 rt"><div class="bw0 tw"></div></div></div><div class="bh0 lh"><div class="bh0 rh"><div class="bm0" id="text"></div></div></div><div class="b0 lb"><div class="b0 rb"><div class="bw0 bw"></div></div></div>';
td.innerHTML=_html;

		if(htmlTooltip)
		ge("text").innerHTML = htmlTooltip;
		//td.id="text";
		tr.appendChild(td);
		//tr1.appendChild(th1);
		tb.appendChild(tr);
		//tr2.appendChild(th2);
		//tr2.appendChild(th3);
		//tb.appendChild(tr2);
		t.appendChild(tb);
		d.appendChild(t);
		return d;
	},

	fix: function(tooltip, noShrink, visible)
	{
	/*	var table = gE(tooltip, 'table')[0],
		    td = gE(table, 'td')[0],
		    c = td.childNodes;
		if(c.length >= 2 && c[0].nodeName == 'TABLE' && c[1].nodeName == 'TABLE')
		{
			
			var m;
			if(c[1].offsetWidth > 300)
				m = Math.max(300, c[0].offsetWidth) + 20;
			else
				m = Math.max(c[0].offsetWidth, c[1].offsetWidth) + 20;
			if(m > 20)
			{
				tooltip.style.width = m + 'px';
				c[0].style.width = c[1].style.width = '100%';

				if(!noShrink && tooltip.offsetHeight > document.body.clientHeight)
					table.className = 'shrink';
			}
		}
		*/
		if(visible)
			tooltip.style.visibility = 'visible';
	},

	fixSafe: function(p1, p2, p3)
	{
		if(Browser.ie)
			setTimeout(Tooltip.fix.bind(this, p1, p2, p3), 1);
		else
			Tooltip.fix(p1, p2, p3);
	},

	append: function(el, htmlTooltip)
	{
		var el = $(el);
		var tooltip = Tooltip.create(htmlTooltip);
		el.appendChild(tooltip);

		Tooltip.fixSafe(tooltip, 1, 1);
	},

	move: function(_this, tooltip, x, y, tow, toh, clip)
	{
		var _,
		    c = ac(_this),
		    left = c[0],
		    top  = c[1],
		    minx = 0,
		    miny = 0,
		    w1   = _this.offsetWidth  + x,
		    h1   = _this.offsetHeight + y,
		    windowSize = Get.windowSize(),
		    scroll = Get.scroll(),
		    bcw = windowSize.w,
		    bch = windowSize.h,
		    bsl = scroll.x,
		    bst = scroll.y;


		tooltip.style.width = tow + 'px';
		if(clip)
		{
			_ = ge(clip);
			if(_)
			{
				c = ac(_);
				minx = c[0];
				miny = c[1];

				if(_.offsetWidth + minx <= bsl + bcw)
					bcw = _.offsetWidth  + minx - bsl;

				if(_.offsetHeight + miny <= bst + bch)
					bch = _.offsetHeight + miny - bst;
			}
		}
		if(left + w1 + tow > bcw)
			left = Math.max(left - tow - x, minx);
		else
			left += w1;

		if(left < minx)
			left = minx;
		else if(left + tow > bsl + bcw)
			left = bsl + bcw - tow;

		if(top - toh - y > Math.max(bst, miny))
			top = top - toh - y;
		else
			top += h1;

		if(top < miny)
			top = miny;
		else if(top + toh > bst + bch)
			top = Math.max(bst, bst + bch - toh);
		tooltip.style.left = left + 'px';
		tooltip.style.top  = top  + 'px';
		tooltip.style.visibility = 'visible';
	},

	show: function(_this, text, x, y,spanClass)
	{
		var _;
		if(!Tooltip.tooltip)
		{
			_ = Tooltip.create();
			_.style.position = 'absolute';
			_.style.left = _.style.top = '-2323px';

			var lay = ge('layers');
			lay.appendChild(_);

			Tooltip.tooltip      = _;
			Tooltip.tooltipTable = gE(_, 'table')[0];
			Tooltip.tooltipTd    = gE(_, 'td')[0];
		}

		if(spanClass) text = '<span class="' + spanClass + '">' + text + '</span>';
		_ = Tooltip.tooltip;
		_.style.width = '500px';
		_.style.left = '-2323px';
		_.style.top  = '-2323px';




ge("text").innerHTML=text;

//		Tooltip.tooltipTd.innerHTML = _text;


		_.style.display = '';
		Tooltip.fix(_, 0, 0);
		Tooltip.move(_this, _, x, y, Tooltip.tooltipTable.offsetWidth, Tooltip.tooltipTable.offsetHeight, 'fixTooltip');
	},

	hide: function()
	{
		if(Tooltip.tooltip)
		{
			Tooltip.tooltip.style.display = 'none';
			Tooltip.tooltip.visibility = 'hidden';
			Tooltip.tooltipTable.className = '';
		}
	}
};
/////////////////////////////////////////

//nav

navHover = function() {
	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);




var Map=
{

	create:function(_zonename,_zone,_coords)
	{

_id="zone";

	ge(_id).style.background="url(http://db.duowan.com/wow/map/"+_zone+".jpg)";

	var html=[];
	var len=_coords.length;
	for (i=0;i<len;i++)
	{
html.push('<span class="p" style="top:'+_coords[i][1]+'%;left:'+_coords[i][0]+'%;" id="'+_coords[i][0]+' , '+_coords[i][1]+'" onmouseover="Map.show(this);"></span>');
	}

html.push('<span style="position: absolute; top:5px;left:5px;" class="glow">地图: '+_zonename+'<br/>');
if (_coords[0][0] >= 0)
{
html.push('坐标: <span id="coordinates">'+_coords[0][0]+' , '+_coords[0][1]+'</span>');
}
html.push('</span>');

	ge(_id).innerHTML=html.join("");

	ge('dbSubTitle').innerHTML =_zonename;


	},

	show:function(_this)
	{
	ge("coordinates").innerHTML=_this.id;
	}

}

function getFaction (x,y)
{
eval ("_x=["+x+","+y+"]");
var AH=["联盟","部落"];
var s="";
var c=0;
for(var k=0;k<2;++k)
{

	if(_x[k]!=null) 
	{

		s+=" "; 

		s+="<span class=\"q";

		if(_x[k]==-1) {s+="7";} else { if(_x[k]==1) s+="2";}

		s+="\">"+AH[k]+"</span>";

	}
}
return s;
}

/////////////////////////////////////////

var Icon = {
	sizes: ['s', 'm', 'l'],
	set:function (_e,_ar)
	{
		ge(_e).appendChild(Icon.create(_ar[0],_ar[1],_ar[2],_ar[3],_ar[4],_ar[5]));
	},
	create: function(image, size, tooltip, link, num, qty)
	{
		var _;
		var icon = ce('div'), tile = ce('div'), hover = ce('div');

		icon.className = 'icon' + Icon.sizes[size];
		if(image != null)
			icon.style.backgroundImage = 'url(icon/' + Icon.sizes[size] + '/' + image + '.jpg)';

		tile.className = 'tile';
		hover.className = 'hover';

		if(tooltip)
		{

			hover.id = (tooltip).length ? tooltip : null;

			if (! hover.id)
			{
				hover.onmouseover = Icon.over;
				hover.onmouseout  = Icon.out;
			}

		}

		if(typeof(link) == 'string')
		{
			var a = ce('a');
			a.href = link;
			hover.appendChild(a);
		}

		else if(size == 2)
		{
			hover.ondblclick = function() { prompt('', image) };
		}

		if(num != null && (num > 1 || num.length))
		{
			_ = g_createGlow(num, 'q1');
			_.style.right = '0';
			_.style.bottom = '0';
			_.style.position = 'absolute';
			tile.appendChild(_);
		}

		if(qty != null && qty > 0)
		{
			_ = g_createGlow('(' + qty + ')', 'q');
			_.style.left = '0';
			_.style.top = '0';
			_.style.position = 'absolute';
			tile.appendChild(_);
		}

		tile.appendChild(hover);
		icon.appendChild(tile);

		return icon;
	},

	over: function()
	{
		if(!Icon.hilite)
		{
			var _ = ce('div');
			_.className = 'hilite';
			Icon.hilite = _;
		}
	
		this.parentNode.insertBefore(Icon.hilite, this.parentNode.lastChild.nextSibling);
		Icon.hilite.style.display = '';

		if(this.id != null)
		{
			//alert (this.id);
			Tooltip.show(this, this.id, 0, 0);
		}
	},

	out: function()
	{
		if(Icon.hilite)
			Icon.hilite.style.display = 'none';
		Tooltip.hide();
	}
};

/////////////////////////////////////////
var subtype_=[["","--  无子分类  --"]];
var subtype_1=[["","--  所有武器  --"],[1,"长剑"],[2,"匕首"],[4,"手杖"],[5,"步枪"],[6,"手枪"],[7,"弯刀"],[8,"西洋剑"],[9,"法杖"],[10,"长柄武器"],[11,"双手剑"],[12,"火焰手镯"],[13,"冰寒手镯"],[14,"雷电手镯"],[15,"手镯"],[16,"拳套"],[17,"护腿"],[18,"左手短剑"],[19,"霰弹枪"],[20,"火炮"],[21,"战锤"],[22,"梭镖"],[23,"枪刺"],[24,"斧子"],[25,"锤子"],[26,"控制器"]];
var subtype_2=[["","--  所有防具  --"],[3,"盾牌"],[30,"皮甲"],[31,"金属甲"],[32,"长袍"],[33,"法袍"],[34,"靴子"],[35,"护手"]];
var subtype_3=[["","--  所有首饰  --"],[50,"项链"],[51,"戒指"]];
var subtype_4=[["","--  其他物品  --"],[70,"医疗"],[71,"料理"],[72,"即时道具"],[73,"弹药"],[74,"材料"],[75,"矿物"],[76,"训练书"],[77,"制造卷轴"]];

var skills_=[["","--  无子分类  --"]];
var skills_1=[["","--  ----  --"],[1,"自由搏击"],[5,"疾风腿法"],[9,"自然拳法"],[14,"攻防平衡"],[19,"强化守备"],[24,"长剑双持"],[29,"长剑守备"],[34,"战锤守备"],[39,"击剑刺击"],[44,"击剑横扫"],[49,"击剑双持"],[54,"弯刀劈砍"],[58,"军刀双持"],[62,"巨剑守备"],[67,"拖剑劈砍"],[72,"扛剑劈砍"],[76,"巨剑之怒"],[80,"长斧守备"],[84,"挺枪守备"],[88,"梭镖守备"],[93,"单手持匕"],[99,"匕首双持"]];
var skills_2=[["","--  ----  --"],[104,"瞄准射击"],[109,"单手射击"],[113,"双枪射击"],[118,"普通站姿射击"],[124,"普通跪姿射击"],[128,"火枪守备"],[134,"霰弹射击"],[138,"狩猎射击"],[144,"火炮发射"],[148,"火炮轰袭"],[153,"精确站姿射击"],[159,"精确跪姿射击"],[164,"刺杀射击"]];
var skills_3=[["","--  ----  --"],[169,"精神力"],[174,"祈祷"],[179,"幻术"],[184,"悬浮术"],[188,"神之庇护"],[193,"恶魔的微笑"],[198,"火焰操控"],[202,"火焰召唤"],[206,"火焰驾御"],[211,"冰霜操控"],[216,"冰霜召唤"],[220,"冰霜驾御"],[225,"雷电操控"],[230,"雷电召唤"],[234,"雷电驾御"],[239,"元素召唤"]];
var skills_4=[["","--  ----  --"],[244,"冰霜刺剑"],[250,"冰晶疾刺"],[255,"战神之舞"],[260,"天堂地狱"],[266,"烈焰守备"]];
var skills_5=[["","--  ----  --"],[272,"急救"],[277,"祝福"],[282,"埋设"],[287,"架设"],[293,"工兵战技"],[299,"人偶操控"]];
