Check out the following blog entry, it helped me a great deal while developing something similar
http://alexmarandon.com/articles/web_widget_jquery/
In general, keywords for you are dynamic javascript and css loading and JSON-P that enables getting around browser's same origin policy while sending AJAX requests.