var D=document;
var W=window;
var IE=/MSIE (\d+\.\d+);/.test(navigator.userAgent);
var IMGS=[
  'cccdea@@eeb  a ? bdbbdbae de cacbbba@b a a  aaaed@cab ab bb@aaac aabbba ac@dbb bbbb  aadab@bacabaab',
  '   a@a bb@@        aaa @  @aa a b aacaa ab    bba  a  baaacaaaa a bcbaa?ba   caaa @bb ca  b   b    a',
  'ca a     a  @a aaba ba b b  ?@ @b  a    d   aa   a  a           a b  a @ b  a   a  a a   aa b aa a a',
  'c a accba ca     ab aa ab  d b  b   @aa@     abaa b a  a a @aab  abaa   aaa aa  a b caa aab        a',
  'c c ab   aba c aaaaaa acaab  ab            abaa    aa   a b    b     a ca  b  a  b@   b c  a  bbb   ',
  'a a   c          ab   ba   aaab            bba aa b  a    bb@        aa   ba         b a aaa    b a ',
  '   a a     a b @abab        a   b    b   aa  a a        a   b a  aab   a a    aba ca   a            ',
  'ca   @         bb @      a            @a    a                 aa     a                    @         ',
  'a        a  a                                aa      b                                              ',
  ' aaa    a          a         a                     @    @       a a    cd                     ?     ',
  '          b   @   @  @         @a              a     a     @    a  a ba a   @         a      ?      ',
  '   @a   a                @    aa a@aaa a a             aa    a     @     a            a       a a   ',
  'b b aaaaa    ?  @    aa     a            a           aaa    ab                        a       a    a',
  'ba  a aa   @          @a    @ a                  aa            aa?     aaa  a            a          ',
  '@@@    @@a                             a                                 b         a a @b           ',
  '                ca                                                        a    @                    ',
  '    a            a         a  a        b     b  ca          b   a       @c    a  a   @   a         a',
  'a      a          @@ @              @    a  @     @       @@    b  @    a              @  a         ',
  '        a     a       @    @ a  @@    @c    a   @@     ?            d a        @b@   @  @      @    ',
  '@a  a       @                       @        @  @             a   @         a   d                   ',
  '@   a                                     a  @  @ @     @a@    @                                  a ',
  '@            @     @@     a                @  @         @        a  a                        b b a  ',
  '        a        a           a b  a a   @@     @@          @    a a   a            @@  @       @a   ',
  '        @ @          @                @              @@@  @         a             aaa        @    a ',
  '             b                          a                                                      a    ',
  '                   @  @a                    @           @ @               @           @             ',
  '               aa                 @a                        b            aa       a   a  a       a  ',
  '    a @          a    bb   a                    a           a   a            b                      ',
  'aa                                  aa                        a  a aa@  b                           '
];
var _onload=[],_onunload=[];
function pageLoaded(){for(var i=0;i<_onload.length;i++)_onload[i].call();}
function pageUnLoaded(){for(var i=0;i<_onunload.length;i++) _onunload[i].call();}
function EUMCard(c,n,d,h){this.card=c;this.name=n;this.date=d;this.href=h;}
function $$(c,p,kl){
  var tag;
  if(IE&&(p||kl)){
    tag="<"+c;
    if(p){
      for(o in p){
        if(typeof(p[o])=="function")continue;
        tag+=' '+o+'="'+p[o]+'"';
      }
    }
    if(kl)
      tag+=' class="'+kl+'"';
    tag+="></"+c+">";
    tag=document.createElement(tag);
  }else{
    tag=document.createElement(c);
    if(p){
      for(o in p){
        if(typeof(p[o])=="function")continue;
        tag.setAttribute(o,p[o]);
      }
    }
    if(kl)
      tag.setAttribute("class",kl);
  }
  return tag;
}
function section(s){
  go("content/sections/"+s);
}
function go(s){
  if(s.indexOf("http")==0){
    W.location=s;
  }else{
    W.location="http://www.eumreborn.com/es/"+s+".html";
  }
}
function eum(c){
  var i=Math.floor(c/100);
  var p=i<10?"00"+i:i<100?"0"+i:i;
  var card=c<10?"0"+c:c;
  if(c<100){
    W.location=BASE+"cards/"+p+"/"+card+".html";
  }else{
    W.location="http://www.eumreborn.com/es/cards/"+p+"/"+card+".html";
  }
}

if(!D.getElementById){
  D.getElementById=function(id){
    if(!D._IEac)D._IEac=[];
    if(D._IEac[id]==null)D._IEac[id]=D.all[id];
    return D._IEac[id];
  };
}
function $(){
  var a=[],s=arguments;
  for(var i=0;i<s.length;i++){
    var e=s[i];
    if(typeof e=='string')e=D.getElementById(e);
    if(s.length==1)return e;
    a.push(e);
  }
  return a;
}

function showcard(c){
  var e=$("eum");
  var s=e.style;
  //mouseOffset=getMouseOffset(eum);
  if(e){
    var i=mousePos.y-90;
    if(i<0)i=mousePos.y+90;
    s.top=i+"px";
    i=mousePos.x-40;
    if(i<0)i=0;
    s.left=i+"px";
    e.innerHTML="<img src='"+cardimg(c,BASE+"..")+"'>";
  }
  visibility("eum",true);
}

function cardimgLetter(c){
  var p=Math.floor(c/100);
  var c1=c<100?c-1:c%100;
  return IMGS[p].charAt(c1);
}

function cardimg(c,d){
  var p=Math.floor(c/100);
  var c1=c<100?c-1:c%100;
  var i=c>=IMGS.length?' ':IMGS[p].charAt(c1);
  var z=p<10?"00"+p:p<100?"0"+p:p;
  if(i=='?')i="unknown";
  else if(i==' ')i="";
  z+="/"+(c<10?"0"+c:c)+i;
  return d+"/pics/"+z+".jpg";
}

function cardimgPath(c,d,i){
  var p=Math.floor(c/100);
  var z=p<10?"00"+p:p<100?"0"+p:p;
  var c1=c<100?c-1:c%100;
  if(i=='?')i="unknown";
  else if(i==' ')i="";
  z+="/"+(c<10?"0"+c:c)+i;
  return d+"/pics/"+z+".jpg";
}

function swapCards(a,r){
  for(var i=1;i<=5;i++){
    var j=a[i-1];
    $("card"+i+"i").src=cardimg(j.card,".");
    $("card"+i+"a").href=j.href?j.href:"javascript:eum("+j.card+");";
    $("card"+i+"h").innerHTML=j.name;
    $("card"+i+"c").innerHTML=CARD.replace('@',j.card);
    $("card"+i+"d").innerHTML=j.date.indexOf('-')==-1?VISITS.replace('@',j.date):j.date;
  }
  for(var i=0;i<4;i++)
    $("arrow"+i).src="./img/arrow"+(i==r?"":"-off")+".gif";
}

function hidecard(c){
  visibility("eum",false);
}

function visibility(e,v,d){
  e=$(e);
  if(e){
    if(D.layers)
      e.visibility=visible?'show':'hide';
    else{
      e=e.style;
      e.visibility=v?'visible':'hidden';
      if(arguments.length==3)
        e.display=d==true?"block":d==false?"none":d;
    }
  }
}

D.onmousemove=mouseMove;
function mouseMove(e){
  e=e||W.event;
  W.mousePos=mouseCoords(e);
}

function mouseCoords(ev){
  if(ev.pageX||ev.pageY)return{x:ev.pageX,y:ev.pageY};
  var b=D.body;
  return {x:ev.clientX+b.scrollLeft-b.clientLeft,y:ev.clientY+b.scrollTop-b.clientTop};
}

function getPos(e){
  var l=0,t=0;
  while(e.offsetParent){
    l+=e.offsetLeft;
	t+=e.offsetTop;
	e=e.offsetParent;
  }
  l+=e.offsetLeft;
  t+=e.offsetTop;
  return {x:l,y:t};
}

function getMouseOffset(target){
  var docPos=getPos(target);
  return {x:mousePos.x-docPos.x,y:mousePos.y-docPos.y};
}

function visits(){
}

var zoomDiv=null;
var zoomImg=null;
function zoom(i){
  if(!D.createElement)return;
  if(zoomDiv==null){
    zoomDiv=D.createElement('div');
    zoomDiv.setAttribute('id',"picZoom");
    zoomDiv.style.top="50px";
    zoomDiv.style.left="350px";
    zoomDiv.style.position = "absolute";
    var a=D.createElement('a');
    a.href="javas"+"cript:zoomHide()";
    zoomImg=D.createElement('img');
    zoomImg.src= "../../../pics-high/"+i;
    a.appendChild(zoomImg);
    zoomDiv.appendChild(a);
    D.body.appendChild(zoomDiv);
  }else{
    zoomImg.src="../../../pics-high/"+i;
    zoomDiv.style.display="block";
  }
}

function zoomHide(){
 zoomDiv.style.display="none";
}

function loadRefs(eum){
	ajax("/eum?cmd=card.refs&eum="+eum,loadRefsOut);
}
function loadRefsOut(txt){
	var data=eval(txt);
	//({empty:false,cards:[{n:'"Bestia"',id:385}]})
	if(!data.empty){
		txt="";
		data=data.cards;
		var c=$("refsContent");
		for(var i=0;i<data.length;i++){
			if(i!=0)c.appendChild(document.createTextNode("; "));
			var a=$$("A");
			a.innerHTML=data[i].n;
			a.href="/eum?cmd=card.view&id="+data[i].id;
			c.appendChild(a);
		}
		$("refs").style.display = "block";
	}
}
