/*	--------------------------------------------------------------------------------
	Dependencies:
		prototype/prototype.js
	--------------------------------------------------------------------------------
*/

// --------------------------------------------------------------------------------
// Remarks:
// This class implements a simple way to tweet, post to twitter via a URL
// http://twitter.com/home?source=ropemarks&status=%22bla die bla%22 - http%3A%2F%2Fropemarks.com%2Ftw%2F%3FXXX %23RopeMarks %23NSFW
// 
var SimpleTwitter = Class.create();

SimpleTwitter.TWITTER_HOME		= "http://twitter.com/home";
SimpleTwitter.URI_ARG_SOURCE	= "source";
SimpleTwitter.URI_ARG_STATUS	= "status";

SimpleTwitter.prototype =  
{
	// --------------------------------------------------------------------------------
	// Private section
	// --------------------------------------------------------------------------------
	
	//
	// %22 = "
	// %3A = :
	// %2F = /
	// %23 = #
	// escape, url encode a string.
	//
	__buildUri: function( /* string */ message, /* string */ uriToMedia )
	{
		//alert( "__buildUri( '" + message + "', '" + uriToMedia + "' )" );
		var uri = 
			SimpleTwitter.TWITTER_HOME + 
			"?" + SimpleTwitter.URI_ARG_SOURCE	+"=" + "RopeMarks" + 
			"&" + SimpleTwitter.URI_ARG_STATUS	+ "=" + escape( message + " " +  uriToMedia + " #RopeMarks #NSFW" )
		;
		//alert( uri );
		return uri;
	},
	
	// --------------------------------------------------------------------------------
	// Public section
	// --------------------------------------------------------------------------------

	// --------------------------------------------------------------------------------
	// --------------------------------------------------------------------------------
	
	initialize: function()
	{
		//alert( "initialize()" );
		this.name = "SimpleTwitter";
	}, 
	
	// --------------------------------------------------------------------------------
	// --------------------------------------------------------------------------------
	
	tweetUri: function( /* string */ message, /* string */ uriToMedia)
	{
		//alert( "tweetUri( '" + message + "', '" + uriToMedia + "' )" );
		return this.__buildUri( message, uriToMedia );
	},
	
	tweetThis: function( /* string */ uri )
	{
		// Navigate to the URI in a new window
		window.open( uri, "Twitter" );		
	}//,
	
} // SimpleTwitter.prototype





// --------------------------------------------------------------------------------
// Support functions
// --------------------------------------------------------------------------------

function TweetThis( /* string */ message, /* string */ uriToMedia )
{
	//alert( "TweetThis( '" + message + "', '" + uriToMedia + "' )" );
	
	var twitter = new SimpleTwitter();
	var uri = twitter.tweetUri( message, uriToMedia );
	twitter.tweetThis( uri );
}

/* EOF */