function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function thumbnailSwap(){
	var thumbnailsUL = document.getElementById('thumbnails');
	if(thumbnailsUL){
		var thumbnailsULChildren = new Array();
		for(i=0; i < thumbnailsUL.childNodes.length; i++){
			if(thumbnailsUL.childNodes[i].nodeType != 3){
				thumbnailsULChildren.push(thumbnailsUL.childNodes[i]);
			}
		}

		for(i=0; i < thumbnailsULChildren.length; i++){
			thumbnailA = checkNode(thumbnailsULChildren[i].childNodes[0]);
			if(thumbnailA){
				thumbnailA.onclick = function(){
					var mugshotIMG = document.getElementById('mugshotImage');
					//var imgNew = document.createElement('img');
					mugshotIMG.src = 'images/suspects/' + this.name;
					//mugshotIMG.id = 'mugshotImage';
					//mugshotIMG.parentNode.replaceChild(imgNew,mugshotIMG);
				}
			}
		}
	}
}

function resultsPP(){
	if (document.getElementById('results') != null) {
		var select = document.getElementById('results');
		select.onchange = function(){
			document.getElementById('searchForm').submit();
		}
	}
}

function checkNode(i){
	while(i && i.nodeType == 3){
		i = i.nextSibling;
	}
	return i;
};

function getrss(){
	var oRSS = document.getElementById("whatIsRSS");
	if(!oRSS) return;
	var oContent = document.getElementById("RSSContent");
	oRSS.onclick = function(){
		if(oContent.style.display == "block"){
			oContent.style.display = "none";
		}else{
			oContent.style.display = "block";
		};
	};
};

addLoadEvent(thumbnailSwap);
addLoadEvent(resultsPP);
addLoadEvent(getrss);
