So, it's unlikely this will solve your problem, since you seem competent enough to know how to do this, posted no real code to actually asses the problem, and I can't figure out exactly which facebook API you're using, BUT-
Can't you just capture the click event and the width of the iframe or whatever it is and just compare the offsets? Something like -
$("#social-container").click(function(e){
var facebookSelector = $( iframe selector here );
var iframeHeight = facebookSelector.height();
var iframeWidth = facebookSelector.width();
var winHeight = $(window).height();
var winWidth = $(window).width();
if ( e.clientY && e.clientX ){
//Set the top based on where mouse click occured
if ( e.clientY > (winHeight-iframeHeight) ){
facebookSelector[0].style.top = winHeight-iframeHeight + "px";
}
else {
facebookSelector.style.top = e.clientY + "px";
}
//Set the left based on where mouse click occured
if ( e.clientX > (winWidth-iframeWidth) ){
facebookSelector[0].style.left = winWidth-iframeWidth + "px";
}
else {
facebookSelector[0].style.left = e.clientX + "px";
}
}
}
The above example less verbose-
$("#social-container").click(function(e){
var facebookSelector = $( iframe selector here );
var h = $(window).height() - facebookSelector.height();
var w = $(window).width() - facebookSelector.width();
if ( e.clientY && e.clientX ){
//Set the top based on where mouse click occured
facebookSelector[0].style.top = ( e.clientY > h ) ? h + "px" : e.clientY + "px";
//Set the left based on where mouse click occured
facebookSelector[0].style.left = ( e.clientX > w ) ? winWidth-iframeWidth + "px" : e.clientX + "px";
}
}
You could also use the position of the facebook like button instead of the click location (or whatever you want, really).
Caveats and Addendums:
1. This won't work so easily if the id of your iframe (or whatever) is being dynamically generated by facebook and you have no control over it
2. This won't work so easily if the Like button is in the iframe and prevents event bubbling up to your container.
3. This example currently requires jQuery.
4. Your iframe (or whatever) must be position: absolute
or position: fixed