function wp_navbar_combo(menubarid, navtree, options, styleOptions) 
{
	var me = this;
	if( navtree === null || navtree.childArray === null )
	{	//NavTree could not be loaded
		return;
	}

	me.options = {
		"m_bNoScript" : false,
		"m_bStaticScript" : false
	};
	if( options )
	{	me.options = WpNavBar.mergeOptions( me.options, options );}

	me.styleOptions = {
		'select' : {
			'sStyle':[],
			'bIndent':true },
		'option1' : {
			'sStyle':[] },
		'option2' : {
			'sStyle':[] },
		'button' : {
			'bShowButton':false,
			'sText':'' }		
	};
	if( styleOptions )
	{	me.styleOptions = WpNavBar.mergeOptions( me.styleOptions, styleOptions ); }

	
	me.AddItems = function(selectElement, navmenu, styleOptions, iLevel)
	{
		var spacing = '';	//IE doesn't support padding/margin for OPTION elements, so we have to use spaces to indent them
		if( styleOptions.select.bIndent )
		{	for( var i = 0; i < iLevel; ++i )
			{	spacing += '&nbsp;&nbsp;&nbsp;'; }
		}
	
		for( var index = 0; index < navmenu.childArray.length; index++ )
		{
			var navbaritem = navmenu.childArray[index];
			var optionElement = document.createElement('OPTION');
			optionElement.navbaritem = navbaritem;	//option remembers the navbaritem it represents
			optionElement.innerHTML = spacing + navbaritem.sTitle; //Using createTextNode would lose the spaces
			selectElement.appendChild(optionElement);
	
			//Apply styles
			if( iLevel===0 )
			{	for( var name1 in this.styleOptions.option1.sStyle )
				{	if( this.styleOptions.option1.sStyle.hasOwnProperty(name1) )
					{ optionElement.style[name1]=styleOptions.option1.sStyle[name1]; }
				}
			}
			else
			{	for( var name2 in styleOptions.option2.sStyle )
				{	if( this.styleOptions.option2.sStyle.hasOwnProperty(name2) )
					{	optionElement.style[name2]=styleOptions.option2.sStyle[name2]; }
				}
			}
		
			if( navbaritem.bIsCurrentPage )
			{	optionElement.defaultSelected = true; }	//Select current page in the combo. Not supported by IE.
	
			if( navbaritem.childArray )
			{	this.AddItems(selectElement, navbaritem, styleOptions, iLevel+1); }
		}
	};

	var divElement = document.getElementById( menubarid );	//Parent DIV object
	divElement.style.textAlign='left';//ensure we override site setting

	//Create the SELECT element
	var selectElement = document.createElement('SELECT');
	for ( var name in this.styleOptions.select.sStyle )	//Apply user style
	{	if( me.styleOptions.select.sStyle.hasOwnProperty(name) )
		{	selectElement.style[name]=me.styleOptions.select.sStyle[name]; }
	}
	divElement.appendChild(selectElement);

	//Add the links recursively
	me.AddItems(selectElement, navtree, me.styleOptions, 0);
	
	//As IE doesn't process defaultSelected, do the job for it
	for( var i=0; i< selectElement.length; ++i )
	{	if( selectElement.options[i].defaultSelected )
		{	selectElement.selectedIndex = i; }
	}

	if( me.styleOptions.button.bShowButton )
	{
		//Add GO button
		var buttonElement = document.createElement('INPUT');
		buttonElement.type = 'button';
		buttonElement.value = me.styleOptions.button.sText;
		buttonElement.selectElement = selectElement;
		buttonElement.onclick = wp_navbar_combo.onbuttonclicked;
		divElement.appendChild(buttonElement);
	}
	else
	{	//Add event to select element
		selectElement.onchange = wp_navbar_combo.onselectchanged;
	}
}

wp_navbar_combo.go = function(selectElement)
{
	if( selectElement.selectedIndex < 0 )
	{	return; }
	var optionElement = selectElement.options[selectElement.selectedIndex];
	window.open(optionElement.navbaritem.sUrl,optionElement.navbaritem.sTarget);
};

wp_navbar_combo.onbuttonclicked = function()
{	//Button has been pressed
	wp_navbar_combo.go( this.selectElement );
};

wp_navbar_combo.onselectchanged = function()
{	//Select element has been changed when in automatic mode 
	wp_navbar_combo.go( this );
};


