function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function init(){
	
	// Set the style for images within the COPY div based on their alignment
	var copy = document.getElementById('content');
	if(copy){
		var images = copy.getElementsByTagName('IMG');
		for(var i=0;i<images.length;i++){
			var align = images[i].getAttribute('align');
			if((align == 'left')||(align == 'right')){
				//images[i].setAttribute('align', '');
				images[i].setAttribute('className', align);
				images[i].setAttribute('class', align);
			}
		}
		
		// Find Anchors with the "imagelink" class and set them up for lightbox
		var anchors = copy.getElementsByTagName('A');
		for(var i=0;i<anchors.length;i++){
			if(anchors[i].className == 'imagelink'){
				anchors[i].setAttribute('rel', 'lightbox[set]');
			}
		}
		
		// Add a self focus to the global search
		var search = document.getElementById('s');
		if(search){
			search.onfocus = function(){
				this.select();	
			}
		}
	}
}

addLoadEvent(init);

startTopList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace("over", "");
				}
			}
		}
	}
}

addLoadEvent(startTopList);

var images = new Array();
var current = 0;
var imageSwitch = 0;

function rotator(){
	var count=0; 
	var exists = true;
	while(exists){
		if(document.getElementById('img-'+count)){
			images[count] = document.getElementById('img-'+count);
			count++;
		} else {
			exists = false;
		}
	}
	current = images.length-1;
	if(current > 0){
		setTimeout("fadeOut()", 5000);
	}
}

addLoadEvent(rotator);

function fadeOut(){
	if(imageSwitch == 1){
		for(var i=0;i<=(images.length-1);i++){
			Effect.Appear('img-'+i);
		}
		imageSwitch = 0;
	}
	var myID = 'img-'+current;
	Effect.Fade(myID);
	if(current > 0){
		current--;
		setTimeout("fadeOut()", 6000);
	} else {
		current = images.length-1;
		Effect.Appear('img-'+(images.length-1));
		setTimeout("fadeOut()", 6000);
		imageSwitch = 1;
	}
}