/*-------------------------------------------------------------------------*/
// IPS BASIC MENU CLASS (EXTENSION: BUILD SIMPLE MENU)
// (c) 2005 Invision Power Services, Inc
// Assumes that "ips_menu.js" has been loaded
/*-------------------------------------------------------------------------*/

//----------------------------------
// INIT some CSS classes
//----------------------------------

var css_mainwrap     = 'popupmenu';
var css_menusep      = 'popupmenu-item';
var css_menusep_last = 'popupmenu-item-last';

//----------------------------------
// INIT some images
//----------------------------------

var img_item   = "<img src='" + ipb_var_image_url + "/menu_item.gif' border='0' alt='V' style='vertical-align:middle' />";
var img_action = "<img src='" + ipb_var_image_url + "/menu_item2.gif' border='0' alt='V' />";

/*-------------------------------------------------------------------------*/
// Return formed image
/*-------------------------------------------------------------------------*/

function make_image( img )
{
	return "<img src='" + ipb_var_image_url + "/" + img + "' border='0' alt='-' class='ipd' />";
}

/*-------------------------------------------------------------------------*/
// menu_build_menu
// cid: ID of opener object (img, div, etc)
// menuinput: Array of menu entries | Variable of menu HTML
// complexmenu: Treat as HTML stream if true, else treat as array of HTML
/*-------------------------------------------------------------------------*/

function menu_build_menu(cid, menuinput, complexmenu)
{
	var html = "\n<div id='" + cid + "_menu' style='display:none;z-index:100'>\n<div class='" + css_mainwrap + "'>";
	
	if ( ! complexmenu )
	{
		menuinput = _clean_menu_array(menuinput);
		len = parseInt(menuinput.length);
		
		if ( len > 0 )
		{
			for( var i in menuinput )
			{
				t = parseInt(i) + 1;
				
				thisclass = ( t == len ) ? css_menusep_last : css_menusep;
				
				if ( menuinput[i].match( /^--NODIV--/ ) )
				{
					html += menuinput[i].replace( /^--NODIV--/, '' );
				}
				else
				{
					html += "<div class='" + thisclass + "'>\n" + menuinput[i] + "\n</div>\n";
				}
			}
		}
	}
	else
	{
		html += menuinput;
	}
	
	html += "</div>";
	if (!is_ie && !is_opera && is_ns)
	{
		html += "<div align='left' style='white-space:nowrap'><div class='popupmenu-footer-tile' style='position:relative;margin-left:3px;margin-right:3px'><div class='popupmenu-footer-left' style='position:relative;float:left;left:0px;margin-left:-3px;width:100%'></div><div class='popupmenu-footer-right' style='position:relative;float:left;left:3px' align='right'></div><div class='cleared'></div></div></div></div>\n";
	}
	else
	{
		html += "</div>";
		//html += "<div align='left' style='white-space:nowrap;padding:0;margin:0'><div style='float:left;padding:0'><img src='"+ipb_var_image_url+"/menu_bot_left.gif' border='0' alt='' /></div><div style='float:left' style='background:url("+ipb_var_image_url+"/menu_bot_tile.gif) repeat-x left top;height:10px;font-size:1px;width:100%'>&nbsp;</div><div style='float:left;padding:0'><img src='"+ipb_var_image_url+"/menu_bot_right.gif' border='0' alt='' /></div><div class='cleared'></div></div></div>\n";
		//html += "<div align='left' style='white-space:nowrap'><div class='popupmenu-footer-tile' style='margin-left:3px;margin-right:3px;white-space:nowrap;width:auto'><div class='popupmenu-footer-right' style='position:relative;float:right;right:0px;margin-left:3px' align='right'></div><div class='popupmenu-footer-left' style='position:relative;left:3px;float:margin-left:-3px'></div><div class='cleared'></div></div></div></div>\n";
		//html += "<div align='left' style='white-space:nowrap'><div style='background-image:url("+ipb_var_image_url+"/menu_bot_tile.gif);height:10px'>Test</div></div></div>\n";
	}

	//----------------------------------
	// Workaround for IE bug which shows
	// select boxes and other windows GUI
	// over divs. Write iframe
	//----------------------------------
	
	if ( is_ie )
	{
		html += "\n"+'<iframe id="if_' + cid + '" src="' + ipb_var_image_url + '/iframe.html" scrolling="no" frameborder="1" style="position:absolute;top:0px;left:0px;display:none;"></iframe>'+"\n";
	}
	
	//----------------------------------
	// Write the html
	//----------------------------------
	
	if ( html != '' )
	{
		document.open();
		document.writeln( html );
		document.close();
	}
	
	//----------------------------------
	// Register and init
	//----------------------------------
	
	menu_register( cid );
}


function _clean_menu_array(mi)
{
	var a = mi[mi.length-1];
	if (a == '' || a == '--NODIV--')
	{
		delete(mi[mi.length-1]);
	}

	var z = new Array();
	for (var i in mi)
	{
		if (mi[i] == 'undefined' || typeof(mi[i]) == 'undefined')
		{
			continue;
		}

		z[z.length] = mi[i];
	}

	return z;
}
