//Local Variable with Flash Content id. default = flashcontent
var as_swf_name = "flashcontent";
var title;
var firstname;
var game;
var desc;

//Initialize Facebook
function fbInit(pAsSwfName,pApi_key,pReceiver){
  as_swf_name = pAsSwfName;
  FB.init(pApi_key,pReceiver);
}
 

//JavaScript Connect methods
function login(){
  FB.Connect.requireSession( onLoginHandler );
}

function showPermission(){
	FB.Connect.showPermissionDialog("publish_stream");
}

function postScore(ptitle,pgame){
	title = ptitle;
	game = pgame;
	FB.Connect.ifUserConnected(onLoginHandler,login)
}

function onLoginHandler(){ 
    FB.Facebook.apiClient.users_getInfo(FB.Facebook.apiClient.get_session().uid,'first_name',getFirstNameResult);
}

function getFirstNameResult (result, ex){
    firstname = result[0].first_name;
	postToStream();
}

function postToStream(){
  var attachment = {'media':[{'type':'image','src':'http://www.quittersarcade.com/facebook/images/game'+game+'.jpg','href':'http://www.quittersarcade.com'}]}; 
  FB.Connect.streamPublish(title.split("{name}").join(firstname) , attachment);
}
 
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]();
  }
}