var Famclub = {
	
	script: null,
	timeout: null,
	
	init: function(section) {
		switch(section) {
			case 'minisites':
				this.script = '/famclub/profiles/addMinisite.php';
				break;
			case 'videos':
				this.script = '/famclub/profiles/addVideo.php';
				break;
			case 'games':
				this.script = '/famclub/profiles/addGame.php';
				break;
		}
	},					
	
	addToFamclub: function(id) {
		clearTimeout(this.timeout);
		var messageWindow = $('famclubMessage');
		var messageContent = $('famclubMessageContent');
		messageContent.update('<img src="/images/community/loader_dark_aqua.gif" />&nbsp;&nbsp;Loading...');
		$('famclubMessageClose').update('<a href="javascript:Famclub.closeFamclubMessage();"><img src="/images/community/external_close_famclub.gif" border="0" alt="Close" /></a>');
		new Effect.Appear(messageWindow, {duration:0.3});
		var obj = this;
	
		new Ajax.Request(this.script, {
			method:'post',
			parameters: {id: id},
			onSuccess: function(transport){
				var json = transport.responseText.evalJSON(true);
				var msg = '';
				
				if(json.message) {
					msg = json.message + '<br><br><a href="/famclub/profiles/"><img src="/images/community/visit_famclub.gif" alt="Visit Famclub" border="0" /></a>';
					//msg = json.message + '<br><br><a href="/famclub/profiles/">Visit Famclub</a>';
				} else {
					msg = 'Sorry, we could not add this show to your Famclub.  Please try again.';
				}
				messageContent.update(msg);
				obj.timeout = setTimeout(obj.closeFamclubMessage.bind(obj), 10000);
			},
			onFailure: function(){ 
				messageContent.update('Sorry, we could not add this show to your Famclub.  Please try again.');
			}
		});
	},
	
	closeFamclubMessage: function() {
		clearTimeout(this.timeout);
		new Effect.Fade('famclubMessage', {duration:0.3});
	}
	
};