var mhtml = "";
var Gindex = 0;
var SexyElem = "";
var TextElem = "";
var PlaceElem = "";
var InitSexy = false;
var NullPartnerFlag = false;

function mySexyInit(elem, elem2, elem3, flag)
{
	if(!elem || !elem2 ||!elem3)
		return;
	
	SexyElem = elem;
	TextElem = elem2;
	PlaceElem = elem3;
	NullPartnerFlag = flag;
	mhtml = "";
	Gindex = 0;
	$.each(GLARR, function(key, val)
	{
		$.each(val, function(key1, val1)
		{
			if(show_user_id == val1.id)
				$("#"+TextElem).val(val1.login.substr(4,4));
			mhtml += "<div style=\"font-weight:normal; white-space: nowrap; color:black; cursor:pointer\" onMouseOver=\"change_style(this, '#4193D4')\" onMouseOut=\"change_style(this, 'white')\"" + 
						" onMouseDown=\"mchange('"+val1.id+"', '"+val1.login.substr(4,4)+"')\">"+
						val1.login.substr(4,4) + "</div>";
			
			Gindex++;
		});
	});
	
	$("#"+SexyElem).html(mhtml);
	if(Gindex > 10)
	{
		$("#"+SexyElem).css("height", "150px");
		$("#"+SexyElem).css("overflow", "auto");
		$("#"+SexyElem).css("overflow-x", "hidden");
		$("#"+SexyElem).css("overflow-y", "visible");
	}
	else if(Gindex > 0)
	{
		$("#"+SexyElem).css("height", 17*Gindex + "px");
	}
	InitSexy = true;
}

function show_div()
{
	$("#"+SexyElem).toggle();
}
		
function change_div()
{
	var text = $("#"+TextElem).val();
	
	if(text)
	{
		$("#"+SexyElem).html("");
		lhtml = "";
		index = 0;
		
		$.each(GLARR, function(key, val)
		{
			$.each(val, function(key1, val1)
			{
				var str = val1.login.substr(4,4);
				
				if("-1" != str.indexOf(text))
				{
					
					lhtml += "<div style=\"font-weight:normal; white-space: nowrap; cursor:pointer; color:black;\" onMouseOver=\"change_style(this, '#4193D4')\" onMouseOut=\"change_style(this, 'white')\"" + 
						" onMouseDown=\"mchange('"+val1.id+"', '"+val1.login.substr(4,4)+"')\">"+
						str + "</div>";
					index++;
				}
			});
		});
		
		$("#"+SexyElem).html(lhtml);
		if(index > 10)
		{
			$("#"+SexyElem).show();
			$("#"+SexyElem).css("height", "150px");
			$("#"+SexyElem).css("overflow", "auto");
			$("#"+SexyElem).css("overflow-x", "hidden");
			$("#"+SexyElem).css("overflow-y", "visible");
		}
		else if(index > 0)
		{
			$("#"+SexyElem).show();
			$("#"+SexyElem).css("height", 17*index + "px");
		}
		else
		{
			$("#"+SexyElem).html("");
			$("#"+SexyElem).css("height", "0px");
			$("#"+SexyElem).hide()
		}
	}
	else
	{
		if(NullPartnerFlag)
			mchange(0, "");
		
		$("#"+SexyElem).html(mhtml);
		if(Gindex > 10)
		{
			$("#"+SexyElem).css("height", "150px");
			$("#"+SexyElem).css("overflow", "auto");
			$("#"+SexyElem).css("overflow-x", "hidden");
			$("#"+SexyElem).css("overflow-y", "visible");
		}
		else
		{
			$("#"+SexyElem).css("height", 15*Gindex + "px");
		}
	}
}

function mchange(id, text)
{
	$("#"+TextElem).val(text);
	$("#"+PlaceElem).val(id);
	//$("#"+SexyElem).html("<div style=\"white-space: nowrap; cursor:pointer\" onMouseOver=\"change_style(this, '#4193D4')\" onMouseOut=\"change_style(this, 'white')\" onMouseDown=\"mchange('"+id+"', '"+text+"')\">" + id + " / " + text + "</div>");
	//$("#"+SexyElem).css("height", "15px");
	$("#"+SexyElem).hide();
}
