function doPopup() {
	if (!document.getElementsByTagName) return false;
	var aLinks = document.getElementsByTagName("a");
	for (var i=0; i < aLinks.length; i++) {
		if (aLinks[i].className.match("popup")) {
			//add onclick code
			var regex = /.(jpg)|(gif)|(jpeg)|(png)|(bmp)$/i;
			if (aLinks[i].href.match(regex)){
				//it is a link direct to an image
				//alert('match ' + aLinks[i].href);
				aLinks[i].onclick = function() {
					var sWidth 		= this.getAttribute('w') ? ',width=' + (parseInt(this.getAttribute('w')) + 30) : '';
					var sHeight 	= this.getAttribute('h') ? ',height=' + (parseInt(this.getAttribute('w')) + 50) : '';
					var sTitle		 	= this.getAttribute('title') ? '&t=' + this.getAttribute('title') : '';
					window.open('/image.cfm?i=' + this.href + sTitle,'','toolbar=0,resizable=1,menubar=0,scrollbars=1'+sWidth+sHeight);
					return false;
				}//func
			}else{
				//is not a link to an image
				aLinks[i].onclick = function() {
					var sWidth 		= this.getAttribute('w') ? ',width=' + this.getAttribute('w') : '';
					var sHeight 	= this.getAttribute('h') ? ',height=' + this.getAttribute('h') : '';
					window.open(this.href,'','toolbar=0,resizable=1,menubar=0,scrollbars=1'+sWidth+sHeight);
					return false;
				}//func
			}//if
		}//if
	}//for
}//func


/***** WINDOW ONLOADER ****/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


/*
////////////////
	Processes the elements adding corner heads and footers within given id based on groups of groupClass
	Sequentially applies corner styles to the blocks, sneeks a look at the next sibling to get the bg color
////////////////
*/
function processCorners(containingElmId,groupClass,bDirection) {
	if(!document.getElementsByClassName) return false;
	var aBlocks = document.getElementsByClassName(groupClass,containingElmId);
	var ctr = 0;
	var iRadius = 4;
	if(bDirection == null) bDirection = true;//Overlaps go down, hard to explain but is the visual stacking thing
	//dbg.h('processCorners(' + containingElmId + ',' + groupClass + ',' + bDirection +')');
	//dbg.p('Got ' + aBlocks.length + ' ' + groupClass);
		
	aBlocks.each(
		function(block,idx){
			var children = Element.immediateDescendants(block);
			//dbg.h(groupClass + ' : ' + idx);
			children.each(
				function(child,idx){
					//	set rounding rules for each child.
					//dbg.h(idx + ':' + children.length + '  [' + child.id + '] ' + child.className);
					//get my bg colour
					var myBgCol = get_current_style(child,"background-color","transparent");
					
					if(idx == 0){
						//first, always against white (round top)
						//dbg.p('First');
						AddRounded(child,'#ffffff', myBgCol, iRadius, iRadius, true);
					}
					if(idx == children.length-1){
						//last one always against white (round bottom)
						//dbg.p('Last');
						AddRounded(child,'#ffffff', myBgCol, iRadius, iRadius, false);
					}
					if(children.length > 1){
						//middles, we need to get the background of our next or previous sibling
						//dbg.p('Round ' + bDirection);
						if(bDirection){
							if(idx != children.length-1){
								//higher divs on top (round bottom effect) : Unless we are the last
								//dbg.p('Round ' + (bDirection ? 'bottom' : 'top'));
								AddRounded(child,get_current_style(children[idx+1],"background-color","transparent"), myBgCol, iRadius, iRadius, false);
							}
						}else{
							if(idx != 0){
								//lower divs on top (round top effect) : Unless we are first
								//AddRounded(child,'#ffffff', get_current_style(child,"background-color","transparent"), iRadius, iRadius, true);
								//dbg.p('my bg : ' + get_current_style(child,"background-color","transparent") + ', bg prevSib : ' + get_current_style(children[idx-1],"background-color","transparent"));
								AddRounded(child,get_current_style(children[idx-1],"background-color","transparent"), myBgCol, iRadius, iRadius, true);
							}
						}
					}//if
				}//func
			);//each
		}//func
	);//each
	//dbg.p('//end');
}//end func



addLoadEvent(function() {
  /* more code to run on page load */ 
	doPopup();
	processCorners('sidebar','level2',false);
	processCorners('content','block',true);
	processCorners('banner','block',true);
	processCorners('sidebar','block',false);
});