/**
 * @class GE_Main
 * @author ed.hicks@frogdesign.com
 */
var GE_Main_Singleton = Class.create( {
	initFns:[],
	mappedFns:{},
	addInitFn:function(fn) {
		this.initFns.push(fn)
	},
	bindFns:function(el) {
		var mFns = this.mappedFns;
		var all = el.getElementsByTagName('*');
		var len = all.length;
		var actions = new Array();
		for (var i=0;i<len;i++) {
			var el = all[i];
			var cns = el.className.split(" ");
			var j = cns.length;
			while(j--) {
				var fn = mFns[ cns[j] ];
				if (fn != null) {
					actions.push({_fn:fn,_el:el});
				}
			}
		}
		len = actions.length;
		for (var i=0;i<len;i++) {
			var obj = actions[i];
			new obj._fn(obj._el);
		}
	},
	mapCSSToFn:function(cssClass, fn) {
		if (this.mappedFns[cssClass]) {
			throw new Error( "GE_mapFnToCSS has already been called for css class '" + cssClass + "'.")
		}
		this.mappedFns[cssClass] = fn;
	},
	initialize:function() {
		//TODO: get rid of all instances of mapFnToCSS across site js (argument order is wrong);
		this.mapFnToCSS = this.mapCSSToFn;

		//to prevent image flicker in IE/6
		try {
			document.execCommand('BackgroundImageCache', false, true);
		} catch(e) {}

		document.observe('dom:loaded', function() {
			for (var i=0; i<this.initFns.length; i++) {
				this.initFns[i]();
			}
			this.bindFns(document);

			//fixes sIFR hasLayout bug
			if (/MSIE/i.test(navigator.userAgent)) {
				if ($('ge_content')) {
					new Insertion.Bottom('ge_content','<div style="clear:both;color:#fff;height:10px;margin:0;padding:0">&nbsp;</div>');
				} else {
					new Insertion.Bottom('content','<div style="clear:both;color:#fff;height:10px;margin:0;padding:0">&nbsp;</div>');
				}
			}

		}.bind(this));
	}
} );
var GE_Main = new GE_Main_Singleton();

function GE_containsElement(el1, el2) {
	if (el2==null) return false;
	var pel = el2.parentNode;
	while(pel != null) {
		if (el1==pel) return true;
		pel = pel.parentNode;
	}
	return false;
}
function GE_detectMouseLeave( srcEl, e ) {
	// relTarg is "where the mouse goes to"
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;

	return ( !GE_containsElement(srcEl, relTarg) );
}
function GE_detectMouseEnter( srcEl, e ) {

	// relTarg is "where the mouse comes from"
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.fromElement;

	return ( !GE_containsElement(srcEl, relTarg) );
}

function GE_pop(url, name, w, h) {
   window.open(url, name,'height='+h+'px,width='+w+'px,menubar=0,scrollbars=1,titlebar=0,resizable=1,toolbar=0,location=0,status=0,directories=0');
}

