function hideAllSelect() {
	var i = 0;
	$('select').each(function() {
		if (document.getElementById('div_select_'+i) != null) {
			$(document.getElementById('div_select_'+i)).show();
		} else {
			var _w = $(this).width();
			$(this).parent().append('<div id="div_select_'+i+'" style="border: 1px solid #7F9DB9; background: white; width: '+parseInt($(this).width()+0)+'px; height:'+parseInt($(this).height()+0)+'px;">&nbsp;</div>');
		}
		$(this).hide();
		i++;
	});
}

function showAllSelect() {
	var i = 0;
	$('select').each(function() {
		if (document.getElementById('div_select_'+i) != null) {
			$(document.getElementById('div_select_'+i)).hide();
		}
		$(this).show();
		i++;
	});
}

var _tm = new Array();
var _flag1 = new Array ();
var _flag2 = new Array ();
addOnLoadEvent(function () {
	initDMenu();
});

function initDMenu() {
	$('a.bmenu').each(function() {
		var mid = $(this).attr('id');
		var dbm = $(this).parent().find('div.bmenu');
		if (dbm!=undefined) {
			_tm[mid] = false;
			_flag1[mid] = false;
			_flag2[mid] = false;
			var coords = findPos(document.getElementById(mid));
			var cl = jQuery.iUtil.getClient();
			var el_w = 230;
			var el_l = coords[0]-30;
			if ((el_l+el_w)>(cl.w)) el_l = cl.w - el_w;
			$(dbm).css('left', el_l);
			$(dbm).css('top', coords[1]+20);
			$(dbm).css('display', 'none');
			/*
			$(dbm).mouseover(function() {
				_flag1[$(this).attr('iid')] = true;
			});
			$(dbm).mouseout(function() {
				_flag1[$(this).attr('iid')] = false;
			});
			$(this).mouseover(function() {
				if ($.browser.msie) hideAllSelect();
				$(this).parent().find('div.bmenu').css('display', 'block');
				_flag2[$(this).attr('id')] = true;
				if (_tm[$(this).attr('id')]===false) {
					_tm[$(this).attr('id')] = setInterval(function() {
						hideSDiv(mid, dbm);
					}, 100);
				}
			});
			$(this).mouseout(function() {
				_flag2[$(this).attr('id')] = false;
			});
			*/
		}
	});
}

$(window).resize(function(){
	initDMenu();
});

function hideSDiv(id, obj) {
	if (_flag2[id]===false && _flag1[id]===false) {
		$(obj).css('display', 'none');
		clearInterval(_tm[id]);
		_tm[id] = false;
		if ($.browser.msie) showAllSelect();
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}