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

function init(){
	
	// Set the style for images within the mainpage div based on their alignment
	var mainpage = document.getElementById('main-page');
	if(mainpage){
		var images = mainpage.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 images with thumbnailsand set them up for lightbox*/
		var anchors = mainpage.getElementsByTagName('A');
		
		for(var i=0;i<anchors.length;i++){
			if(anchors[i].getAttribute('rel') == 'lightbox'){
				anchors[i].setAttribute('rel', 'lightbox[]');
			}
		}
		
		// Add a self focus to the global search
		var search = document.getElementById('s');
		if(search){
			search.onfocus = function(){
				this.select();
			}
		}
	}
}

addLoadEvent(init);