/**
* SocialShare Static Class.
* Class that provides straight integration with Facebook and Twitter share
* 
* REQUIRES:
* - FACEBOOK: JavaScript Client Library implemented on host HTML (and initialised)
*   see: http://wiki.developers.facebook.com/index.php/JavaScript_Client_Library#Setting_Up_the_JavaScript_Client
*
* - TWITTER: 
*
* @version	1.0
* @since    2010MAR09
* @author	Federico Campo Piombi
*/
function SocialShare()
{
	alert("SocialShare class is not meant to be instantiated. Use 'SocialShare.init' instead");
}

/**
* PROPERTIES
*/
SocialShare._movieID = null;

/**
 * Initialises the SocialShare class and links it to a Flash Movie
 * @param	movieID (String) ID of the flash movie to link with (ActionScript ExternalInterface usage only)
 */
SocialShare.init = function(movieID)
{
	SocialShare._movieID = movieID;
}

/**
* Returns true if initialised with a Flash Movie ID 
*/
SocialShare.isReady = function()
{
	return !(SocialShare._movieID == null);
}

/**
 * FACEBOOK: Publishes a message on the user's stream
 * @param	msgprompt (String) User's message prompt (ie: "What are you thinking?")
 * @param	message (String) User's default message
 */
SocialShare.fbPublishStream = function(msgprompt, message)
{
  FB.ensureInit(function () {
	FB.Connect.streamPublish(message, {}, {}, null, msgprompt, SocialShare._fbPublishStreamCallback);
  });		
}

/**
 * FACEBOOK: Shares a story on the user's stream
 * @param	attachment (Object) JSON object with the attachment info
 * @param	action (Object) JSON object with the action_link info
 * @param	msgprompt (String) User's message prompt (ie: "What are you thinking?")
 * @param	message (String) User's default message
 */
SocialShare.fbShareStream = function(attachment, action, msgprompt, message)
{
  FB.ensureInit(function () {
	FB.Connect.streamPublish(message, attachment, action, null, msgprompt, SocialShare._fbShareStreamCallback);
  });	
}

/**
 * FACEBOOK: Shares a story on a friend's wall
 * @see	SocialShare.fbPublishStreamShare
 */
SocialShare.fbPublishFriendWall = function(friendID, story, action, msgprompt, message)
{
  FB.ensureInit(function () {
	FB.Connect.streamPublish(message, story, action, friendID, msgprompt, SocialShare._fbPublishStreamCallback);
  });	
}
SocialShare._fbPublishStreamCallback = function(post_id, exception)
{
  var movie = SocialShare._getMovie();
  if(movie != null){ movie._SSCallback("FB.PublishStream,"+post_id+","+exception); };
}
SocialShare._fbShareStreamCallback = function(post_id, exception)
{
  var movie = SocialShare._getMovie();
  if(movie != null){ movie._SSCallback("FB.ShareStream,"+post_id+","+exception); };
}

/** 
 * FACEBOOK: Shares a link to the user's stream
 * @param	url (String) URL of the link to share
 */
SocialShare.fbShareLink = function(url)
{
  FB.ensureInit(function () {
	FB.Connect.showShareDialog(url, SocialShare._fbShareLinkCallback);
  });
}
SocialShare._fbShareLinkCallback = function()
{
  var movie = SocialShare._getMovie();
  if(movie != null){ movie._SSCallback("FB.ShareLink,null,null"); } //link sharing does not return status info
}


/**
* PRIVATE METHODS
*/
SocialShare._getMovie = function()
{
	return (navigator.appName.indexOf("Microsoft") != -1) ?	window[SocialShare._movieID] : document[SocialShare._movieID];
}
