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)";
	el=shadow(el);
	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;
  }
  linkify_ww();
}}

function linkify_ww() { // add 'ww' to page links
 var ww=468;
 if (document.documentElement && document.documentElement.clientWidth) ww=document.documentElement.clientWidth;
 else if (typeof(self.innerHeight)=="number") ww=self.innerWidth;
 else if (document.body.clientWidth) ww=document.body.clientWidth;
 if (ww>468) {
   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.indexOf('?')==-1?'?':'&')+'ww='+ww;
   }
 }
}

function shadow(el) {
  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 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;
}

// popup generator used on mindex and some music pages (move to these pages only)
function tx_popUp(mylink, windowname, width, height) { 
  var mywin, href;
  if (typeof(mylink)=='string') href=mylink;
  else href=mylink.href;
  href+=(href.indexOf("?")==-1)?"?t=":"&t=";
  href+=escape(self.location.pathname);
  mywin=window.open(href , windowname, 'width='+width+',height='+height+',scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0');
  if (mywin && !mywin.opener) mywin.opener=self;
  if (mywin && mywin.opener==self) {
    mywin.focus();
    return false;
  }
  else return true;
}

// 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;}
