/*-------------------------------------------------------------------------*/

// IPS BASIC MENU CLASS (EXTENSION: BUILD SIMPLE MENU)

// (c) 2005 Invision Power Services, Inc

// Assumes that "ips_menu.js" has been loaded

//-----------------------------------------------

// Modified By Dean

/*-------------------------------------------------------------------------*/



//----------------------------------

// INIT some CSS classes

//----------------------------------

var css_mainwrap     = 'popupmenu';

var css_menusep      = 'popupmenu-item';

var css_menusep_last = 'popupmenu-item-last';

var menucorners      = true;



//----------------------------------

// INIT some images

//----------------------------------



var img_item   = "<img src='" + ipb_var_image_url + "/menu_item.gif' border='0' alt='V' />";

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, pnode, mw)

{

	var _fnc = null;

	var _wid = (mw != '' && mw != null) ? ';width:'+mw : '';

	var html = "\n<div id='"+cid+"_menu' style='display:none;z-index:100"+_wid+"'>\n<div class='"+css_mainwrap+"' id='"+cid+"_menu_popupmenu'>";



	if (!complexmenu)

	{

		menuinput = _clean_menu_array(menuinput);

		len       = parseInt(menuinput.length);



		if (len > 0)

		{

			for (var i in menuinput)

			{

				if (typeof(menuinput[i]) != 'string')

				{

					continue;

				}



				t = parseInt(i)+1;

				thisclass = (t == len) ? css_menusep_last : css_menusep;



				if (len == 1)

				{

					thisclass = css_menusep_last;

				}



				if (menuinput[i].match(/^~~SKIP~~/))

				{

					continue;

				}

				else if (menuinput[i].match( /^(~~NODIV~~|--NODIV--)/))

				{

					html += menuinput[i].replace( /^(~~NODIV~~|--NODIV--)/, '');

				}
				
				else

				{

						     if ( is_ie && cid == 'rss-syndication' && menuinput[i].match( /id='fixrss'/i)) {
		
		             html += "<div class='"+thisclass+"'>\n"+menuinput[i].replace( /id='fixrss'/, 'style=\'color:#34496a\'')+"\n</div>\n";

	                 } else       {
					
					html += "<div class='"+thisclass+"'>\n"+menuinput[i]+"\n</div>\n";

												  }
				
				}

			}

		}

	}

	else

	{

		if (cid == 'cblock-options')

		{

			_cht = 0;

			_chk = false;

			_cbm = menuinput.split('\n');

			_lid = '';

			

			for (var i=0; i<_cbm.length; i++)

			{

				if (_cbm[i].match(/class='popupmenu-category'/i))

				{

					_chk = true;

					continue;

				}



				if (_chk != true)

				{

					continue;

				}



				if (_cbm[i].indexOf("id='cbmenu_") > -1)

				{

					_cht += 1;

					if (_mm = _cbm[i].match(/id='(.+?)'/i))

					{

						_lid = _mm[1];

					}

				}

			}



			if (_cht <= 0)

			{

				menuinput += "<div align='center' class='popupmenu-item-last' id='cbmenu_block_none' style='display:block'>~0~</div>\n";
			
			}

			else

			{

				_fnc = "my_getbyid(_lid).className = css_menusep_last";

				menuinput += "<div align='center' class='popupmenu-item-last' id='cbmenu_block_none' style='display:none'>~0~</div>\n";

			}

		}



		html += menuinput;

	}



	html += "\n</div>\n";

	if (menucorners)
	{
		html += "<div align='left' style='position:relative;white-space:nowrap'><table cellspacing='0' cellpadding='0' width='100%' style='position:absolute;top:0;left:0'><tr><td class='nopad' nowrap='nowrap'><div class='popupmenu-footer-left'><!-- --></div></td><td class='nopad' nowrap='nowrap' width='100%'><div class='popupmenu-footer-tile' style='width:100%'><!-- --></div></td><td class='nopad' nowrap='nowrap'><div class='popupmenu-footer-right'><!-- --></div></td></tr></table>";
	}

	html += "</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 != '')

	{

		if ( is_ie && cid == 'rss-syndication') { pnode = '' ;}
		
		if (pnode != '' && document.getElementById(pnode))

		{

			document.getElementById(pnode).innerHTML += html;

		}

		else

		{

			document.getElementById(cid).parentNode.innerHTML += html;

		}

	}



	if (typeof(_fnc) != null)

	{

		eval(_fnc);

	}

	

	//----------------------------------

	// Register and init

	//----------------------------------

	

	ipsmenu.dynamic_register[ipsmenu.dynamic_register.length+1] = cid;

	ipsmenu.menu_openfuncs[cid] = "_blur_menu_obj()";

}



function _blur_menu_obj(e)

{

	var o = my_getbyid(ipsmenu.menu_cur_open);

	if (typeof(o.blur) == 'function')

	{

		o.blur();

	}

}



function _clean_menu_array(mi)

{

	var a = mi[mi.length-1];

	if (a == '' || a.match(new RegExp('^(\-\-|~~)(NODIV|SKIP|IGNORE)(\-\-|~~)$', 'i')))

	{

		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;

}

/* function itab_load_rss()
{
	try
	{
		var o = document.getElementById('itab-js-rss');
		var b = document.getElementsByTagName('body')[0];

		if (o && b)
		{
			while (o.hasChildNodes() || o.childNodes.length > 0)
			{
				b.appendChild(o.childNodes[o.childNodes.length-1]);
			}
		}

		o.style.display = 'none';
		itab_add_event(window, 'load', itab_load_rss);
	}

	catch(me){}
}*/
