// addEvent cross-browser event handling for IE5+, NS6 and Mozilla
// By Scott Andrew
function addEvent(elm, evType, fn, useCapture) {	
	if (elm.addEventListener) {
	  elm.addEventListener(evType, fn, useCapture); 
	  return true;
	} else if (elm.attachEvent) {
	  var r = elm.attachEvent('on' + evType, fn);
	  return r;
	} else {
	  elm['on' + evType] = fn;
	}
}

function cancelClick() {
	return false;
}


/**************************************************
 column length adjuster
**************************************************/

var advanstarCols = {

	balloons: new Array(),

	init: function() {
		// if no supported DOM, return
		if (!document.getElementsByTagName || !document.getElementById)
			return;
		  
		// check the body ID and call the resizing function appropriately
		
		var bodyid = document.body.getAttribute('id');
	
		switch(bodyid) {
			case 'v1': 
			case 'v1a': 
				var thecols = new Array('rightaux', 'primary', 'leftaux');
				advanstarCols.matchHeight(thecols, true); break;		
		}
	
	},
	
	// matchHeight - makes the height of multiple CSS columns match
	// the height of the tallest one
	//--------------------------------------------
	// cols: an array of column IDs
	// stylediv: bool value; if true, match the heights of the styledivs 
	// 		instead of the col itself... use if using tables for the cols
	
	matchHeight: function(cols, stylediv) {
		
		var stylediv = (stylediv == undefined) ? false : stylediv;
	
		if(!cols.length || cols.length <= 1) return;
		
		// clear all balloons
		for(var i = 0; i < this.balloons.length; i++) {
			var theb = this.balloons[i];
			theb.parentNode.removeChild(theb);
		}
		this.balloons = new Array();
		
		
		var maxcol;
		var maxheight = 0;
		
		// find out which column is the tallest
		for(var i = 0; i < cols.length; i++) {
		
			var thecol = (stylediv) ? this.getStyleDiv(cols[i]) : document.getElementById(cols[i]);
			

			var theheight = thecol.offsetHeight;
			if(theheight > maxheight) {
				maxheight = theheight;
				maxcol = thecol;
			}
		}
		
		// now make them all the same height
		for(var i = 0; i < cols.length; i++) {
			// only adjust height if it's not the max height column
			if(cols[i] != maxcol.getAttribute('id')) {
				var thecol = (stylediv) ? this.getStyleDiv(cols[i]) : document.getElementById(cols[i]);
				
				var theheight = thecol.offsetHeight;
		
				// create a new DIV element to "inflate" like a balloon and expand the DIV
				// (--> no messing around with the box model)
				
				var balloon = document.createElement('div');
				balloon.style.height = (maxheight - theheight) + 'px';
				balloon.className = 'advanstarBalloon';
		
				if(maxheight - theheight > 0) {
					thecol.appendChild(balloon);
					this.balloons.push(balloon);
				}
			}
		}
	
		return true;
	},
	
	getStyleDiv: function(col) {
		if(!col) return;
		
		var thecol = document.getElementById(col);
		
		var divs = thecol.getElementsByTagName('div');
		
		for(var i = 0; i < divs.length; i++) {
			if(divs[i].className.search(/\bstylediv\b/) != -1)
				return divs[i];
		}
	}

};



// add the onLoad event - also resize
addEvent(window, "load", advanstarCols.init, false);
addEvent(window, "resize", advanstarCols.init, false);
