var currentColor;

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 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();	
			}
		}
		
		if(document.getElementById){
			
			var o = document.getElementById('o');
			if(o){
				var b = document.getElementById('b');
				var r = document.getElementById('r');
				var g = document.getElementById('g');
				
				var currentColor = b;
				
				var orange = document.getElementById('orange');
				var blue = document.getElementById('blue');
				var red = document.getElementById('red');
				var green = document.getElementById('green');
					
				orange.onmouseover = function(){
					currentColor.style.display = 'none';
					o.style.display = 'block';
					currentColor = o;
				}
				blue.onmouseover = function(){
					currentColor.style.display = 'none';
					b.style.display = 'block';
					currentColor = b;
				}
				red.onmouseover = function(){
					currentColor.style.display = 'none';
					r.style.display = 'block';
					currentColor = r;
				}
				green.onmouseover = function(){
					currentColor.style.display = 'none';
					g.style.display = 'block';
					currentColor = g;	
				}
			}
		}
			
	}
}

addLoadEvent(init);