// Copyright (c) WoW-Space.info 2008-2010
vers = {243:'2.4.3',309:'3.0.9',310:'3.1.3',320:'3.2.2',330:'3.3.3',400:'4.0.0',403:'4.0.3',406:'4.0.6',410:'4.1.0',420:'4.2.0'};

for (var i in vers) { } vers.last = ver = i;
var a = new Array(); var b = new Array(); var c = new Array(); var drz = new Array(); var buildy = new Array();
var allsuma=0, abcl, link=false, tre='1', all, allsumap, ppoint, xmax, tag, tag2, speclimit=0, resetted=false, drze, lastd=1, klasa, spec;

function X(obj) {
 var x = obj.offsetLeft;
 while (obj = obj.offsetParent) { x += obj.offsetLeft; }
 return x;
} function Y(obj) {
 var y = obj.offsetTop;
 while (obj = obj.offsetParent) { y += obj.offsetTop; }
 return y;
} function isset(variable) {
 return(typeof(variable) != 'undefined');
} function act(idek,activ,niee) { // activ: 0=off, 1=act, 2=actt
	if (!activ) { activ=1; }
	img = document.getElementById(drze+'i'+idek);
	imga = img.style.backgroundPosition.split(" ");
	img.style.backgroundPosition = imga[0] + ((activ!=3)?' 0px':' -36px');
	img = document.getElementById(drze+idek);
	imga = img.className.split(" ");
	switch (activ) {
		case 3: img.className = imga[0]; if(!niee){drz[idek].active=false;} break;
		case 1: img.className = imga[0]+' act'; if (!niee){drz[idek].active=true;} break;
		case 2: img.className = imga[0]+' act actt'; break;
	}
} stfind = function(numer, tab) {
	numer = parseInt(numer,10);
	if (!tab) { var tab = drz.str; }
	var returnArray = false;
	for (var i in tab) {
		if (tab[i].a==numer) {
			if (!returnArray) { returnArray = new Array; }
			returnArray.push(tab[i].b);
		}
	}
	return returnArray;
}; strfind = function(numer, tab) {
	numer = parseInt(numer,10);
	if (!tab) { var tab = drz.str; }
	var returnArray = false;
	for (var i in tab) {
		if (tab[i].b==numer) {
			if (!returnArray) { returnArray = new Array; }
			returnArray.push(tab[i].a);
		}
	}
	return returnArray;
};
function tree(dzywo) {
	switch (dzywo) {
		case 1: case '1': case 'a': drz = a; drze = 'a'; drzi = 1; break;
		case 2: case '2': case 'b': drz = b; drze = 'b'; drzi = 2; break;
		case 3: case '3': case 'c': drz = c; drze = 'c'; drzi = 3; break;
	}
} function klasaid(tklasa) {
	switch (tklasa) {
		case 'deathknight': return 0;
		case 'druid': return 1;
		case 'hunter': return 2;
		case 'mage': return 3;
		case 'paladin': return 4;
		case 'priest': return 5;
		case 'rogue': return 6;
		case 'shaman': return 7;
		case 'warlock': return 8;
		case 'warrior': return 9;
		case 'pet': return 10;
	}
} function klasan(tklasa) {
	switch (tklasa) {
		case 0: return 'deathknight';
		case 1: return 'druid';
		case 2: return 'hunter';
		case 3: return 'mage';
		case 4: return 'paladin';
		case 5: return 'priest';
		case 6: return 'rogue';
		case 7: return 'shaman';
		case 8: return 'warlock';
		case 9: return 'warrior';
		case 10: return 'pet';
	}
}
function showUp(d) {
	tree(lastd);
	document.getElementById(drze+'tab').className='tab';
	document.getElementById(drze+'w').style.display = '';
	tree(d);
	document.getElementById(drze+'tab').className='tab act';
	document.getElementById(drze+'w').style.display = 'block';
	lastd = d;
}
function changexmax(drzxxmax) {
	xmax = drzxxmax;
	if (tag2) { tag2.parentNode.removeChild(tag2); }
	tag2 = document.createElement("style");
	tag2.setAttribute("type", "text/css");
	csstxt = '<style>div.t-window {height:'+((xmax*64)+74)+'px!important;}div.t-middle{height:'+((xmax*64)+10)+'px!important;}div.t-bottom{top:'+((xmax*64)+66)+'px!important;}div.t-wline5{top:'+((xmax*64)+72)+'px!important;}div.t-tabb{top:'+((xmax*64)+98)+'px!important;}table.talents{height:'+((xmax*64)+6)+'px!important;}div.t-left, div.t-right{height:'+((xmax*64)+2)+'px!important;}</style>';
	if (tag2.styleSheet) {   // IE
		tag2.styleSheet.cssText = csstxt;
	} else {                // the world
		var tt1 = document.createTextNode(csstxt);
		tag2.appendChild(tt1);
	}
	var hh1 = document.getElementsByTagName('head')[0];
	hh1.appendChild(tag2);
}

function wybierzklase() {
	document.getElementById('talents').style.display="none";
}

function showspec(pokazac) {
	if (pokazac) {
		document.getElementById('at').style.display="none";
		document.getElementById('bt').style.display="none";
		document.getElementById('ct').style.display="none";
		document.getElementById('aspec').style.display="block";
		document.getElementById('bspec').style.display="block";
		document.getElementById('cspec').style.display="block";
		document.getElementById('showspec').innerHTML="Pokaż talenty";
		document.getElementById('showspec').onmouseup=function(){showspec(0);};
	} else {
		document.getElementById('at').style.display="block";
		document.getElementById('bt').style.display="block";
		document.getElementById('ct').style.display="block";
		document.getElementById('aspec').style.display="none";
		document.getElementById('bspec').style.display="none";
		document.getElementById('cspec').style.display="none";
		document.getElementById('showspec').innerHTML="Wyświetl podsumowanie";
		document.getElementById('showspec').onmouseup=function(){showspec(1);};
	}
}

function zrobspec() {
	for (var d=1;d<4;d++) {
		tree(d);
		if (!drz.color) { drz.color='red'; }
		document.getElementById(drze+'w').className='t-window '+drz.color;
		all = '<a class="button" onmouseup="zmienspec('+d+')">'+drz.name+'</a>';
		all += '<div class="tspec" onmouseup="zmienspec('+d+')" style="background-image: url(../../img/talent/'+klasa+'.gif); background-position:-'+(56*(d-1))+'px 0px"><div class="tspec-icon"></div>';
		for (var j in drz.role) {
			if (drz.role[j] == '1') { all += '<div class="tspec-role role'+j+' dps"></div>'; }
			if (drz.role[j] == '2') { all += '<div class="tspec-role role'+j+' tank"></div>'; }
			if (drz.role[j] == '3') { all += '<div class="tspec-role role'+j+' healer"></div>'; }
		}
		all += '</div>';
		j = 90;
		while (drz[j]) {
			all += '<div class="specline'+((j==90)?' main':'')+'">';
			all += '<div id="'+drze+j+'" class="talent spec">';
			all += '<div class="tlo"></div>';
			if (j==90) { all += '<div id="'+drze+'b'+j+'" class="ramka"></div>'; }
			all += '<div oncontextmenu="return false" onmouseout="swiatloOff(\''+j+'\',\''+drze+'\')"  onmouseover="swiatloOn(event,\''+j+'\',\''+drze+'\')">';
			if (drz[j].img==99) {
				all += '<div id="'+drze+'i'+j+'" class="icon" style="background-image: url(../../img/talent/mastery.gif); background-position:0px 0px"></div>';
			} else {
				all += '<div id="'+drze+'i'+j+'" class="icon" style="background-image: url(../../img/talent/'+ver+'/'+klasa+'_'+d+'.jpg); background-position:-'+(drz[j].img*36)+'px 0px"></div>';
			}
			all += '<div id="'+drze+'n'+j+'"  class="swiatlo"></div>';
			all += '</div></div>';
			all += '<a onmouseout="swiatloOff(\''+j+'\',\''+drze+'\')"  onmouseover="swiatloOn(event,\''+j+'\',\''+drze+'\')">'+drz[j].name+'</a>';
			all += '</div>';
			j++;
		}
		if (drz.opis) { all += '<span>'+drz.opis+'</span>'; }
		all += '</div>';
		document.getElementById(drze+'spec').innerHTML=all;
	}
}

function taload(maszdane, tklasa, tspec, tver, tabcl) {
	if (maszdane==true) {
		klasa = tklasa;
		spec = tspec;
		if (tver!=null) { ver = tver; }
		if (tabcl == null) { tabcl="||"; }
		abcl = tabcl;
		tabcl = abcl.split('|');
		if (abcl!="||") { link=true; }
	} else {
		uri = window.location.hash.slice(1);
		if (uri!="") { // jest #
			uril = uri.split('|');
			if (uril[0][0] != 'c' && uril[0]!=null) { // comments lub nie #klasa|1|ver|a|b|c
				klasa = uril[0];
				img = document.getElementById('tal-kl'+klasaid(klasa));
				if (img!=null) { imga = img.style.backgroundPosition.split(" ");
				img.style.backgroundPosition = imga[0] + ' 0px'; }
				spec = parseInt(uril[1],10); if (spec==null) { spec=0; }
				ver = uril[2]; if (ver==null) { ver=vers.last; }
				abcl = uril[3]+'|'+uril[4]+'|'+uril[5];
				if (abcl!="||"&&abcl!="undefined|undefined|undefined") { link=true; }
				abcl += '|'+uril[1];
			} else { return wybierzklase(); }
		} else { return wybierzklase(); }
	}
	loadver(ver);
	var all = '';
	for (var i in vers) {
		if (i != 'last' && !(i=='243' && klasa=='deathknight')) {
			all += '<option value="'+i+'"'+((ver==i)?' selected="selected"':'')+'>Wersja kalkulatora talentów: '+vers[i]+'</option>';
		}
	} document.getElementById('wersje').innerHTML = all;
}

function zmienklase(tklasa) {
	img = document.getElementById('tal-kl'+klasaid(klasa));
	if (img==null) {
		document.getElementById('talents').style.display="block";
	} else {
		imga = img.style.backgroundPosition.split(" ");
		img.style.backgroundPosition = imga[0] + ' -43px';
	}
	klasa = klasan(tklasa);
	if (klasa=='deathknight' && ver=='243') { ver = vers.last; }
	img = document.getElementById('tal-kl'+tklasa);
	imga = img.style.backgroundPosition.split(" ");
	img.style.backgroundPosition = imga[0] + ' 0px';
	taload(true, klasa, 0, ver);
}

function zmienspec(tspec,odrazu) {
	if (!odrazu && tspec!=spec) { reset(); }
	spec = tspec;
	if (!odrazu) { tree(spec); } 
	document.getElementById('spec').innerHTML = drz.name;
	window.location.hash='#'+klasa+'|'+spec+'|'+ver;
	blokuj(1,tspec);
	if (!odrazu) { showspec(0); } 
}

function loadver(ve) {
	if (!vers[ve]) { ve = vers.last; }
	ver = ve;
	
	speclimit=0;
	if (klasa == 'pet') {
		allsumap = ((bmtalent)?20:16); ppoint = 3; xmax = ((ver=='309')?5:6);
		document.getElementById('pet1').style.display = 'block';
		document.getElementById('pet2').className = 'right';
		speclimit = 100;
	} else {
		document.getElementById('pet1').style.display = 'none';
		document.getElementById('pet2').className = 'both';
		if (ver == '243') { ppoint = 5; xmax = 9; allsumap = (xmax * ppoint) + 16; 
		} else if (parseInt(ver,10) > 399) { ppoint = 5; xmax = 7; allsumap = 41; speclimit = (xmax-1)*5+1;
		} else { ppoint = 5; xmax = 11; allsumap = (xmax * ppoint) + 16; }
	}
	document.getElementById('pet2').style.display = ((!speclimit)?'none':'block');
	changexmax(xmax);

	if (ver == '243') { document.getElementById('tal-kl0').style.display="none";
	} else { document.getElementById('tal-kl0').style.display="block"; }
	
	if (tag) { tag.parentNode.removeChild(tag); }
	tag = document.createElement("script");
    tag.type="text/javascript";
    tag.src = '../img/talent/'+ver+'/'+klasa+'.js';
    document.getElementsByTagName('head')[0].appendChild(tag);
	document.getElementById('wersja').innerHTML = vers[ver];
}
function reset() {
	spec=0;
	for (var d=1;d<4;d++) {
		all = '';
		tree(d);
		all += '<table id="'+drze+'" class="talents" cellspacing="0" style="background: url(../img/talent/'+klasa+'_'+d+'.jpeg) no-repeat;">';
		i=0;
		for (x=0;x<xmax;x++) {
		all += '<tr>';
			for (y=0;y<4;y++) {
			all += '<td>';
			if (drz[i] && drz[i].ammo && drz[i].y==y && drz[i].x==x) {
				drz[i].value = 0;
				drz[i].active = ((x==0&&!strfind(i))?true:false);
				all += '<div id="'+drze+i+'" class="talent'+((drz[i].active)?' act':'')+'">';
				all += '<div class="tlo"></div>';
				all += '<div id="'+drze+'b'+i+'" class="ramka"></div>';
				all += '<div onMouseOver="swiatloOn(event,'+i+','+d+')" onMouseOut="swiatloOff('+i+','+d+')" onContextMenu="return false" onMouseUp="add(event, '+i+','+d+')">';
				if (drz[i].img==99) {
					all += '<div id="'+drze+'i'+i+'" class="icon" style="background-image: url(../../img/talent/mastery.gif); background-position:0px 0px"></div>';
				} else {
					all += '<div id="'+drze+'i'+i+'" class="icon" style="background-image: url(../../img/talent/'+ver+'/'+klasa+'_'+d+'.jpg); background-position:-'+(drz[i].img*36)+'px '+((drz[i].active)?'0px':'-36px')+'"></div>';
				}
				all += '<div id="'+drze+'n'+i+'" class="swiatlo"></div>';
				all += '</div>';
				all += '<div id="'+drze+'c'+i+'" class="cyfra">0</div>';
				if (strfind(i)) {
					if (drz[strfind(i)].x == x) {
						if (drz[strfind(i)].y < y) {
							all += '<div id="'+drze+'s'+i+'" class="right" style="width: '+(28+(y-drz[strfind(i)].y-1)*64)+'px; left: -'+(11+(y-drz[strfind(i)].y-1)*64)+'px;"></div>';
						} else {
							all += '<div id="'+drze+'s'+i+'" class="left" style="width: '+(29+(drz[strfind(i)].y-y-1)*64)+'px; left: '+(48+(drz[strfind(i)].y-y-1)*64)+'px;"></div>';
						}
					} else {
						if (drz[strfind(i)].y < y) {
							all += '<div id="'+drze+'s'+i+'" class="rightdown'+(x-drz[strfind(i)].x)+'""></div>';
						} else if (drz[strfind(i)].y > y) {
							all += '<div id="'+drze+'s'+i+'" class="leftdown'+(x-drz[strfind(i)].x)+'""></div>';
						} else {
							all += '<div id="'+drze+'s'+i+'" class="down" style="height: '+(28+(x-drz[strfind(i)].x-1)*64)+'px; top: -'+(12+(x-drz[strfind(i)].x-1)*64)+'px;"></div>';
						}
					}
				}
				all += '</div>';
				i++; ii = i; if (ii == drz.length) { break; }
			}
			all += '</td>';
			}
		all += '</tr>';
		}
		all += '</table>';
		drz.suma=0;
		drz.xyes=0;
		document.getElementById(drze+'n').innerHTML = drz.name;
		document.getElementById(drze+'t').innerHTML = all;
		document.getElementById(drze+'sum').innerHTML = 0;
		document.getElementById(drze+'p').innerHTML = 'Punkty w drzewku '+drz.name+': <span class="white">'+drz.suma+'</span>';
	}
	allsuma = 0;
	document.getElementById('pozostale').innerHTML = allsumap;
	document.getElementById('allsum').innerHTML = '9';
	window.location.hash='#'+klasa+'|'+spec+'|'+ver;
	if (link==true) {
		link = false;
		loadTal(abcl);
	} else {
		a.linkej=b.linkej=c.linkej="";
		if (speclimit && spec==0) { showspec(1); }
	}
	return true;
}

function loadedtal() {
	all = '<option value="||" SELECTED> - '+((buildy.length)?buildy.length:'0')+' gotowych buildów ('+vers[ver]+') - </option>';
	for (var i in buildy) {
		all += '<option value="'+buildy[i].link+'">'+buildy[i].name+'</option>';
	} document.getElementById('buildy').innerHTML = all;
	document.getElementById('spec').innerHTML = '';
	document.getElementById('klasa').innerHTML = name;
	if (speclimit) { zrobspec(); } else { showspec(0); }
	reset();
}

function loadTal(abcl) {
	reset();
	abc = abcl.split('|');
	a.linkej = abc[0];
	b.linkej = abc[1];
	c.linkej = abc[2];
	spec = parseInt(abc[3],10); if(!abc[3]) { spec=0; }
	for (var d=1;d<4;d++) {
		tree(d);
		linke=drz.linkej.split(''); 
		for(ajdi=0;ajdi<(linke.length);ajdi++) {
			if (drz.xyes < drz[ajdi].x) { break; }
			if (strfind(ajdi) && parseInt(linke[strfind(ajdi)],10) < drz[strfind(ajdi)].ammo && strfind(ajdi) != ajdi) { continue; }
			if (strfind(ajdi) && strfind(ajdi) == ajdi && linke[(ajdi+1)] != drz[ajdi].ammo) { continue; }
			var cyfra = document.getElementById(drze + 'c' + ajdi);
			cyfra.innerHTML = linke[ajdi];
			drz[ajdi].value = parseInt(linke[ajdi],10);
			act(ajdi);
			if (drz[ajdi].value == drz[ajdi].ammo) {
				act(ajdi,2);
			}
			drz.suma += drz[ajdi].value;
			drz.xyes = (drz.suma - (drz.suma % ppoint)) / ppoint;
		}
		document.getElementById(drze+'sum').innerHTML = drz.suma;
		document.getElementById(drze+'p').innerHTML = 'Punkty w drzewku '+drz.name+': <span class="white">'+drz.suma+'</span>';
		allsuma+=drz.suma;
	}
	tree(spec);
	document.getElementById('spec').innerHTML = ((speclimit)?drz.name:'');
	if (speclimit && drz.suma < speclimit) { blokuj(1,spec); }
	if (klasa=='pet' && allsuma > 16) { petpoints(); }
	if (allsuma == allsumap) { blokuj(1); }
	document.getElementById('pozostale').innerHTML = (allsumap-allsuma);
	document.getElementById('allsum').innerHTML = allsuma+9;
	window.location.hash='#'+klasa+'|'+spec+'|'+ver+'|'+a.linkej+'|'+b.linkej+'|'+c.linkej;
	if (speclimit) { showspec(0); }
	return true;
}

function blokuj(blokuj, drzewko) { // drzewko - drzewko ktore pominiemy
 var oldtree = drze;
 if (blokuj==1) { // zablokuj
  for (var d=1;d<4;d++) {
   if (drzewko == d) { continue; }
   tree(d);
   for(i in drz) {
	if (drz[i].value == 0 && drz[i].ammo) {
	 act(i,3,true);
	}
	if (drzewko && drz[i].active) {
	 act(i,3,true);
	 drz[i].active=2;
	}
   }
  }
 } else { // odblokuj
  for (var d=1;d<4;d++) {
   tree(d);
   for(i in drz) {
    if (drz[i].value == 0 && drz[i].active==true && drz[i].ammo) {
     act(i,1,true);
    }
	if (drz[i].active==2) {
     act(i,1,true);
	 drz[i].active=1;
	}
   }
  }
 }
 tree(oldtree);
}

function add(event, ajdi, drzewo) {
 tree(drzewo);
 ajdi = parseInt(ajdi,10);
 if (drz[ajdi].active!=true) { return false; }
 var id = ajdi;
 var cyfra = document.getElementById(drze + 'c' + ajdi);
 if ((event.button==1 || event.button==0) && event.shiftKey == false) { // dodajemy
  if (drz[ajdi].value == drz[ajdi].ammo || allsuma == allsumap) { return false; }
  if (allsuma==0 && speclimit) { zmienspec(drzi,true); }
  if (drz[ajdi].value < drz[ajdi].ammo) {
   cyfra.innerHTML++;
   drz[ajdi].value++;
   drz.suma++;
   allsuma++;
   if (drz.suma % ppoint == 0) { drz.xyes++; }
  }
  if (drz[ajdi].value == drz[ajdi].ammo) {
   act(ajdi,2);
   for (stt in stfind(ajdi)) {
    if (drz[stfind(ajdi)[stt]].active == false && drz[stfind(ajdi)[stt]].x <= drz.xyes) {
	 act(stfind(ajdi)[stt]);
    }
   }
  }
  if (drz.suma % ppoint == 0) {
   for(i in drz) {
    if (!isset(drz[i].ammo)) { continue; }
    if (drz[i].x > drz.xyes) { break; }
    if (drz[i].active == false && drz[i].x == drz.xyes) {
	 if (strfind(i) && drz[strfind(i)].value < drz[strfind(i)].ammo) { continue; }
	 act(i);
	}
   }
  }
  if (speclimit && drzi == spec && drz.suma == speclimit) {
	blokuj(0);
  }
  if (allsuma == allsumap) { blokuj(1); }
 } else { // odejmujemy
  if (drz[ajdi].value == 0) { return false; }
  var suma = 0; // suma talentów do wiersza który jest aktywny
  var sumaa = 0; // suma talentów w wierszu który jest ostatni aktywny
  var ax = 0;
  var ay = 0;
  for(i in drz) {
   if (!isset(drz[i].ammo)) { continue; }
   if (drz[i].x < drz.xyes) { suma += drz[i].value; }
   if (drz[i].x == drz.xyes) { sumaa += drz[i].value; }
   if (drz[i].x > drz.xyes) { break; }
   if (ax < drz[i].x && ay < drz[i].x*ppoint && drz[i].x != drz.xyes) { return false; }
   ax = drz[i].x;
   ay += (i == ajdi) ? drz[i].value-1 : drz[i].value;
  }
  if (suma % ppoint == 0 && drz[ajdi].x < drz.xyes && sumaa > 0) { return false; }
  if (drz[ajdi].value == drz[ajdi].ammo) {
   for (stt in stfind(ajdi)) {
    if (drz[stfind(ajdi)[stt]].value > 0) { return false; }
   }
   for (stt in stfind(ajdi)) {
    if (drz[stfind(ajdi)[stt]].active == true) { act(stfind(ajdi)[stt],3); }
   }
  }
  if (speclimit && drzi == spec && drz.suma == speclimit) {
	if (allsuma != drz.suma) { return false; }
	blokuj(1,spec);
  }
  act(ajdi,1);
  if (drz.suma % ppoint == 0) {
   for(i in drz) {
    if (!isset(drz[i].ammo)) { continue; }
    if (drz[i].x > drz.xyes) { break; }
    if (drz[i].x == drz.xyes && drz[i].active == true) {
 	 act(i,3);
    }
   }
   drz.xyes--;
  }
  if (allsuma == allsumap) { blokuj(0); if (allsuma<speclimit) { blokuj(1,spec); } }
  cyfra.innerHTML--;
  drz[ajdi].value--;
  drz.suma--;
  allsuma--;
 }
 if (allsuma==0 && speclimit) { blokuj(0); }
 document.getElementById(drze+'p').innerHTML = 'Punkty w drzewku '+drz.name+': <span class="white">'+drz.suma+'</span>';
 document.getElementById('pozostale').innerHTML = (allsumap-allsuma);
 document.getElementById(drze+'sum').innerHTML = drz.suma;
 document.getElementById('allsum').innerHTML = allsuma+9;
 drz.linkej = '';
 for(i in drz) {
  if (drz[i].x > drz.xyes) { break; }
  if (drz[i].ammo) { drz.linkej+=drz[i].value; }
 }
 window.location.hash='#'+klasa+'|'+spec+'|'+ver+'|'+a.linkej+'|'+b.linkej+'|'+c.linkej;
 swiatloOn(event, id);
}


function swiatloOn (event, ajdi, drzewo) {
 tree(drzewo);
 ajdi = parseInt(ajdi,10);
 var div = document.getElementById(drze + 'n' + ajdi);
 div.style.backgroundPosition = '-38px 50%';
 var tip = document.getElementById('tiptalent');
 tip.style.display = 'block';
 if (strfind(ajdi) && drz[strfind(ajdi)].ammo > drz[strfind(ajdi)].value) {
  if (drz[strfind(ajdi)].ammo == 1) { znak = 'u'; } else { znak = 'ów'; }
  requires = '<span class="red">Wymaga '+drz[strfind(ajdi)].ammo+' punkt'+znak+' w '+drz[strfind(ajdi)].name+'</span><br />';
 } else { requires = ''; }
 requires += ((drz[ajdi].x*ppoint > drz.suma) ? '<span class="red">Wymaga '+(drz[ajdi].x*ppoint)+' punktów w '+drz.name+'</span><br />' : '');
 if (drz[ajdi].active==1) {
 learn = (drz[ajdi].value < drz[ajdi].ammo) ? ((allsuma!=allsumap)?'<span class="green">Kliknij by się nauczyć</span><br />':'') : '<span class="red">Kliknij z Shiftem by się oduczyć</span><br />';
 }
 if (drz[ajdi].ammo) { poziom = 'Poziom '+drz[ajdi].value+'/'+drz[ajdi].ammo+'<br />'; } else { poziom=''; }
 if (!drz[ajdi].value) { drz[ajdi].value=0; }
 tip.innerHTML = '<div id="tip"><b>'+drz[ajdi].name+'</b><br />'+poziom+((drz[ajdi].active) ? '' : requires)+(drz[ajdi].add?drz[ajdi].add:'')+'<span class="opis">'+((drz[ajdi].value == 0) ? drz[ajdi].opis[drz[ajdi].value] : drz[ajdi].opis[drz[ajdi].value-1]) + ((drz[ajdi].value == 0 || drz[ajdi].value == drz[ajdi].ammo) ? '' : '</span><br />Następny poziom:<br /><span class="opis">'+drz[ajdi].opis[drz[ajdi].value])+'</span>'+((drz[ajdi].active==1) ? learn : '')+'</div><div id="ld"></div><div id="rd"></div>';
 tip.style.left = X(div) + 39 + 'px';
 if (event.clientY > tip.clientHeight+140) {
  tip.style.top = Y(div) - tip.clientHeight + 'px';
 } else {
  tip.style.top = Y(div) + 39 + 'px';
 }
}

function swiatloOff (ajdi, drzewo) {
 tree(drzewo);
 document.getElementById(drze + 'n' + ajdi).style.backgroundPosition = '0px 50%';
 var tip = document.getElementById('tiptalent');
 tip.style.display = 'none';
 tip.innerHTML = '';
}

function convert (abcl) {
	abcl = abcl.split('tal=');
	abcll = abcl[1].split('');
	drz = a;
	var i = 0;
	for (d=0;d<3;d++) {
		var bum = "";
		for (ajdi in drz) {
		if (!isset(drz[ajdi].ammo)) { continue; }
		bum += abcll[i];
		i++;
		}
		if (d==0) { al=bum; drz=b;}
		if (d==1) { bl=bum; drz=c; }
		if (d==2) { cl=bum; }
	}
	loadTal(al+'|'+bl+'|'+cl);
	var bec;
	for (var d=0;d<3;d++) {
		if (d==0) { bec=a; }
		if (d==1) { bec=b; }
		if (d==2) { bec=c; }
		bec.linkej = '';
		for(i in bec) {
			if (!isset(bec[i].ammo)) { continue; }
			if (bec[i].y > bec.xyes) { break; }
			bec.linkej+=bec[i].value;
		}
		window.location.hash='#'+klasa+'|'+spec+'|'+ver+'|'+a.linkej+'|'+b.linkej+'|'+c.linkej;
	}
}

function print() {
	printer = window.open('', 'print', 'toolbar=0,location=0,status=0,menubar=1,scrollbars=1,resizable=1,width=800,height=500');
	printer.focus();
	printer.document.title = document.title;
	printer.document.body.style.fontFamily='Arial';
	printer.document.body.style.fontSize='12px';
	printer.document.body.innerHTML = '<br /><span style="font-size:17px"><b>'+(9+allsuma)+'lv '+name+' - Talenty ('+a.suma+'/'+b.suma+'/'+c.suma+')</b></span><br /><ol type="none">';
	for (var d=0;d<3;d++) {
		if (d==0) { drz=a; drze='a'; }
		if (d==1) { drz=b; drze='b'; }
		if (d==2) { drz=c; drze='c'; }
		znak = (''+drz.suma+'').charAt((''+drz.suma+'').length-1);
		if ((drz.suma < 10 || drz.suma > 20) && znak > 1 && znak < 5) {
		 znak = 'y';
		} else {
		 znak = 'ów'; 
		}
		if (drz.suma == 1) { znak = ''; }
		printer.document.body.innerHTML += '<li style="list-style-type:none"><span style="font-size:15px"><b>'+drz.name+'</b> - '+drz.suma+' talent'+znak+'</span><br /><ol type="disc" style="margin: 0">';
		for(i in drz) {
			if (drz[i].value > 0) {
				printer.document.body.innerHTML += '<li>'+drz[i].name+' - Poziom '+drz[i].value+'/'+drz[i].ammo+'</li>';
			}
		}
		printer.document.body.innerHTML += '</li></ol><br />';
	}
	printer.document.body.innerHTML += '</ol></font>';
}

var bmtalent = false;
function petpoints() {
if (bmtalent==false) {
	bmtalent=true;
	if (allsuma == allsumap) {
		for (d=1;d<4;d++) {
			tree(d);
			for(i in drz) {
				if (drz[i].value == 0 && drz[i].ammo && drz[i].active==2) {
					act(i,1,true);
				}
			}
		}
	}
	allsumap+=4;
	document.getElementById('pettalent').innerHTML = 'Wyłącz Beast Mastery';
	document.getElementById('pozostale').innerHTML = (allsumap-allsuma);
} else {
	if (allsumap-allsuma < 4) { alert('Przed pomniejszeniem liczby punktów do rozdania do 16, usuń kilka talentów, żebyś miał 4 wolne punkty do rozdania!'); return; }
	bmtalent=false;
	allsumap-=4;
	document.getElementById('pettalent').innerHTML = 'Włącz Beast Mastery';
	document.getElementById('pozostale').innerHTML = (allsumap-allsuma);
	if (allsuma == allsumap) {
		for (var d=1;d<4;d++) {
			tree(d);
			for(i in drz) {
				if (drz[i].value == 0 && drz[i].ammo && drz[i].active) {
					act(i,3,true);
				}
			}
		}
	}
}

}
