function objGetKeywordMenuInst()
{
    var inst = new Object();
    inst.Id = getObjUniqueId();
    //alert('asd' + getObjUniqueId());
    Objects[inst.Id] = inst;

    var code =
        '	<div class="edit-word-menu-box" id="edit-word-menu-box-'+inst.Id+'">'
      + '		<div class="menu-design">'
      + '			<div class="edit-word-menu">'
      + '				<a class="word-icons word-icons-ico1 hCopyKeywords2SelectedAd" href="#" title="Добавить выделенные слова в текущее объявление">Добавить выделенные слова в текущее объявление</a>'
      + '				<a class="word-icons word-icons-ico2 hCreateAdBasedOnKeywordsSelected" href="#" title="Создать новое объявление на базе выделенных слов">Создать новое объявление на базе выделенных слов</a>'
      + '				<a class="word-icons word-icons-ico3 hCreateNewAdPerKeywordSelected" href="#" title="Создать по одному новому объявлению для каждого из выделенных слов">Создать по одному новому объявлению для каждого из выделенных слов</a>'
      /* '				<a class="word-icons word-icons-ico4 hCopyKeyword2Clipboard" href="#" title="Копировать выделенные слова в буфер">Копировать выделенные слова в буфер</a>' */
      + '				<a class="word-icons word-icons-ico5 hWordstatEmAll" href="#" title="Открыть по новой табе для каждого из выделенных слов">Открыть по новой табе для каждого из выделенных слов</a>'
      + '				<a class="word-icons word-icons-ico6 hShowTopYandex" href="#" title="Посмотреть выдачу Яндекса">Посмотреть выдачу Яндекса</a>'
      + '				<a class="word-icons word-icons-ico7 hShowTopRambler" href="#" title="Посмотреть выдачу Рамблера">Посмотреть выдачу Рамблера</a>'
      + '				<a class="word-icons word-icons-ico8 hShowTopGoogle" href="#" title="Посмотреть выдачу Гугла">Посмотреть выдачу Гугла</a>'
      + '			</div>'
      + '		</div>'
      + '	</div>';
    
    inst.jq = $(code);
    
    inst._initialize = function()
    {
	    $('#edit-word-menu-box-'+inst.Id + '').each(function()
            {
                $(this).hover(function(e)
                {   
		    
                }, function()
                {
		    inst.Hide();
		    /* inst.DelayedHide(1234); */
                })
            });
        

        $('.word-icons', inst.jq).each(function()
            {
		var tooltip = $(this).attr('title');
                $(this).hover(function(evt)
                    {
			clearTimeout(inst._delayedHideTimer);
                        $('#elama-tooltip').text(tooltip).css(
                            {
                                left: evt.pageX + 'px',
                                top: evt.pageY + 22 + 'px'
                            });
                        $(this).attr('title','');
                    },
                    function()
                    {    
                        $(this).attr('title', tooltip);
                        $('#elama-tooltip').css(
                        {
                            left: '-9999px',
                            top: '-9999px'
                        });
                    })
            })
    }
    inst.Initialize = function()
    {
		    $('.hCopyKeywords2SelectedAd').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
			    var ad = Panels[1].Tabs[0].Controls[0].GetSelectedAd();
			    if (ad!=null)
			    {
				for (x in tNode.SelectedNodes)
				{
				    var node = tNode.SelectedNodes[x];
				    var keyword = node.Values[0];
				    ad.AddKeyword(keyword);
				}
			    }
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    $('.hCreateAdBasedOnKeywordsSelected').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
			    var ad = Panels[1].Tabs[0].Controls[0].AddNewAd();
			    if (ad!=null)
			    {
				for (x in tNode.SelectedNodes)
				{
				    var node = tNode.SelectedNodes[x];
				    var keyword = node.Values[0];
				    ad.AddKeyword(keyword);
				}
			    }
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    $('.hCreateNewAdPerKeywordSelected').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
			    for (x in tNode.SelectedNodes)
			    {
				var node = tNode.SelectedNodes[x];
				var keyword = node.Values[0];
				
				var ad = Panels[1].Tabs[0].Controls[0].AddNewAd();
				if (ad!=null)
				{
					ad.AddKeyword(keyword);
				}
			    }
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    
		    /*
		    $('.hCopyKeyword2Clipboard').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
			    var sResult = "";
			    for (x in tNode.SelectedNodes)
			    {
				var node = tNode.SelectedNodes[x];
				var keyword = node.Values[0];
				var stat = node.Values[2];
				if (sResult.length>0)
				{
				    sResult += "\r\n";
				}
				sResult += keyword + "\t" + stat;
			    }
			    //AddKeyword2Clipboard(sResult);
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    */
		    
		    $('.hWordstatEmAll').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
			    var panel = tNode.Parent.Parent.Panel;
			    if (panel!=null)
			    {
				for (x in tNode.SelectedNodes)
				{
				    var node = tNode.SelectedNodes[x];
				    var keyword = node.Values[0];
				    
				    var tab = panel.addWordstatTab(keyword);
				    if (tab!=null)
				    {
					tab.ProcessKeyword(keyword);
				    }
				}
			    }
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    
		    $('.hShowTopYandex').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
				for (x in tNode.SelectedNodes)
				{
				    var node = tNode.SelectedNodes[x];
				    var keyword = node.Values[0];
				    window.open("http://yandex.ru/yandsearch?text=" + keyword);
				}
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    
		    $('.hShowTopRambler').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
				for (x in tNode.SelectedNodes)
				{
				    var node = tNode.SelectedNodes[x];
				    var keyword = node.Values[0];
				    window.open("http://nova.rambler.ru/search?query=" + keyword);
				}
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    
		    $('.hShowTopGoogle').bind("click", function()
		    {
			var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
				for (x in tNode.SelectedNodes)
				{
				    var node = tNode.SelectedNodes[x];
				    var keyword = node.Values[0];
				    window.open("http://www.google.ru/search?hl=ru&q=" + keyword);
				}
			}
			//$('.hCreateAdBasedOnKeywordsSelected').unbind("click");
		    });
		    
		    
		    
		    
/*
                    $(".edit-word-menu-box").hover(function()
                    {
			
			//alert('hover menu');
                        $(this).css(
                        {
                            opacity: 1
                        });
                        $(".edit-word-menu-box").show();
                    }, function()
                    {
			//alert('unhover menu');
                        $(this).css(
                        {
                            opacity: 0.7
                        });
                        //$("#edit-word-menu-box").hide();
                    })
										 STUBSTUBSTUB */ 
		    inst.initClipboard();
		    inst._initialize();
    }
    
    inst._clip;
    inst.initClipboard = function ()
    {
	// setup single ZeroClipboard object for all our elements
	//if (inst._clip == null)
	//{
	    inst._clip = new ZeroClipboard.Client();
	    inst._clip.setHandCursor( true );
	//}

	// assign a common mouseover function for all elements using jQuery
	$('.hCopyKeyword2Clipboard').mouseover( function()
	{
	    var sResult = "";
	    var tNode = inst.objCaller.ParentTreeNode;
			if (tNode !=null )
			{
			    sResult = "";
			    for (x in tNode.SelectedNodes)
			    {
				var node = tNode.SelectedNodes[x];
				var keyword = node.Values[0];
				var stat = node.Values[2];
				if (sResult.length>0)
				{
				    sResult += "\r\n";
				}
				sResult += keyword + "\t" + stat;
			    }
			    //AddKeyword2Clipboard(sResult);
			}
	    
	    // set the clip text to our innerHTML
	    //alert('ss: ' + sResult );
	    inst._clip.setText( sResult );
	    
	    // reposition the movie over our element
	    // or create it if this is the first time
	    if (inst._clip.div)
	    {
		inst._clip.receiveEvent('mouseout', null);
		inst._clip.reposition(this);
		$('ZeroClipboardMovie_1').css({ background: "#000000" });
	    }
	    else inst._clip.glue(this);
				    
	    // gotta force these events due to the Flash movie
	    // moving all around.  This insures the CSS effects
	    // are properly updated.
	    inst._clip.receiveEvent('mouseover', null);
	} );
    }



    inst.lolCheckEnabledness = function(selectedTargetsNumber)
    {
	if (selectedTargetsNumber > 3)
	{
	    //alert('disabling');
	    $('.hWordstatEmAll').hide(); //addClass("invisible");

	}
	else
	{
	    //alert('enabling');
	    $(".hWordstatEmAll").show(); //removeClass("invisible");
	}
    }
    inst.objCaller;
    
    inst.Show = function(objCaller, event, targetElementsCount)
    {
	if (targetElementsCount == null)
	{
	    targetElementsCount = 0;
	}
    	inst.objCaller = objCaller;
        var target = event.target || event.srcElement;
        
        var offset = $(target).offset();
        
        
	var intMouseY = offset.top;//event.clientY;
    	var intMouseX = offset.left//event.clientX;
    	
        //console.log(intMouseX +'/'+ intMouseY);
        
    	inst.ClearDelayedHide();
	
	    instId = inst.jq.attr('id');
	    var offset = intMouseY;
	
	    var menu_size = $(".word-icons", inst.jq).length;
	    if (menu_size > 5)
	    {
		$('#edit-word-menu-box-'+inst.Id+'').css(
		    {
			width:29*(Math.round(menu_size/2))+'px'
		    })
	    }
	
	    var correctTop = target.offsetHeight;//$('#edit-word-menu-box-'+inst.Id+'').height();
	    var correctLeft = $('#edit-word-menu-box-'+inst.Id+'').outerWidth() - target.offsetWidth;//intMouseY;
	 
	    $('#edit-word-menu-box-'+inst.Id+'').css({
		top:  intMouseY + correctTop + 'px',
		left: intMouseX - correctLeft + 'px'
	    });
	    
	    
	    
	    inst.jq.show();
	    inst.lolCheckEnabledness(targetElementsCount);
	    inst.DelayHide();
	    /*
	    setTimeout(function()
	    {
		inst.jq.show();
	    }, 1234)
	 */
		/*
		inst._clip = new ZeroClipboard.Client();
	        inst._clip.setText( 'zzz!' );
		inst._clip.glue('Clipboard' + inst.Id);
		   */
	    
    }
    inst._delayedHideTimer;
    inst.ClearDelayedHide = function()
    {
	clearTimeout(inst._delayedHideTimer);
    }
    inst.DelayHide = function()
    {
	inst.DelayedHide(1234);
    }
    inst.DelayedHide = function(intMilliseconds)
    {
	inst._delayedHideTimer = setTimeout(function()
	    {
		inst.Hide();
	    }, intMilliseconds)
    }
    inst.Hide = function()
    {
	//alert('#edit-word-menu-box-'+inst.Id+'');
	    $('#edit-word-menu-box-'+inst.Id+'').css({
			    top: '-9999px',
			    left: '-9999px'
			}).hide();

    }
    
    
    return inst;
}




function MenuKeywordShow(objNode)
{
    //alert(objNode.Values[0]);
}
    /*

	*/
function MenuKeywordCorrect()
{
    
}


function objGetStopKeywordMenuInst()
{
    var inst = objGetKeywordMenuInst();
	var code = 
        '	<div class="edit-word-menu-box" id="edit-word-menu-box-'+inst.Id+'">'
      + '		<div class="menu-design">'
      + '			<div class="edit-word-menu">'
      + '				<a class="word-icons word-icons-ico9 hDeleteStopWord" href="#" title="Удалить слово" id="delete-word">Удалить слово</a>'
      + '			</div>'
      + '		</div>'
      + '	</div>';
    inst.jq = $(code);
    inst.Initialize = function ()
    {
	//alert('stop initialized');
	$('.hDeleteStopWord').bind("click", function()
		    {
			if (inst.objCaller.Type == typeStopKeyword)
			{
			    var parentKeyword = inst.objCaller.Parent;
			    if (parentKeyword.Type == typeKeyword)
			    {
				parentKeyword.RemoveKeyword(inst.objCaller.Id);
			    }
			    else
			    {
				// STUB вставить диаг
			    }
			}
			else
			{
			    // STUB вставить диаг
			}
		    });
	inst._initialize();
    }
    return inst;
}