ASPxClientPopupMenu = _aspxCreateClass(ASPxClientMenuBase, {
 constructor: function(name){
  this.constructor.prototype.constructor.call(this, name);
  this.skipNextPEMouseOutBeforePEMouseOver = false; 
  this.cursorOverPopupElement  = false;
  this.isPopupMenu = true;
  this.closeAction = "OuterMouseClick";
  this.popupAction = "RightMouseClick";
  this.popupElementID = "";
  this.popupElement = null;
  this.popupHorizontalOffset = 0;
  this.popupVerticalOffset = 0;
  this.popupHorizontalAlign = __aspxNotSetAlignIndicator;
  this.popupVerticalAlign = __aspxNotSetAlignIndicator;
  this.left = 0;
  this.top = 0;
 }, 
 Initialize: function(){
  this.GetPopupElement();
  ASPxClientMenuBase.prototype.Initialize.call(this);
 },
 SetPopupElementReference: function(popupElement, attach) {
  if (!_aspxIsExistsElement(popupElement)) return;
  var setReferenceFunction = attach ? _aspxAttachEventToElement : _aspxDetachEventFromElement;
  if(_aspxIsExistsElement(popupElement)) {
   if (this.closeAction == "MouseOut" || this.popupAction == "MouseOver") {
     setReferenceFunction(popupElement, "mouseover", _aspxClientOverControlUtils.OnMouseOver);
     setReferenceFunction(popupElement, "mouseout",  _aspxClientOverControlUtils.OnMouseOut);
   }
   if(this.popupAction == "RightMouseClick")
    setReferenceFunction(popupElement, "contextmenu", aspxMEvent);
   else if(this.popupAction == "LeftMouseClick") { 
    setReferenceFunction(popupElement, "mouseup", aspxMEvent);
    setReferenceFunction(popupElement, "mousedown", aspxMEvent);
   }
   if(attach) {
    popupElement.DXPopupElementControl = this;
    this.popupElement = popupElement;
    this.popupElementID = popupElement.id;
    this.popupElement.isPopuped = false;
   } else 
    this.popupElement = popupElement.DXPopupElementControl = undefined; 
  }   
 },
 AttachToPopupElement: function(newPopupElementId) {
  var oldPopupElementId = this.popupElementID;
  var popupElementId = _aspxIsExists(newPopupElementId) ? newPopupElementId : this.popupElementID;
  var popupElement = _aspxFindPopupElementById(popupElementId);
  if(popupElementId != oldPopupElementId) 
   if(this.closeAction == "MouseOut") {      
      aspxGetMenuCollection().ClearDisappearTimer();
      aspxGetMenuCollection().DoHidePopupMenus(null, -1, "", false, "");
   }
  this.SetPopupElementReference(popupElement, true);  
 },
 DetachFromPopupElement: function() {
  this.SetPopupElementReference(this.popupElement, false);
 },
 GetPopupElement: function(){
  if(!_aspxIsExistsElement(this.popupElement)){
   this.AttachToPopupElement();
  }
  return this.popupElement;
 },
 IsMenuVisible: function(){
  var element = this.GetMainElement();
  return (element != null) ? _aspxGetElementDisplay(element) : false;
 },
 IsParentElementPositionStatic: function(indexPath){
  return false;
 },
 GetClientSubMenuPos: function(element, indexPath, pos, isXPos){
  if (indexPath == "") {
   var popupPosition = null;
   if (isXPos){
    popupPosition = _aspxGetPopupAbsoluteX(this.GetMenuMainCell(this.GetMainElement()),
     __aspxPopupShadowWidth, this.GetPopupElement(), this.popupHorizontalAlign, this.popupHorizontalOffset, pos, this.left);
   }
   else{
    popupPosition = _aspxGetPopupAbsoluteY(this.GetMenuMainCell(this.GetMainElement()), 
     __aspxPopupShadowHeight, this.GetPopupElement(), this.popupVerticalAlign, this.popupVerticalOffset, pos, this.top);
   }
   popupPosition.position -= _aspxGetPositionElementOffset(element, isXPos);
   return popupPosition;
  }
  return ASPxClientMenuBase.prototype.GetClientSubMenuPos.call(this, element, indexPath, pos, isXPos);
 },
 GetMenuElement: function(indexPath){
  if (indexPath == "")
   return this.GetMainElement();
  return ASPxClientMenuBase.prototype.GetMenuElement.call(this, indexPath);
 },
 OnItemOverTimer: function(indexPath){
  aspxGetMenuCollection().ClearCurrentShowingPopupMenuName();
  if(indexPath == ""){
   aspxGetMenuCollection().DoHidePopupMenus(null, -1, this.name, false, "");
   aspxGetMenuCollection().DoShowAtCurrentPos(this.name, indexPath);
  }
  else
   ASPxClientMenuBase.prototype.OnItemOverTimer.call(this, indexPath);
 },
 DoShow: function(x, y){
  var element = this.GetMainElement();
  if(element != null && !_aspxGetElementDisplay(element)){
   aspxGetMenuCollection().DoHidePopupMenus(null, -1, this.name, false, "");
   this.DoShowPopupMenu(element, x, y, "");
  }
 },
 DoShowByAPI: function(x, y){
  var enableAnimationBackup = this.enableAnimation;
  this.enableAnimation = false;
  this.DoShow(x, y);
  this.enableAnimation = enableAnimationBackup;
 },
 WrongEventOrderOperaHack: function(){
  this.skipNextPEMouseOutBeforePEMouseOver = true;
 },
 WrongEventOrderOperaRollBack: function(){
  this.skipNextPEMouseOutBeforePEMouseOver = false;
 },
 OnAfterItemOver: function(hoverItem, hoverElement) {
  var afterItemOverAllowed = ASPxClientMenuBase.prototype.AfterItemOverAllowed(this, hoverItem);
  if(afterItemOverAllowed) {
   this.WrongEventOrderOperaHack();
   ASPxClientMenuBase.prototype.OnAfterItemOver.call(this, hoverItem, hoverElement); 
  }
 },
 OnPopupElementMouseOver: function(evt, popupElement) {
   if (popupElement != null) {
   this.cursorOverPopupElement  = true;
   this.WrongEventOrderOperaRollBack();
   if(this.popupAction == "MouseOver")
    if(!this.IsMenuVisible()) { 
     aspxGetMenuCollection().SetCurrentShowingPopupMenuName(this.name);
     this.ShowInternal(evt);
    }
   }
 },
 OnPopupElementMouseOut: function(evt, popupElement) {
   if (popupElement != null) {
   aspxGetMenuCollection().ClearCurrentShowingPopupMenuName();
   this.cursorOverPopupElement = false; 
   if(!this.IsMenuVisible()) 
    aspxGetMenuCollection().ClearAppearTimer();
   else if (!this.skipNextPEMouseOutBeforePEMouseOver) 
    this.SetDisappearTimer();
   }
 },
 DoHidePopupMenu: function(evt, element){
  if ((__aspxNetscapeFamily || __aspxWebKitFamily) && _aspxIsExists(evt) && this.GetPopupElement() != null 
   && _aspxIsExists(this.GetPopupElement().isPopuped)){
   if (_aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupMenuElement) == this.GetPopupElement()) {
    this.GetPopupElement().isPopuped = true;
   }
  }
  ASPxClientMenuBase.prototype.DoHidePopupMenu.call(this, evt, element);
 },
 DoShowPopupMenuBorderCorrector: function(element, x, y, indexPath, toTheLeft, toTheTop){
  if (indexPath != "")
   ASPxClientMenuBase.prototype.DoShowPopupMenuBorderCorrector.call(this, element, x, y, indexPath, toTheLeft, toTheTop);
 },
 ShowInternal: function(evt){
  var x = _aspxGetEventX(evt);
  var y = _aspxGetEventY(evt);
  if (evt.type == "mouseover")
   aspxGetMenuCollection().SetAppearTimer(this.name, "", this.appearAfter);
  else
   this.DoShow(x, y);
 },
 GetAnimationHorizontalDirection: function(indexPath, popupPosition){
  if (this.GetMenuLevel(indexPath) == 0)
   return _aspxGetAnimationHorizontalDirection(popupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
  else 
   return popupPosition.isInverted ? 1 : -1;
 },
 GetAnimationVerticalDirection: function(indexPath, popupPosition){
  if (this.GetMenuLevel(indexPath) == 0)
   return _aspxGetAnimationVerticalDirection(popupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
  else 
   return 0;
 },
 OnHideByItemOut: function(){
  if(this.closeAction == "MouseOut" && !this.cursorOverPopupElement)
   aspxGetMenuCollection().DoHidePopupMenus(null, -1, this.name, false, "");
  else
   ASPxClientMenuBase.prototype.OnHideByItemOut.call(this);
 },
 ReplacePopupElementID: function(newPopupElementID){
  var popupElementIDBackup = this.popupElementID;
  this.popupElementID = newPopupElementID;
  this.popupElement = null;
  this.GetPopupElement();
  return popupElementIDBackup;
 },
 SetPopupElementID: function(popupElementId) {
  if(popupElementId != this.popupElementID) {
   this.DetachFromPopupElement();
   this.AttachToPopupElement(popupElementId);
   this.WrongEventOrderOperaRollBack();
  }
 },
 RefreshPopupElementConnection: function(){
  this.AttachToPopupElement();   
 },
 Hide: function(){
  var element = this.GetMainElement();
  if(element != null) this.DoHidePopupMenu(null, element);
 },
 Show: function(){
  this.DoShowByAPI(__aspxInvalidPosition, __aspxInvalidPosition);
 },
 ShowAtElement: function(htmlElement){
  var popupElementBackup = this.popupElement;
  this.popupElement = htmlElement;
  this.DoShowByAPI(__aspxInvalidPosition, __aspxInvalidPosition);
  this.popupElement = popupElementBackup;
 },
 ShowAtElementByID: function(id){
  var htmlElement = document.getElementById(id);
  this.ShowAtElement(htmlElement);
 },
 ShowAtPos: function(x, y){
  var popupElementIDBackup = this.ReplacePopupElementID("");
  this.DoShowByAPI(x, y);
  this.ReplacePopupElementID(popupElementIDBackup);
 },
 GetVisible: function(){
  return this.IsMenuVisible();
 },
 SetVisible: function(visible){
  if(visible && !this.IsMenuVisible())
   this.Show();
  else if(!visible && this.IsMenuVisible())
   this.Hide();
 }
});
ASPxClientPopupMenu.Cast = ASPxClientControl.Cast;
function aspxMEvent(evt){
 var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupMenuElement);
 if(element != null) 
  if (evt.type == "mousedown")
   return aspxPMOnMouseDown(evt, element);
  else
   return aspxPMOnMouseUp(evt, element);
}
function aspxPMOnMouseDown(evt, element){
 if (!__aspxNetscapeFamily && !__aspxWebKitFamily && _aspxIsExists(element.isPopuped))
  element.isPopuped = element.DXPopupElementControl.IsMenuVisible();
}
function aspxPMOnMouseUp(evt, element){
 if (element.DXPopupElementControl.popupAction=="RightMouseClick" || _aspxGetIsLeftButtonPressed(evt)) {
  if (element.DXPopupElementControl.popupAction=="RightMouseClick")
   _aspxPreventContextMenu(evt);
  if (element.isPopuped != true)
   element.DXPopupElementControl.ShowInternal(evt);
  else if ((__aspxNetscapeFamily || __aspxWebKitFamily) && _aspxIsExists(element.isPopuped))
   element.isPopuped = false;
  return _aspxCancelBubble(evt);
 }
}
function aspxTestPopupMenuElement(element){
 return _aspxIsExists(element.DXPopupElementControl);
}
_aspxAttachEventToDocument("mousemove", aspxPopupMenuDocumentMouseMove);
function aspxPopupMenuDocumentMouseMove(evt){
 var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupMenuElement);
 if(element != null)
  aspxGetMenuCollection().SaveCurrentMouseOverPos(evt, element);
}

