//Local Variable with Flash Content id. default = flashcontent
var as_swf_name = "flashcontent";
 
//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 );
  //alert("FB.Connect.requireSession( onLoginHandler );");
}
 
//Event Handlers
function onLoginHandler(){
  flashCallBack( "onLogIn" );
}
 
//Method to dispatch an Event to Flash
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]();
  }
}

//logout stuff
function logout()
{
	FB.Connect.logout( onLogout );
}
function onLogout()
{
	flashCallBack( "onLoggedOut" );
}

function postToFacebook(mouthtrap){
	//alert('facebook');
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent('http://www.jigsawsgame.com/?s=1&mouthtrap=' + mouthtrap),'sharer','toolbar=0,status=0,width=626,height=436');
	//window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent('http://www.jigsawsgame.com/'),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function prePostToFacebook(player){
	//alert('facebook');
	//window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent('http://www.jigsawsgame.com/?mouthtrap=' + mouthtrap),'sharer','toolbar=0,status=0,width=626,height=436');
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent('http://www.jigsawsgame.com/?pre_name=' + player),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function postToTwitter(mouthtrap){
	window.open("http://twitter.com/home?status=I just survived Jigsaw's Game and escaped from his head trap. Can you? Play Jigsaw's Game: http://www.jigsawsgame.com/",'sharer','toolbar=0,status=0,width=780,height=570');
	return false;
}
