/**
	MySmartChannels JavaScript Library

	DHTML support for myst.details class.

	Copyright (C) 2005 MyST Technology Partners, All rights reserved.
	$Header: details.js, 1, 7/27/05 10:56:51 PM, F. Andy Seidl$
 **/

g_aDetailSection = new Array();

function DetailSection(obj_)
{
	this.m_Obj     = obj_;          
	this.m_bOpen   = true;         
	this.m_Content = obj_.innerHTML;
}

function addDetailSection(ds_)
{
	g_aDetailSection = g_aDetailSection.concat([ds_]);
}

function findDetailSection(iDetailSection_)
{
	return g_aDetailSection[iDetailSection_];
}

function initDetailSections()
{
	var divs = document.getElementsByTagName("DIV");
	var i;

	for (i=0; i < divs.length; i++)
	{
		var div = divs[i];

		if (div.className != null && div.className.indexOf("myst.details") != -1)
		{
			var ds = new DetailSection(div);
			addDetailSection(ds);
		}
	}

	for (i=0; i < g_aDetailSection.length; ++i)
	{
		updateDetailSection(i, null);
	}
}

function onClickDetailSection(event_, iDetailSection_)
{
	var bOpen = null;		// toggle state
	var bAll  = false;

	var e = event_
	if (!e)
	{
		e = window.event;
	}

	if (e)
	{
		var bAll  = e.ctrlKey;

//		var bCtrl  = e.ctrlKey;
		var bAlt   = e.altKey;
		var bShift = e.shiftKey;

		if (bShift)
		{
			bOpen = true;
		}
		else if (bAlt)
		{
			bOpen = false;
		}
	}
	
	if (bAll)
	{
		updateAllDetailSections(bOpen);
	}
	else
	{
		updateDetailSection(iDetailSection_, bOpen);
	}
}

function updateAllDetailSections(bOpen_)
{
	for (i=0; i < g_aDetailSection.length; ++i)
	{
		updateDetailSection(i, bOpen_);
	}
}

function updateDetailSection(iDetailSection_, bOpen_)
{
	var ds = g_aDetailSection[iDetailSection_];
	if (bOpen_ == null)
	{
		ds.m_bOpen = !ds.m_bOpen;
	}
	else
	{
		ds.m_bOpen = bOpen_
	}

	// Parameters for "open".
	var image     = "_gizmo-btn-roll-up.gif";
	var title     = "Hide Details";
	var tip       = "Click to hide details.";

	// Change parameters if not "open".
	if (!ds.m_bOpen)
	{
		image    = "_gizmo-btn-roll-down.gif";
		title    = "Show Details";
		tip      = "Click to show details.";
	}

	// Assert parameters.

	var onclick  = "onClickDetailSection(event, " + iDetailSection_ + ")";
	var toggle =
		"<h3 onclick='{onclick}' title='{tip}' style='cursor:pointer;'>"+
			"<img src='images/{image}' height='10' width='11' border='0' alt='' />&nbsp;{title}"+
		"</h3>";

	toggle = toggle.replace(new RegExp("{image}",   "g"), image);  
	toggle = toggle.replace(new RegExp("{title}",   "g"), title);  
	toggle = toggle.replace(new RegExp("{tip}",     "g"), tip);    
	toggle = toggle.replace(new RegExp("{onclick}", "g"), onclick);

	html   = toggle;
	if (ds.m_bOpen)
	{
		html += "<div class='DetailSection'>" + ds.m_Content; + "</div>";
	}

	ds.m_Obj.innerHTML = html;
}

function init_details()
{
	//alert("Hello, from init_details() in details.js.");
	initDetailSections();
}

