/*

 javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com 

Modified for Armada Games 5/2/2011 by Matt Holden
  http://www.mattholden.com
  
  
*/


// Define what the image extension will be (note: depending on your server configuration, this will most likely be case sensitive)
   var IMAGE_TYPE = "jpg";

// Path (relative, absolute paths should work but are untested) to find images
   var IMAGE_PATH = "/forums/images/games/mtg/";

// What to replace spaces with - an empty string ("") should work too
   var REPLACE_SPACES_WITH = "_";
   
// If this is set to 1, force lower-case image names. If set to 2, force upper-case image names. If set to 0, leave the existing case.
   var FORCE_CASE_IN_IMAGES = 1;
   
// What color to force the links to be - can either be a CSS-recognized color word ("blue") or a color code (0000ff) but must be in quotes.
// Set this to null (no quotes) to use the base CSS.
   var FORCE_LINK_COLOR = "blue";
   
   
function card(c) { 
  
  var parsed = parse(c);
  var cardParsed = "card" + parsed;
  
  document.write("<a class='cardToolTip' ");
  
  if (FORCE_LINK_COLOR != null) {
  	document.write("style='color: ");
  	document.write(FORCE_LINK_COLOR);
  	document.write(";' ");
  }
  document.write("href='");
  document.write(document.URL)
  document.write("' id='")
  document.write(cardParsed)  
  document.write("' title='");
  document.write(c);
  document.write("'>");
  document.write(c);
  document.write("</a>");
}


function parse(card) { 

 var i;
 var name = "";
 for (i = 0; i < card.length; i++) {
    var ch = card.charAt(i);
    if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z')) {
    
    	if (FORCE_CASE_IN_IMAGES == 1)
    		name = name + ch.toLowerCase();
       	else if (FORCE_CASE_IN_IMAGES == 2)
       		name = name + ch.toUpperCase();
       	else 
    		name = name + ch;
    }
    if((ch>='1'&&ch<='0')) name = name + ch;
    if (ch == ' ') name = name + REPLACE_SPACES_WITH;

 }
 return name;
 
}

function enableTooltips(id){
var links,i,h;
if(!document.getElementById || !document.getElementsByTagName) return;
AddCss();
h=document.createElement("span");
h.id="btc";
h.setAttribute("id","btc");
h.style.position="absolute";
document.getElementsByTagName("body")[0].appendChild(h);

if(id==null) links=document.getElementsByTagName("a");
else links=document.getElementById(id).getElementsByTagName("a");
for(i=0;i<links.length;i++){    

   if (links[i].getAttribute("id") != null && links[i].getAttribute("id").substring(0,4) == "card")
      Prepare(links[i]);
   }
}

function Prepare(el){
var tooltip,t,b,s,l;
tooltip=CreateEl("span","tooltip");
s=CreateEl("span","top");
//tooltip.appendChild(s);

t = CreateEl("img", "card");
t.setAttribute("src", IMAGE_PATH+el.getAttribute("id").substring(4)+"."+IMAGE_TYPE);
tooltip.appendChild(t);



b=CreateEl("b","bottom");
//tooltip.appendChild(b);
b.appendChild(document.createTextNode(IMAGE_PATH+el.getAttribute("id").substring(4)+"."+IMAGE_TYPE));
b.appendChild(document.createTextNode(el.getAttribute("title")));

setOpacity(tooltip);
el.tooltip=tooltip;
el.onmouseover=showTooltip;
el.onmouseout=hideTooltip;
el.onmousemove=Locate;
}

function showTooltip(e){
document.getElementById("btc").appendChild(this.tooltip);
Locate(e);
}

function hideTooltip(e){
var d=document.getElementById("btc");
if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
el.style.filter="alpha(opacity:95)";
el.style.KHTMLOpacity="0.95";
el.style.MozOpacity="0.95";
el.style.opacity="0.95";
}

function CreateEl(t,c){
var x=document.createElement(t);
x.className=c;
x.style.display="block";
return(x);
}

function AddCss(){
var l=CreateEl("link");
l.setAttribute("type","text/css");
l.setAttribute("rel","stylesheet");
l.setAttribute("href","bt.css");
l.setAttribute("media","screen");
document.getElementsByTagName("head")[0].appendChild(l);
}

function Locate(e){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
    }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
document.getElementById("btc").style.top=(posy+10)+"px";
document.getElementById("btc").style.left=(posx-20)+"px";
}
