var w3c=document.getElementById;
var ie45=document.all; // needed for backward compatibility with earlier pages and used to detect media player!

var tx_ani=0;
function title_animate() { if (w3c) {
  var i=0;
  var el, tex, fg, bg, j, k, sp;
  while (el=document.getElementById("title"+(i++))) {
	fg=el.style.color;
	if (!fg) alert ("No foreground colour set for 'title"+(i-1)+"'");
	bg=el.style.backgroundColor;
	if (!bg && fg.substring(0,1)=="#") bg="#550088";
	else if (!bg) bg="rgb(85, 0, 136)";
	tex=el.firstChild.nodeValue;
	el.firstChild.nodeValue="";
	k=0;
	for (j=0; j<tex.length; j++){
	  if (/\S/.test(tex.charAt(j))) {
		sp=document.createElement("span");
		sp.style.color=fg;
		sp.appendChild(document.createTextNode(tex.charAt(j)));
		sp.setAttribute("id", "stuff"+((k++)+tx_ani));
	    el.appendChild(sp);
	  }
	  else el.appendChild(document.createTextNode(tex.charAt(j)));
	}
	tx_go(tx_ani, k, true, fg, bg);
	tx_ani+=k;
  }
  if (document.getElementById("p2007")) expandify();
  linkify_ww();
}}

function expandify() { // are we on pictures page? new stuff added Dec 2011
  var i, p, c;
  for (i=2002; i<2008; i++) {
    p=document.getElementById("p"+i);
    c=document.getElementById("c"+i);
    c.style.width="15px";
    c.style.visibility="visible";
    if (window.location.href.indexOf(i)!=-1 || (window.location.href.indexOf('200')==-1 && i==2007)) {
      p.style.visibility="visible";
      p.style.display="block";
      c.firstChild.nodeValue="-";
    }
    else {
      p.style.visibility="hidden";
      p.style.display="none";
      c.firstChild.nodeValue="+";
    }
  }
}

function linkify_ww() { // add 'ww' to page links
 var z;
 var ww=600;
 if (document.documentElement && document.documentElement.clientWidth) ww=Math.max(ww, document.documentElement.clientWidth);
 else if (typeof(self.innerHeight)=="number") ww=Math.max(ww, self.innerWidth);
 else if (document.body.clientWidth) ww=Math.max(ww,document.body.clientWidth);
 if (ww>600) {
   var a=document.getElementsByTagName("a");
   for (var z=0; z<a.length; z++) if (a[z].href.indexOf('trans-mission.org')!=-1 && a[z].href!="#") a[z].href=a[z].href+(a[z].href.indexOf('?')==-1?'?':'&')+'ww='+ww;
  }
}

function shadow(el) { // now unused but kept here for future reference
  var spt, sps, wor;
  wor=el.firstChild.nodeValue;
  sps=document.createElement("span");
  sps.style.position="relative";
  sps.style.color="#303";
  sps.appendChild(document.createTextNode(wor))
  spt=document.createElement("span");
  spt.style.position="absolute";
  spt.style.top="-1px";
  spt.style.left="-1px";
  spt.appendChild(document.createTextNode(wor));
  sps.appendChild(spt);
  el.removeChild(el.firstChild);
  el.appendChild(sps);
  return (spt);
}

function clicky(yr) { // expanding menu on events pages
  var j=document.getElementById("p"+yr);
  if (j.style.visibility=='hidden') {
    j.style.visibility="visible";
    j.style.display="block";
	document.getElementById("c"+yr).firstChild.nodeValue='-';
  }
  else {
    j.style.visibility="hidden";
    j.style.display="none";
	document.getElementById("c"+yr).firstChild.nodeValue='+';
  }
  return (false);
}

function tx_go(start, end, visbl, fg, bg) {
  var delay=250+(2000+50*end)*visbl;
  visbl=!(visbl);
  eval ('setTimeout("tx_t'+Math.floor(1+Math.random()*5)+'("+start+", "+end+", 0, "+visbl+", \'"+fg+"\', \'"+bg+"\')", delay)');
}

function tx_t1(start, end, pos, visbl, fg, bg) {
  var el=document.getElementById("stuff"+(pos+start));
  el.style.color=(visbl)?fg:bg;
  if (++pos==end) tx_go(start, end, visbl, fg, bg);
  else setTimeout("tx_t1("+start+", "+end+", "+pos+" ,"+visbl+" ,'"+fg+"', '"+bg+"')", 90+start%20);
}

function tx_t2(start, end, pos, visbl, fg, bg) {
  var el=document.getElementById("stuff"+(start+end-pos-1));
  el.style.color=(visbl)?fg:bg;
  if (++pos==end) tx_go(start, end, visbl, fg, bg);
  else setTimeout("tx_t2("+start+", "+end+", "+pos+" ,"+visbl+" ,'"+fg+"', '"+bg+"')", 90+start%20);
}

function tx_t3(start, end, pos, visbl, fg, bg) {
  var ra, el;
  var cl=(visbl)?fg:bg;
  do {
    ra=start+Math.floor(Math.random()*end);
    el=document.getElementById("stuff"+ra);
  }
  while (el.style.color==cl)
  el.style.color=cl;
  if (++pos==end) tx_go(start, end, visbl, fg, bg);
  else setTimeout("tx_t3("+start+", "+end+", "+pos+" ,"+visbl+" ,'"+fg+"', '"+bg+"')", 90+start%20);
}

function tx_t4(start, end, pos, visbl, fg, bg) {
  var fgh, bgh, i, col;
  if (fg.substring(0,1)=="#") {
	col="#"
	for (i=1; i<6; i+=2) {
      fgh=parseInt(fg.substring(i, i+2), 16);
      bgh=parseInt(bg.substring(i, i+2), 16);
      col+=oo((visbl)?bgh+(pos/(end-1))*(fgh-bgh):fgh-(pos/(end-1))*(fgh-bgh));
	}
  }
  else {
	col="rgb(";
	fgh=fg.substring(4, fg.length-1).split(",");
	bgh=bg.substring(4, bg.length-1).split(",");
    for (i=0; i<3; i++) col+=Math.floor((visbl)?parseInt(bgh[i])+(pos/(end-1))*(fgh[i]-bgh[i]):fgh[i]-(pos/(end-1))*(fgh[i]-bgh[i]))+", ";
	col=col.substring(0, col.length-2)+")";
  }
  for (i=start; i<start+end; i++) document.getElementById("stuff"+i).style.color=col;
  if (++pos==end) tx_go(start, end, visbl, fg, bg);
  else setTimeout("tx_t4("+start+", "+end+", "+pos+" ,"+visbl+" ,'"+fg+"', '"+bg+"')", 90+start%20);
}

function tx_t5(start, end, pos, visbl, fg, bg) {
  var el, fgh, bgh, i, col;
  if (fg.substring(0,1)=="#") {
	col="#"
	for (i=1; i<6; i+=2) {
      fgh=parseInt(fg.substring(i, i+2), 16);
      bgh=parseInt(bg.substring(i, i+2), 16);
      col+=oo(bgh+(fgh-bgh)/2);
	}
  }
  else {
	col="rgb(";
	fgh=fg.substring(4, fg.length-1).split(",");
	bgh=bg.substring(4, bg.length-1).split(",");
    for (i=0; i<3; i++) col+=Math.floor(parseInt(bgh[i])+(fgh[i]-bgh[i])/2)+", ";
	col=col.substring(0, col.length-2)+")";
  }
  el=document.getElementById("stuff"+(start+pos));
  el.style.color=((pos<(end-1)/2)?col:((visbl)?fg:bg));
  el=document.getElementById("stuff"+(start+end-pos-1));
  el.style.color=((pos<(end-1)/2)?col:((visbl)?fg:bg));
  if (++pos==end) tx_go(start, end, visbl, fg, bg);
  else setTimeout("tx_t5("+start+", "+end+", "+pos+" ,"+visbl+" ,'"+fg+"', '"+bg+"')", 90+start%20);
}

function oo(o) { o=Math.floor(o); return (((o<16)?"0":"")+o.toString(16)); }

function validateEmail(el) {
  var re=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/;
  if (!re.test(el.value)) {
    alert('Please enter a valid e-mail address');
    el.focus();
    return false;
  }
  else return true;
}

function getPageLeft(el) {
  var x=0;
  do {
    x+=el.offsetLeft;
    el=el.offsetParent;
  }
  while (el!=null);
  return x;
}

function getPageTop(el) {
  var y=0;
  do {
    y+=el.offsetTop;
    el=el.offsetParent;
  }
  while (el!=null);
  return y;
}

// background colour changer
var td=0;
function bg(thi, col) { 
  if (!col || col.substring(0,1)=="#") { // historical legacy support
	if (!col) col="transparent";
	thi.style.backgroundColor=col;
  }
  else {
	  if (!thi.parentNode.getAttribute('id')) thi.parentNode.setAttribute('id', 'backgroove'+td++);
	  thi.parentNode.style.backgroundImage='url(/images/edge'+col+'.gif)';
	  if (col.indexOf('trs')!=-1) setTimeout("if(document.getElementById('"+thi.parentNode.getAttribute('id')+"').style.backgroundImage.indexOf('trs')!=-1)document.getElementById('"+thi.parentNode.getAttribute('id')+"').style.backgroundImage='none'", 360);
  }
}

// banner rotation code
function v(w){if(w<u.length){document.getElementById("t").src=z(u[w++]);setTimeout("v("+w+")",4567);}}
function z(y){y="iuuq;00"+unescape(y);var x,s="";for(x=0;x<y.length;x++)s+=String.fromCharCode(y.charCodeAt(x)-1);return s;}

