var isSafari3 = false;
if( window.devicePixelRatio && window.getMatchedCSSRules && !window.Opera)
{ isSafari3 = !!window.getMatchedCSSRules(document.documentElement,'');
} 


var CONTENT_CONTAINER = 'ibmarcontent';

//UTILITY
function isIE() {
	return document.all && !window.opera ? true : false;
}
function isIE7() {
	return isIE() && document.documentElement && typeof document.documentElement.style.maxHeight != "undefined" ? true : false;
}
function islteIE6() {
	return (document.all && !window.opera) && !(document.documentElement && typeof document.documentElement.style.maxHeight != "undefined") ? true : false;
}
function up(srcEl, tag) {
	var _el = srcEl;
	while(_el.tagName != tag.toUpperCase()) { _el = _el.parentNode; }	
	return _el;
}


//HOVERS
function attachTableHovers(){
	if(!document.getElementById(CONTENT_CONTAINER)) {
		return;
	}
	//handle table data cells
	var _tablecells = document.getElementById(CONTENT_CONTAINER).getElementsByTagName('td');
	var _isFinTable = true;
	for (var i = 0; i < _tablecells.length; i++) {
		var _cell = _tablecells[i];
		if(_cell._col == null) {
			//get the table (only need financial tables)	
			var _table = up(_cell, 'table');
			if(_table.className.indexOf('financials') == -1) {
				_isFinTable = false;
			} else {
				//get the col ... will be same index as the cell
				var _col = _table.getElementsByTagName('col')[_cell.cellIndex];
				//store orig class strings for col and cell
				if(_col._className == null) {
					_col._className = _col.className;
				}
				_cell._className = _cell.className;
				//store ref to col on table cell
				_cell._col = _col;
			}
		}
		if(_isFinTable) {
			//attach events	
			_cell.onmouseover = function() {
				//do hover on the cell (lte IE6 only)
				if(islteIE6()) {
					this.className = this._className + ' hover_';					
				}
				this._col.className = this._col._className + ' hover_';
			}
			_cell.onmouseout = function() {
				//remove hover on the cell (lte IE6 only)
				if(islteIE6()) {
					this.className = this._className;
				}
				this._col.className = this._col._className;
			}			
		}
	}
	//handle table rows (lte IE6 only)
	if(_isFinTable && islteIE6()) {
		var _tablerows = document.getElementById(CONTENT_CONTAINER).getElementsByTagName('tr');
		for (var i = 0; i < _tablerows.length; i++) {
			var _row = _tablerows[i];
			//store orig class strings for row
			_row._className = _row.className;
			//attach events	
			_row.onmouseover = function() {
				this.className = this._className + ' hover_';					
			}
			_row.onmouseout = function() {
				this.className = this._className;
			}			
		}		
	}
}



//onload
if(!isSafari3 && navigator.userAgent.indexOf("Opera") == -1){
window.onload = function() {
	attachTableHovers();
}
}