hcName='hidden';
oncName='on';
hovcName='hover';

function email(){
	var addr=Array('lto:','om','cheers','-sendai','.c','mai','@');
	var link=document.getElementById('addr');
	var theadd=addr[2]+addr[6]+addr[2]+addr[3]+addr[4]+addr[1];
	link.innerHTML=theadd;
	link.href=addr[5]+addr[0]+theadd;
}


function thePoints(li){
	if (document.getElementById('points')){
		var hcName="no_text";
		var points=document.getElementById('points').getElementsByTagName('li');
		for (i=0; i<points.length; i++) {
			if (points[i].getElementsByTagName('h2')[0]) {
				points[i].className=points[i].className.replace(new RegExp(hcName+"\\b"), "");
				var rEx=new RegExp("(^|\\s)"+hcName+"(\\s|$)");
//				points[i].getElementsByTagName('a')[0].onclick=function() {return false};
			if (rEx.test(points[i].className)==false) {points[i].className+=" "+hcName;}				}
			points[i].onmouseover=function() {thePoints(this);}
			points[i].onmouseout=function() {thePoints();}	
			points[i].onclick=function() {
					if(this.getElementsByTagName('h2')[0]) {
					window.location=this.getElementsByTagName('h2')[0].getElementsByTagName('a')[0].href;
					}
				}
			}
	}
	if (li) {
		li.className=li.className.replace(new RegExp(hcName+"\\b"), "");
//		li.getElementsByTagName('a')[0].onclick=function() {return true}
	}
}



function addClass(infoDiv,cName) {
		infoDiv.className=infoDiv.className.replace(new RegExp(cName+"\\b"), "");				
		var rEx=new RegExp("(^|\\s)"+cName+"(\\s|$)");
		if (rEx.test(infoDiv.className)==false) {infoDiv.className+=" "+cName;}	
}

function removeClass(infoDiv,cName) {
		infoDiv.className=infoDiv.className.replace(new RegExp(cName+"\\b"), "");
}

function showRnd(oArray) {
			var ran_unrounded=Math.random()*oArray.length;
			var rnd=Math.floor(ran_unrounded);
			var div=oArray[rnd];
			return Array(div,rnd);
}


function teachers(div) {
	if (document.getElementById('teachers_nav')){
		var pics=document.getElementById('teachers_nav').getElementsByTagName('li');
		for (i=0; i<pics.length; i++) {
			var info=pics[i].id.replace(new RegExp('nav'),'');
			var infoDiv=document.getElementById(info);
			addClass(infoDiv,hcName);
			pics[i].onclick=function() {
				teachers(this);
			}
		}
		if (!div) {var div=showRnd(pics)[0];}
		var info=div.id.replace(new RegExp('nav'),'');
		var infoDiv=document.getElementById(info);
		removeClass(infoDiv,hcName);				
	}
}




function toc(div) {
if (document.getElementById('theClasses')) {
	var theClasses=document.getElementById('theClasses');
	var cDivs=theClasses.getElementsByTagName('div');
	var ul = document.createElement('ul');
	ul.id="toc";
	for (i=0; i<cDivs.length; i++) {
		infoDiv=cDivs[i];
		addClass(infoDiv,hcName);
		var li = document.createElement('li');				var theText=infoDiv.getElementsByTagName('h2')[0].firstChild.nodeValue.split(' |')[0];		
		var text=document.createTextNode(theText);		
		li.appendChild(text);
		li.onmouseover=function() {
			var lis=document.getElementById('toc').getElementsByTagName('li');
			var cDivs=theClasses.getElementsByTagName('div');
			for (i=0; i<cDivs.length; i++) {
				removeClass(lis[i],oncName);
				infoDiv=cDivs[i];
				addClass(infoDiv,hcName);								testText=cDivs[i].getElementsByTagName('h2')[0].firstChild.nodeValue.split(' |')[0];				thisText=this.firstChild.nodeValue.split(' |')[0];
				if (testText==thisText) {
					removeClass(cDivs[i],hcName);
					}
				}
				removeClass(this,hovcName);
				addClass(this,oncName);
			}/*
		li.onmouseover=function(){
			if (RegExp("(^|\\s)"+oncName+"(\\s|$)").test(this.className)==false) {addClass(this,hovcName)}
			}*/
		li.onmouseout=function(){removeClass(this,hovcName);}
		ul.appendChild(li);
		}
	theClasses.insertBefore(ul,theClasses.firstChild);
	
	var cats=['special','english','tests','music','languages','other']; 

		var theLis=ul.getElementsByTagName('li');
		for (j=0; j<cats.length; j++) {
			for (k=0; k<theLis.length; k++) {
				var rExp=new RegExp("(^|\\s)"+cats[j]+"(\\s|$)");
				if (rExp.test(cDivs[k].className)==true && cats[j]!=lastCat) {
					newh3=document.createElement('h3');
					newText=document.createTextNode(cats[j]);
					newh3.appendChild(newText);
					newh3.className+=" heading";
					theLis[k].appendChild(newh3);
					var lastCat=cats[j];
					}	
			}
		}

	if (!div) {
		var div=showRnd(cDivs); 
		removeClass(div[0],hcName); 
		addClass(document.getElementById('toc').getElementsByTagName('li')[div[1]],oncName);
		}
		
	}
}

function makeBiscuit(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
	document.cookie = ck;
}

function getQuestion()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  var resp=xmlHttp.responseText;
	  var bits=resp.split("|");
	  var tquestion=bits[0];
      document.getElementById("tquestion").innerHTML=tquestion;
      }
    }
  xmlHttp.open("GET","question_ajax.php",true);
  xmlHttp.send(null);
  }

  function usedQuestion(id)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  var resp=xmlHttp.responseText;
	  var bits=resp.split("|");
	  var tquestion=bits[0];
      document.getElementById("tquestion").innerHTML=tquestion;
	  document.getElementById("uQa").onclick=function() {
		usedQuestion(bits[1]);
		}
      }
    }
  xmlHttp.open("GET","question_ajax.php?q="+id,true);
  xmlHttp.send(null);
  }

window.onload=function() {
	if(document.getElementById('addr')){
		email();
			}
	thePoints(); 
	teachers();
	toc();
	makeBiscuit('cheers', '',365);
	if (document.getElementById('cover')) {
		document.getElementById('cover').onmouseover=function() {
			this.style.display="none";
			}
		}
			
	}