var FAC = {
	timer : null,
	e : null,
	visible : false,
	
	init : function() {
		var myBody = document.getElementsByTagName('body')[0];		
		if(myBody.attachEvent){
			myBody.attachEvent('onclick', FAC.doHide);
		}
		else if(myBody.addEventListener){
			myBody.addEventListener('click', FAC.doHide, true);
		}
		if(isOpera)	document.getElementById('CafeList').style.overflow = 'auto';
		
		//document.getElementsByTagName('body')[0].attachEvent('onmouseover', FAC.hide);
		return true;
	},
	
	show : function(elm,parent) {
		FAC.e = gI(elm);
//		alert(FAC.e.style.visibility);
		//document.getElementById('searchstring').value =FAC.e.id +'=' + FAC.e.style.visibility;
		
		
		if(FAC.visible==true  && parent.id=='lnkFAC'){
			FAC.doHide();
			return false;
		}
		var ScrollXY = getScrollXY();
		var top = ScrollXY[1];
		var minTop = 100;
		if(checkIt('safari')) minTop = 300;
		if(top<=minTop)top = minTop;
		FAC.e.style.top = (top -300) + 'px';
		window.clearTimeout(FAC.timer);
		FAC.e.style.height=ScrollXY[1]+getSize()[1]-top-100 + 'px';
		FAC.e.style.overflow = 'auto';
		FAC.e.style.visibility = 'visible';
		FAC.visible = true;
		return true;
	},
	
	hide : function(ev) {
		//if(!(ev.srcElement.id=='CafeList'||ev.srcElement.parentElement.id=='CafeList')){
			//alert(ev.parentNode.id);
			FAC.timer = window.setTimeout(FAC.doHide,700);
		//}
		return true;
	},
	doHide : function(ev) {
		//debug
		var hidden = false;
		if(ev!=null&&!ev.srcElement) {
			if(FAC.e!=null) hidden = true;
		}else{
			if(ev==null){if(FAC.e!=null) hidden = true;}
			else {if(ev.srcElement.id!='imgFac') {if(FAC.e!=null) hidden = true;}}
		}
		if(ev!=null) //For FireFox/Opera... clicking on the up/down arrow causes it to dissapear.
			if(ev.target && (ev.target.toString().indexOf('XULElement')>0||ev.target.id=='CafeList'||ev.target.id=='imgFac')) hidden = false;

		if(hidden){
			//alert('hiding');
			FAC.e.style.visibility = 'hidden';
//			FAC.e.style.overflow = 'hidden';
			FAC.visible = false;
		}
	},
	over : function(e) {
		e.style.backgroundColor = '#50452a';
	},
	out : function(e) {
		e.style.backgroundColor = 'transparent';
	},
	gotoCafe : function(locID,langID) {
		//window.location.href='cafes.aspx?LocationID='+locID+'&MenuID=15&MIBEnumID='+langID;
		SelectLocation(locID);
	}
};

window.onload = function(){
FAC.init();

}