var graphs=Array();
graphs["updateSpeed"]=10;
graphs["status"]="idle";
graphs["images"]=Array();
graphs["tabs"]=Array();
graphs["queue"]=Array();
graphs["last"]=Array();
preload=Array();

function animateGraphs()
{
 containers=document.getElementsByTagName("div");

 p=0;
 for(x=0;x<containers.length;x++)
 {
  if(containers[x].className=="graphs")
  {
   container=containers[x];

   nav=document.createElement("div");
   nav.className="navigation";

   container.insertBefore(nav, container.firstChild);

   graph=container.getElementsByTagName("div");

   first=false;
   graphs["images"][x]=Array();
   graphs["tabs"][x]=Array();
   graphs["last"][x]=false;

   z=0;
   tmp=Array();
   for(c=0;c<graph.length;c++)
   {
    if(graph[c].className=="graph")
    {
     graphs["images"][x][z]=new Flash(graph[c]);
     graphs["images"][x][z].obj.style.display="none";

     preload[p]=new Image();
     preload[p].src=graphs["images"][x][z].obj.src;
     p++;

     tmp[z]=document.createElement("div");
     tmp[z].id="graph_"+x+"_"+z;
     tmp[z].style.cursor="pointer";
     tmp[z].style.backgroundColor="#D9D9D9";
     tmp[z].onmouseover=showGraphs;
     tmp[z].onclick=showGraphs;

     tmp2=graph[c].getElementsByTagName("div");
     for(k=0;k<tmp2.length;k++)
     {
      if(tmp2[k].className=="tab")
      {
       tmp[z].innerHTML=tmp2[k].innerHTML;
       tmp2[k].style.display="none";
       
      }
     }

     if(!tmp[z].innerHTML)
      tmp[z].innerHTML=graph[c].getElementsByTagName("img")[0].alt;

     z++;
    }
   }

   for(c=0;c<z;c++)
   {
    nav.appendChild(tmp[c]);
    graphs["tabs"][x][c]=new Flash(tmp[c]);
    graphs["tabs"][x][c].updateSpeed=graphs["updateSpeed"];
   }
   nav.appendChild(document.createElement("br"));

   if(z>0)
    tmp[0].onmouseover(); 
  }
 }
}

function showGraphs()
{
 if(this.id==undefined)
  return;

 this.id+="";
 if(!this.id.match("graph"))
  return;

 t=this.id.replace(/graph_/, "").split("_");

 for(c=0;c<graphs["queue"];c++)
 {
  if(graphs["queue"][c]==t)
   return;
 }

 graphs["queue"].push(t);
 showGraphsQueue();
}

function showGraphsQueue()
{
 if(graphs["queue"].length==0)
  return;

 if(graphs["status"]=="showing")
  setTimeout('showGraphs()', 1000);

 tmp=graphs["queue"].shift();
 g=tmp[0];
 t=tmp[1];

 graphs["status"]="showing";

 if(graphs["last"][g]!==false)
  hideGraphs(g, graphs["last"][g]);

 graphs["images"][g][t].obj.style.display="block";

 graphs["tabs"][g][t].backgroundColor("#D9D9D9", 0);
 graphs["tabs"][g][t].backgroundColor("#F5F5F5", 50);
 graphs["tabs"][g][t].go();

 graphs["last"][g]=t;

 return false;
}

function hideGraphs(g, t)
{
 graphs["images"][g][t].obj.style.display="none";

 graphs["tabs"][g][t].backgroundColor("#D9D9D9", 50);
 graphs["tabs"][g][t].go();
}
