var as_swf_name = "flashcontent";

function fbInit(pAsSwfName,pApi_key,pReceiver){
	as_swf_name = pAsSwfName;
	FB.init(pApi_key,pReceiver);
}

function flashCallBack ( func ) {
	if( arguments.length > 1 ){
		document[as_swf_name][func]( Array.prototype.slice.call(arguments).slice(1)[0]);
	}else{
		document[as_swf_name][func]();
	}
}

function login(){
	FB.Connect.requireSession( onLoginHandler );
}

function logout(){
	 FB.Connect.logout();
}


function onLoginHandler(){
	var api = FB.Facebook.apiClient;
	document[as_swf_name].onLogIn(api.get_session().session_key, api.get_session().uid, api.get_session().sig)
}

function streamPublish(id){
	var attachment = {
		"name": "The Busy Fiddler",
		"caption": "{*actor*} has created a personalized music video",
		"href": "http://www.fiddleafriend.com/?id="+id,
		"description": "The Busy Fiddler is spreading the word about career success. Monster.com helped the Busy Fiddler find the right job for him. We can help you find yours too. www.fiddleafriend.com",
		"media": [{"type": "image", "src": "http://www.fiddleafriend.com/images/beaver_90x59.jpg", "href": "http://www.fiddleafriend.com/?id="+id}]
	};
	var actionLinks = [{"text": "Fiddle a Friend", "href": "http://www.fiddleafriend.com/"}];
	FB.Connect.streamPublish('',attachment,actionLinks); 
}

function postToTwitter(id){
	LeftPosition = (screen.width) ? (screen.width-780)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-570)/2 : 0;
	window.open('http://twitter.com/home?status='+encodeURIComponent('I just created a personalized music video featuring the Busy Fiddler, check it out here: http://www.fiddleafriend.com/?id='+id),'sharer','toolbar=0,scrollbars=1,status=0,width=780,height=570,top='+TopPosition+',left='+LeftPosition);
	return false;
}