function CTw(parent)
{
	this.parent = parent;
	
	this.name = "tw";
	
	this.reqs = new CReqs(this);
	
	this.username = "";
	
	this.mazeUrl = "";
	
	this.login = function(username)
	{
		this.username = username;
				
		this.parent.auth(1, this);
	}
	
	this.logout = function()
	{
		this.reqs.get("user.logout");
			
		this.parent.auth(0);
	}
		
	this.share = function()
	{
    if(!game.maze.mazeId)
      return;
      
    parent.hide();
    
		//TODO: display the sharing window
		this.parent.message.input("Enter your Twitter message", "Play my Mind Crime maze!", "Maximum length of your message is 100 characters. Maze link <a id=\"share-url\" target=\"_new\"></a> will be appended.", this.shareSubmit);

    this.reqs.post("tw.url", '{"mazeId":'+game.maze.mazeId+'}', "mazeShareUrl");
	}
	
	this.shareSubmit = function(value)
	{
    if(value)
      this.parent.authService.reqs.post("tw.share", '{"status":"'+this.data+" "+game.authService.mazeUrl+'"}');

		this.parent.show();
	}
	
	this.requestCallback = function(type, data)
	{
		switch(type)
		{
			case "mazeShare":
				//TODO: better message
				alert("Maze was shared with your followers.");
			break;

			case "mazeShareUrl":
				//TODO: update sharing message
				//append child or innerHTML + content;
        var shareUrl = gE("share-url");
        if(!shareUrl)
          return;
          
        shareUrl.href = data.url;
        shareUrl.innerHTML = data.url;
        
        this.mazeUrl = data.url;
			break;
		}
	}
	
	this.renderBar = function()
	{
		var content = "";
		
		content += "<a class=\"link\" href=\"javascript:game.authService.logout()\">Logout...</a>";
		content += "<div class=\"username\">"+this.username+"</div>";
		content += "<a class=\"service\" target=\"_blank\" href=\"http://www.twitter.com/\"><img src=\"images/twitter.png\" alt=\"Twitter\" /></a>";
					
		gE('user-bar').innerHTML = content;
	}
}

