/************************************************/
/* Faqs Javascript for Invision Byte			*/
/* -------------------------------------------- */
/* faqs.js - (c) Invision Byte 2010-2011		*/
/* -------------------------------------------- */
/* Author: Terabyte								*/
/************************************************/

var _faqs = window.IPBoard;

_faqs.prototype.faqs = {
	/* Constructor */
	init: function()
	{
		Debug.write("Initializing faqs.js");
		
		document.observe("dom:loaded", function(){
			/* Update also ALL our faqs on the page */
			$$('div.__faq').each(
				function(elem)
				{
					// Hide the span if JS enabled
					elem.down('span').hide();
					
					// Add also classnames and event
					elem.addClassName('clickable').addClassName('unspecific');
					elem.observe('click', ipb.faqs.toggleFaq.bindAsEventListener( this, elem ) );
				}
			);
			
			/* Fix the onclick even for links in the faqs! */
			$$('a.open_link').each(
				function(link)
				{
					link.observe('click', ipb.faqs.openLink.bindAsEventListener( this, link ) );
				}
			);
		} );
	},
	
	/**
	 * Toggles a FAQ! Simple as that..
	 */
	toggleFaq: function( e, elem )
	{
		// Block any event..
		Event.stop(e);
		
		Debug.write('toggle faq');
		
		// ..update our CSS..
		if ( elem.down('span').visible() )
		{
			elem.down('span').hide();
			elem.addClassName('unspecific');
		}
		else
		{
			elem.removeClassName('unspecific');
			elem.down('span').appear( { duration: 0.5 } );
		}
		
		return true;
	},
	
	/**
	 * Fix for the links since toggle faq is triggered before...
	 */
	openLink: function( e, link )
	{
		// Block any event..
		Event.stop(e);
		
		// .. and redirect
		location.href = link.href;
		
		return true;
	}
};

ipb.faqs.init();
