


function Div
(
  id
, opts
)
	{
	if ( (typeof Div[id]) != 'undefined' )	Div[id].unload();

	this.id = id;
	Div[id] = this;	// keep track of this div thingy;

	this.init();

	if ( !opts )	return;
	for ( var i in opts )
		if ( this['_'+i] )
			this['_'+i]( opts[i] );	// activate initialization function for this option
		else
			this[i] = opts[i];	// otherwise, just copy the value

	}	// End constructor; Div




Div.prototype.init = function ()
		{
		if ( this.div )	return;
		
		this.div = document.getElementById( this.id );	// link this div with the element within the doc
		if ( !this.div )	return;

		this.div.thisJS = this;	// link the element with this script/obj;
		this.displayStyle = ( this.div.style.display && this.div.style.display != 'none'  ?  this.div.style.display  :  'block' );

//  Make backward compatible (crossing fingers);
//	Migrate <DIV>s using height/overflow to open and close
		var h = 1;
		try { 
				h = parseInt( this.div.style.height );
				}
		catch ( ex )
				{}
		if ( h == 0  &&  this.div.style.overflow == 'hidden' )
			{
			this.div.style.height = 'auto';
			this.div.style.overflow = 'visible';

			this.div.style.display = 'none';
			}

		}	// End (subsequent) constructor; init()




Div.prototype.unload = function()
		{
		this.div = null;
		// other (tab) unload stuff may need to be done here
		}	// End method; unload








//  Initialize <a> tabbed interface
Div.prototype._tabs = function
(
  args
)
		{
		var anchors = this.div.getElementsByTagName( 'a' );
		if ( anchors.length < 1 )	return;

		if ( !args )	args = {};
		if ( !args.tabDivOpts )	args.tabDivOpts = {};
		for ( var a in args )
			if ( a != 'tabDivOpts' )	this[a] = args[a];

		this.tabs = new Array();

		for ( var a = 0;  a < anchors.length;  a++ )
			{
			var tab = anchors[a];
			var p, hr;
			if ( tab.href )
				{
				hr = tab.href.replace( /\#\%23/g, '##' );
				p = hr.indexOf( '##' );
				if ( p > -1 )
					{
					this.tabs.push( tab );

					var divName = hr.substring( p+2 );
//				if ( (typeof Div[divName]) == 'undefined' )		new Div( divName, args.tabDivOpts );
					new Div( divName, args.tabDivOpts );

					tab.href = 'javascript:Div.' + this.id + '.activate( ' + (this.tabs.length-1) + ' );'
					tab.tabDiv = Div[divName];
					}
				}
			}	// End for; span of anchors
		}	// End init; _tabs




//  Initialize <li> tabbed interface
Div.prototype._ulTabs = function
(
  args
)
		{
		var ul = this.div.getElementsByTagName( 'li' );
		if ( ul.length < 1 )	return;

		if ( !args )	args = {};
		if ( !args.tabDivOpts )	args.tabDivOpts = {};
		for ( var a in args )
			if ( a != 'tabDivOpts' )	this[a] = args[a];

		this.tabs = new Array();

		var p, hr;

		for ( var li = 0;  li < ul.length;  li++ )
			{
			var a = ul[li].getElementsByTagName( 'a' )[0];
			if ( a.href )
				{
				hr = a.href.replace( /\#\%23/g, '##' );
				p = hr.indexOf( '##' );
				if ( p > -1 )
					{
					this.tabs.push( ul[li] );

					var divName = hr.substring( p+2 );
	//				if ( (typeof Div[divName]) == 'undefined' )		new Div( divName, args.tabDivOpts );
					new Div( divName, args.tabDivOpts );
	
					a.href = 'javascript:Div.' + this.id + '.activate( ' + (this.tabs.length-1) + ' );'
					ul[li].tabDiv = Div[divName];
					}
				}
			}	// End for; span of lis
		}	// End init; _ulTabs




Div.prototype.activate = function
(
	trigger
)
		{
		for ( var t = 0;  t < this.tabs.length;  t++ )
			{
			this.tabs[t].className = ( t == trigger  ?  this.activeTabClass  :  '' );	// active check differs between anchor and tab/div...
			this.tabs[t].tabDiv.peek( this.tabs[t].tabDiv == this.tabs[trigger].tabDiv ); // check object reference in order to support many (anchors) to one (tab/div);
			}
		}	// End method; activate()




Div.calcX = function
(
  obj
)
		{
		return	( obj  ?  obj.offsetLeft + Div.calcX( obj.offsetParent )  :  0  );
		}	// End method; calcX





Div.prototype.createScrollingViewport = function
(
  element
, step
, interval
)
		{
		this.init();
		this.scrolled = 
		  { element: element
		  , step: step
			, timer: window.setInterval( 'Div.' + this.id + '.scrollViewport();', interval )
		  };

		}	// End method; createScrollingViewport




Div.prototype.peek = function
(
  keepOpen
)
		{
		this.init();

		if ( (typeof this.div) == 'undefined'  ||  this.div == null )
			{
			window.defaultStatus = 'Div.' + this.id + ( this.div == null  ?  ' is null.'  :  ' is undefined.' );
			return;
			}


		if ( keepOpen || ( (typeof keepOpen) == 'undefined' && this.div.style.display == 'none' ) )
			{
			this.div.style.display = ( this.displayStyle  ?  this.displayStyle  :  'block' );
			if ( this.onActivate )	this.onActivate( );
			keepOpen = true;
			}
		else
			{
			this.div.style.display = 'none';
			if ( this.onDeactivate )	this.onDeactivate( );
			keepOpen = false;
			}

		if ( !this.tabs )		return;
		for ( var t in this.tabs )
			this.tabs[t].tabDiv.peek( keepOpen && this.tabs[t].className == this.activeTabClass );

		}	// End method; peek



Div.prototype.posX = function()
		{
		this.init();
		return	( !this.div.posX || this.div.posX == 0  ?  this.div.posX = Div.calcX( this.div )  :  this.div.posX );
		}	// End method; posX



Div.prototype.scrollViewport = function ()
		{
		var mT = parseInt( this.scrolled.element.style.marginTop );
		this.scrolled.element.style.marginTop = ( this.scrolled.element.scrollHeight + mT > 0  ?  (mT - this.scrolled.step) + 'px'  :  this.div.style.height );
		}	// End method; scrollViewport

