function LeftMenus(idMainDiv, defaultState)
{
	this.blocks = new Array();
	this.defaultState = defaultState;
	
	var mainEl = document.getElementById( idMainDiv );
	var items = mainEl.getElementsByTagName( "DIV" );
	
	for( var j = 0; j < items.length; j ++ ) {
		if( items[j].className !== undefined ) {
			if( items[j].className != "item" ) continue;
		} else if( items[j].getAttribute !== undefined ) {
			if( items[j].getAttribute( "class" ) != "item" ) continue;
		} else continue;
		
		var blockId = items[ j ].getAttribute( "itemId" );
		
		if( !blockId ) continue;
		
		var blockParts = items[j].getElementsByTagName( "DIV" );
		var blockDescr = {
			id : 0,
			main : null,
			inactive : null,
			active : null,
			isopen : false
		};
		
		blockDescr.id = blockId;
		blockDescr.main = items[ j ];
		
		for( var x = 0; x < blockParts.length; x ++ ) {
			var cn;
			if( blockParts[ x ].className !== undefined ) {
				cn = blockParts[ x ].className;
			} else if( blockParts[ x ].getAttribute !== undefined ) {
				cn = blockParts[ x ].getAttribute( "class" );
			} else continue;
			
			if( cn == "label" ) {
				blockDescr.inactive = blockParts[ x ];
			} else if( cn == "interactive" ) {
				blockDescr.active = blockParts[ x ];
			}
		}
		
		this.blocks[ blockId ] = blockDescr;
	}

	this.load();
}

LeftMenus.prototype.load = function()
{
	if( hasCookies() ) {
		var state = GetCookie( "lmstate" );

		if( state == null ) {
		    state = this.defaultState;
		}
		
		if( (state != null) && (state != "") ) {
			var items = state.split( "," );
			
			for( var j = 0; j < items.length; j ++ ) {
				if( this.blocks[ items[ j ] ] !== undefined ) {
					this.blocks[ items[ j ] ].active.style.display = "block";
					this.blocks[ items[ j ] ].inactive.style.display = "none";
					this.blocks[ items[ j ] ].isopen = true;
				}
			}
		}
	}
}

LeftMenus.prototype.save = function()
{
	if( hasCookies() ) {
		var state = "";

		for( var blockId in this.blocks ) {
			var block = this.blocks[ blockId ];

			if( block.isopen == true ) {
				if( state != "" )
					state += ",";
				state += new String( block.id );
			}
		}
		
		SetCookie( "lmstate", state, null, '/' );
	}
}

LeftMenus.prototype.open = function(id)
{
	if( this.blocks[ id ] !== undefined ) {
		this.blocks[ id ].active.style.display = "block";
		this.blocks[ id ].inactive.style.display = "none";
		this.blocks[ id ].isopen = true;
		
		this.save();
	}
}

LeftMenus.prototype.close = function(id)
{
	if( this.blocks[ id ] !== undefined ) {
		this.blocks[ id ].active.style.display = "";
		this.blocks[ id ].inactive.style.display = "";
		this.blocks[ id ].isopen = false;
		
		this.save();
	}
}

