/************************************************/
/* IPB3 Javascript								*/
/* -------------------------------------------- */
/* idg_custom.js - Code for IDG enhancement		*/
/* (c) IDG, Inc 2010							*/
/* -------------------------------------------- */
/* Author: XLENT Business Integration 			*/
/************************************************/

var _idgcustom = window.IPBoard;

_idgcustom.prototype.idgcustom = {
	init: function()
	{
		Debug.write("Initializing idg_custom.js");
		
		document.observe("dom:loaded", function(){
			ipb.idgcustom.initEvents();
		});
	},
	
	initEvents: function()
	{
		ipb.delegate.register('.bbc_log_show', ipb.idgcustom.toggleLogger);
		
		if($('two_boxes_toggle')) {
			$('two_boxes_toggle').observe('click', ipb.idgcustom.toggleWelcomeBoxes );
		}
		if($('categories_toggle')) {
			$('categories_toggle').observe('click', ipb.idgcustom.toggleForumCategoryBoxes );
		}
	},
	
	
	/**
	 * Toggle logger
	 * 
	 * @param	{event}		e		The event
	*/
	toggleLogger: function(e, button)
	{
		Event.stop(e);
		$(button).up().down('.bbc_log_wrapper').down('.bbc_log_short_content').toggle();		
		var returnvalue = $(button).up().down('.bbc_log_wrapper').down('.bbc_log_content').toggle();
		
		if( returnvalue.visible() )
		{
			$(button).value = '-';
		}
		else
		{
			$(button).value = '+';
		}
	},

	/**
	 * Triggeres a toggle of the welcome boxes
	 * 
	 * @param	{event}		e		The event
	*/
	toggleWelcomeBoxes: function(e)
	{
		Event.stop(e);
		ipb.idgcustom.toggleByCookieSetting('two_boxes', 'welcomeBoxesDisplay');
	},

	/**
	 * Triggeres a toggle of the catagory box on the front page
	 * 
	 * @param	{event}		e		The event
	*/
	toggleForumCategoryBoxes: function(e)
	{
		Event.stop(e);
		ipb.idgcustom.toggleByCookieSetting('categories', 'categoriesDisplay');
	},

	/**
	 * Toggles visibility of div and stores the status in cookie
	 * 
	 * @param	{string}	divId		Id of the div to toggle
	 * @param	{string}	cookieName	Name of the cookie where 
	 *									toggle status will be saved
	*/
	toggleByCookieSetting: function(divId, cookieName)
	{
		// Store setting
		var saveValue = "show";
		if($(divId) && $(divId).visible()) {
			saveValue = "hide";
		}
		ipb.Cookie.set( cookieName, saveValue, 1 );
		window.location.reload(true);
	}		
}
ipb.idgcustom.init();

