/*********************************************************************
 * No onMouseOut event if the mouse pointer hovers a child element 
 * *** Please do not remove this header. ***
 * This code is working on my IE7, IE6, FireFox, Opera and Safari
 * 
 * Usage: 
 * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
 *		So many childs 
 *	</div>
 *
 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/
function is_child_of(parent, child) {
    if( child != null ) {			
    	while( child.parentNode ) {
    		if( (child = child.parentNode) == parent ) {
    			return true;
    		}
    	}
    }
    return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
    var current_mouse_target = null;
    if( event.toElement ) {				
    	current_mouse_target 			 = event.toElement;
    } else if( event.relatedTarget ) {				
    	current_mouse_target 			 = event.relatedTarget;
    }
    if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
    	eval(JavaScript_code);
    }
}
/*********************************************************************/
var FANTASY = false;
	
var resFollowUser = function(t) {
    alertMe('Follower!', t.responseText);
    if ($('followButton') != null) {
    	if ($('followButton').innerHTML == 'FOLLOW') {
    		$('followButton').innerHTML = 'UNFOLLOW';
    	} else {
    		$('followButton').innerHTML = 'FOLLOW';
    	}
    }
}

function followUser(uid,type) {
	var sendVals = 'FID='+escape(uid)+'&TYPE='+escape(type);
	new Ajax.Request('/classes/Following.php', {method:'post', postBody:sendVals, onComplete:resFollowUser});
}

var xPosFO = 0;
var yPosFO = 0;
function activateFlyout(id,uid,alias,img,imgW,type) {

	xPosFO = findPosX($(id));
	yPosFO = findPosY($(id));
	
	var bod = document.getElementsByTagName('body').item(0);
	
	var fOut = document.createElement("div");
	fOut.setAttribute('id', 'flyOutBox');
	fOut.className = 'flyOut';
	fOut.style.left = (xPosFO - Math.ceil((100-imgW)/2))+'px';
	fOut.style.top = (yPosFO - Math.ceil((100-imgW)/2))+'px';
	var add = '';
	if (FANTASY) {
		add = ' <a href="javascript: fantasyBet('+uid+');"><img src="/icn/bet_fo.jpg" width="40" height="20" border="0" /></a>'
	}
	fOut.innerHTML = '<div onMouseOut="fixOnMouseOut(this, event, \'removeFlyout()\');"><div><a href="'+alias+'"><div class="imgPart" style="background: url(\''+img+'\') no-repeat;"></div></a></div><div style="padding: 2px;"><a href="javascript: followUser(\''+uid+'\','+type+');"><img src="/icn/plus_fo.gif" alt="Follow Me" title="Follow Me" width="20" height="20" border="0" /></a>'+add+'</div></div>';
	
	bod.appendChild(fOut);
}

function removeFlyout() {
	document.getElementsByTagName('body').item(0).removeChild($('flyOutBox'));
}
