var FMASC = new Object;
FMASC = {
	
	
	// Keeps template url location url, for ajax call
	template_url: '',
	
	// Ajax memory
	ajax: $H({ }),
	
	
	/**
	 * Show comments
	 */
	showComments: function(postID, fallbackUrl) {
		// Is on fallback page
		if (document.location == fallbackUrl) {
			return;
		}
		// Abort any old ajax call
		if (typeof this.ajax['showComments_'+ postID] == "object") {
			this.ajax['showComments_'+ postID].transport.abort();
		}
		// Is visible, hide
		if ($('post-'+ postID +'-comments-container-inner').visible()) {
			new Effect.SlideUp('post-'+ postID +'-comments-container-inner', { duration:'0.5' });
			return;
		}
		// Show container (and loading)
		$('post-'+ postID +'-comments-container').show();
		$('post-'+ postID +'-comments-loading').show();
		// Call ajax
		var url = this.template_url +"/ajax.php";
		var parameterValues = { 'action':'showComments', 'postID':postID };
		this.ajax['showComments_'+ postID] = new Ajax.Request(url, {
			method: 'post',
			parameters: parameterValues,
			onSuccess: this.__showCommentsSuccess.bindAsEventListener(this, fallbackUrl),
			onFailure: this.__showCommentsFailure.bindAsEventListener(this, fallbackUrl)
		});
	},	
	
	/**
	 * Show comments - Success (called by Ajax)
	 */
	__showCommentsSuccess: function(transporter, fallbackUrl) {
		// Get json data
		var json = transporter.responseText.evalJSON(true);
		// Hide loading
		$('post-'+ json['post_ID'] +'-comments-loading').hide();
		// All ok
		if (json['status'] == 1) {
			// Update html
			$('post-'+ json['post_ID'] +'-comments-container-inner').update(json['html']);
			// Animate out (only first time, or if not visible)
			if (!$('post-'+ json['post_ID'] +'-comments-container-inner').visible()) {
				new Effect.SlideDown('post-'+ json['post_ID'] +'-comments-container-inner', { duration:'0.5' });
			}
		}
		// Error
		else {
			this.__showCommentsFailure(transporter, fallbackUrl);
		}
	},
	
	/**
	 * Show comments - Error (called by Ajax)
	 */
	__showCommentsFailure: function(transporter, fallbackUrl) {
		document.location = fallbackUrl;
	},
	
	
	/**
	 * Menu option - Show projects
	 */
	showMenu: function(content, fallbackUrl) {
		// Abort any old ajax call
		if (typeof this.ajax['menu-'+ content] == "object") {
			this.ajax['menu-'+ content].transport.abort();
		}
		// This menu is already visible
		if ($('menu-extender').hasClassName('menu-'+ content)) {
			// Clean, hide and return
			this.__cleanMenuClass();
			new Effect.SlideUp('menu-extender', { duration:'0.2' });
			return;
		}
		// Start loading
		$('header-menu.loading').show();
		//new Effect.Appear('header-menu.loading', { duration:'0.3' });
		// Clean
		this.__cleanMenuClass();
		// Hide old menu
		if ($('menu-extender').visible()) {
			new Effect.SlideUp('menu-extender', { duration:'0.2' });
		}
		// Cal ajax
		var url = this.template_url +"/ajax.php";
		var parameterValues = { 'action':'menuContent', 'content':content };
		this.ajax['menu-'+ content] = new Ajax.Request(url, {
			method: 'post',
			parameters: parameterValues,
			onSuccess: this.__showMenuSuccess.bindAsEventListener(this, content, fallbackUrl),
			onFailure: this.__showMenuFailure.bindAsEventListener(this, content, fallbackUrl)
		});
	},
	__showMenuSuccess: function(transporter, content, fallbackUrl) {
		// Stop loading
		$('header-menu.loading').hide();
		// Get json data
		var json = transporter.responseText.evalJSON(true);
		// Ok, output
		if (json['status'] == 1) {
			$('menu-extender-inner').update(json['html']);
			new Effect.SlideDown('menu-extender', { duration:'0.2' });
			$('menu-extender').addClassName('menu-'+ content);
		}
		// Error
		else {
			this.__menuProjectsFailure(transporter, content, fallbackUrl);
		}
	},
	__showMenuFailure: function(transporter, content, fallbackUrl) {
		// Hide loading
		$('header-menu.loading').hide();
		//new Effect.Fade('header-menu.loading', { duration:'0.3' });
	},
	__cleanMenuClass: function() {
		$('menu-extender').removeClassName('menu-projects');
		$('menu-extender').removeClassName('menu-tags');
	}


}