/* ==============================================================================================
   Copyright (c) 2006 Factor_UE
   www.factorue.com
   Built by Nate Chrysler
============================================================================================== */
/*
	showHover : on mouse over hover help function
	
	o_src: expects to be the object that called this function (usually passed as "this")
	p_css_class: the css class for the hover help div
	p_text: the text contents for the hover help div
*/
function showHover(o_src, p_css_class, p_text) {
	// set up calendar utility object
	if (typeof(o_src.hoverHelpUtility) == "undefined") o_src.hoverHelpUtility = new HoverHelpUtility(o_src, p_css_class, p_text);
	o_src.hoverHelpUtility.show();
}
function hideHover(o_src) {
	if (typeof(o_src.hoverHelpUtility) != "undefined") o_src.hoverHelpUtility.hide();
}

function HoverHelpUtility(o_src, p_css_class, p_text) {
	// setup defaults
	this.source = o_src;
	this.showtimerid = 0;
	this.hidetimerid = 0;
	this.showPause = 1000;
	this.hidePause = 300;
	this.fgZIndex = 3000;
	this.bgZIndex = 2999;
	this.div = null;
	this.backgroundContainer = null;
	// generate name and necessary divs
	this.name = "div_" + (new Date()).valueOf() + "_" + Math.floor(Math.random() * 999999999); // define unique name
	this.setupSource();
	this.setupBrowser();
	this.build(p_css_class, p_text);
	// assign to window to retrieve later
	window[this.name] = this;
}
HoverHelpUtility.prototype.setupSource = function() {
	this.source.onmouseout = function() { hideHover(this); };
}
HoverHelpUtility.prototype.setupBrowser = function() {
	this.isopera = (navigator.userAgent.indexOf("Opera")>=0);
	this.isexplorer = (!this.isopera && navigator.userAgent.indexOf("MSIE")>=0);
	this.issafari = (navigator.userAgent.indexOf("Safari")>=0);
	this.isgecko = (!this.issafari && navigator.userAgent.indexOf("Gecko")>=0);
}
HoverHelpUtility.prototype.build = function(p_css_class, p_text) {
	// create div and set contents
	this.div = document.createElement("DIV");
	this.div.className = p_css_class;
	this.div.innerHTML = p_text;
	this.div.style.position = "absolute";
	this.div.style.visibility = "hidden";
	this.div.style.zIndex = this.fgZIndex;
	this.div.controller = this;
	this.div.onmouseover = function() { this.controller.show(); };
	this.div.onmouseout = function() { this.controller.hide(); };
	document.body.appendChild(this.div);
	// setup iframe
	if (this.isexplorer) {
		this.backgroundContainer = document.createElement("IFRAME");
		var b = this.backgroundContainer;
		b.style.visibility = "hidden";
		b.style.position = "absolute";
		b.style.zIndex = this.bgZIndex;
		b.style.border = "0px";
		b.frameBorder = "0px";
		b.border = 0;
		document.body.appendChild(b);
	}
}
HoverHelpUtility.prototype.isShowing = function() {
	return (this.div.style.visibility == "visible");
}
HoverHelpUtility.prototype.show = function() {
	this.catchHide();
	if (!this.showtimerid) {
		this.showtimerid = window.setTimeout(this.name + ".showNow();", this.showPause);
	}
}
HoverHelpUtility.prototype.showNow = function() {
	// position and show div
	var pos_src = YAHOO.util.Dom.getXY(this.source);
	YAHOO.util.Dom.setXY(this.div, pos_src);
	this.div.style.visibility = "visible";
	this.showBackground(pos_src);
}
HoverHelpUtility.prototype.catchShow = function() {
	if (this.showtimerid) {
		window.clearTimeout(this.showtimerid);
		this.showtimerid = 0;
	}
}
HoverHelpUtility.prototype.hide = function() {
	this.catchShow();
	if (!this.hidetimerid) {
		this.hidetimerid = window.setTimeout(this.name + ".hideNow();", this.hidePause);
	}
}
HoverHelpUtility.prototype.hideNow = function() {
	YAHOO.util.Dom.setXY(this.div, [-1000, 0] );
	this.div.style.visibility = "hidden";
	this.hideBackground();
}
HoverHelpUtility.prototype.catchHide = function() {
	if (this.hidetimerid) {
		window.clearTimeout(this.hidetimerid);
		this.hidetimerid = 0;
	}
}
HoverHelpUtility.prototype.showBackground = function(pos_src) {
	if (this.isexplorer) {
		this.backgroundContainer.style.visibility = "visible";
		this.backgroundContainer.style.width = this.div.offsetWidth;
		this.backgroundContainer.style.height = this.div.offsetHeight;
		YAHOO.util.Dom.setXY(this.backgroundContainer, pos_src);
	}
}
HoverHelpUtility.prototype.hideBackground = function(pos_src) {
	if (this.isexplorer) {
		this.backgroundContainer.style.visibility = "hidden";
		YAHOO.util.Dom.setXY(this.div, [-1000, 0] );
	}
}



if (typeof(YAHOO) == "undefined") {
	YAHOO = { util: {} };
	YAHOO.util.Dom = function() {
		var ua = navigator.userAgent.toLowerCase();
		var isOpera = (ua.indexOf('opera') != -1);
		var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
		var isGecko = (ua.indexOf('gecko') != -1);
		var id_counter = 0;
		
		return {
			isExplorer: function() {
				return isIE;
			},
			isOpera: function() {
				return isOpera;
			},
			isGecko: function() {
				return isGecko;
			},
			getXY: function(el) {
				 // has to be part of document to have pageXY
				if (el.parentNode === null || this.getStyle(el, 'display') == 'none') {
				   return false;
				}
				
				var parent = null;
				var pos = [];
				var box;
				
				if (el.getBoundingClientRect) { // IE
				   box = el.getBoundingClientRect();
				   var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
				   var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
				   
				   return [box.left + scrollLeft, box.top + scrollTop];
				}
				else if (document.getBoxObjectFor) { // gecko
				   box = document.getBoxObjectFor(el);
				   
				   var borderLeft = parseInt(this.getStyle(el, 'borderLeftWidth'));
				   var borderTop = parseInt(this.getStyle(el, 'borderTopWidth'));
				   
				   pos = [box.x - borderLeft, box.y - borderTop];
				}
				else { // safari & opera
				   pos = [el.offsetLeft, el.offsetTop];
				   parent = el.offsetParent;
				   if (parent != el) {
					  while (parent) {
						 pos[0] += parent.offsetLeft;
						 pos[1] += parent.offsetTop;
						 parent = parent.offsetParent;
					  }
				   }
				   if (
					  ua.indexOf('opera') != -1 
					  || ( ua.indexOf('safari') != -1 && this.getStyle(el, 'position') == 'absolute' ) 
				   ) {
					  pos[0] -= document.body.offsetLeft;
					  pos[1] -= document.body.offsetTop;
				   } 
				}
				
				if (el.parentNode) { parent = el.parentNode; }
				else { parent = null; }
			
				while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') 
				{ // account for any scrolled ancestors
				   pos[0] -= parent.scrollLeft;
				   pos[1] -= parent.scrollTop;
			
				   if (parent.parentNode) { parent = parent.parentNode; } 
				   else { parent = null; }
				}
			
				return pos;
			},
			setXY: function(el, pos) {
				var style_pos = this.getStyle(el, 'position');
				if (style_pos == 'static') { // default to relative
				   this.setStyle(el, 'position', 'relative');
				   style_pos = 'relative';
				}
				
				var pageXY = YAHOO.util.Dom.getXY(el);
				if (pageXY === false) { return false; } // has to be part of doc to have pageXY
				
				var delta = [
				   parseInt( YAHOO.util.Dom.getStyle(el, 'left'), 10 ),
				   parseInt( YAHOO.util.Dom.getStyle(el, 'top'), 10 )
				];
			 
				if ( isNaN(delta[0]) ) // defaults to 'auto'
				{ 
				   delta[0] = (style_pos == 'relative') ? 0 : el.offsetLeft;
				} 
				if ( isNaN(delta[1]) ) // defaults to 'auto'
				{ 
				   delta[1] = (style_pos == 'relative') ? 0 : el.offsetTop;
				} 
		  
				if (pos[0] !== null) { el.style.left = pos[0] - pageXY[0] + delta[0] + 'px'; }
				if (pos[1] !== null) { el.style.top = pos[1] - pageXY[1] + delta[1] + 'px'; }
		  
				var newXY = this.getXY(el);
			},
			getStyle: function(el, property) {
				var value = null;
				var dv = document.defaultView;
				
				if (property == 'opacity' && el.filters) 
				{// IE opacity
				   value = 1;
				   try {
					  value = el.filters.item('DXImageTransform.Microsoft.Alpha').opacity / 100;
				   } catch(e) {
					  try {
						 value = el.filters.item('alpha').opacity / 100;
					  } catch(e) {}
				   }
				}
				else if (el.style[property]) 
				{
				   value = el.style[property];
				}
				else if (el.currentStyle && el.currentStyle[property]) {
				   value = el.currentStyle[property];
				}
				else if ( dv && dv.getComputedStyle )
				{  // convert camelCase to hyphen-case
				   
				   var converted = '';
				   for(var i = 0, len = property.length;i < len; ++i) {
					  if (property.charAt(i) == property.charAt(i).toUpperCase()) 
					  {
						 converted = converted + '-' + property.charAt(i).toLowerCase();
					  } else {
						 converted = converted + property.charAt(i);
					  }
				   }
				   
				   if (dv.getComputedStyle(el, '') && dv.getComputedStyle(el, '').getPropertyValue(converted)) {
					  value = dv.getComputedStyle(el, '').getPropertyValue(converted);
				   }
				}
			
				return value;
			},
			setStyle: function(el, property, val) {
				switch(property) {
				   case 'opacity' :
					  if (isIE && typeof el.style.filter == 'string') { // in case not appended
						 el.style.filter = 'alpha(opacity=' + val * 100 + ')';
						 
						 if (!el.currentStyle || !el.currentStyle.hasLayout) {
							el.style.zoom = 1; // when no layout or cant tell
						 }
					  } else {
						 el.style.opacity = val;
						 el.style['-moz-opacity'] = val;
						 el.style['-khtml-opacity'] = val;
					  }
		
					  break;
				   default :
					  el.style[property] = val;
				}
			}
		}
	}();
}

