/**
 * DrPepper.ModuleBoxList
 *
 * List representation of ModuleBox; used on the site map
 *
 * Author:	Silvan Reinhold
 * Date:	2009-03-03
 * See:		ModuleBox.php
 **/

var DrPepper = DrPepper || {};


/**
 * Constructor
 *
 * @param	p_xDomElement		DOM element representing this ModuleBox in the document (may also be an ID)
 **/ 
DrPepper.ModuleBoxList = function(p_xDomElement)
{
	this._xDomElement = $(p_xDomElement);
	this.setupBehavior();
}


/**
 * Instance attributes
 */
DrPepper.ModuleBoxList.prototype = {
	_xDomElement		:	null	// DOM element representing this ModuleBoxList
}


/**
 * Initializes the dynamic behavior of this ModuleBox. This includes buttons and animations.
 */
DrPepper.ModuleBoxList.prototype.setupBehavior = function()
{
	/* Link hover behavior for IE6 */
	$("a", this._xDomElement).hover(
		function() { $(this).addClass("hover"); },
		function() { $(this).removeClass("hover"); }
	);
	
	/* Set up click behavior */
	$(".item", this._xDomElement).each(function() {
		var l_xMetaData = $(".meta-data", this);
		var l_nLinkType = parseInt($(".link-type", l_xMetaData).text());		

		var l_aActionUrls = [];
		$(".action-url", l_xMetaData).each(function() {
			l_aActionUrls.push($(this).text());
		});

		if (l_aActionUrls.length == 1) {
			$(this).click(function() { DrPepper.Site.performLinkAction({ linkType: l_nLinkType, url: l_aActionUrls[0] }); });
		}
		else {
			// For MultiLinkModuleBoxItems, attach a click handler to each of the action links
			$(".action-link", this).each(function(l_nIndex) {
				$(this).click(function() {
					DrPepper.Site.performLinkAction({ linkType: l_nLinkType, url: l_aActionUrls[l_nIndex] });
				});
			});
		}
	});
}
