﻿//---------------------------------------------------------------------------------
//  (c) 2007 Guardian Networks, Inc
//---------------------------------------------------------------------------------

GNgui.GNMenuItem = Class.create();
GNgui.GNMenuItem.prototype = 
{
	initialize : function (id , Text, Top, MouseOver)
	{
		if ( id == null ) {	alert('PleaseWait: id not specified' ); }	
    
		this.newelement = $ce('div');
		this.newelement.setAttribute('id',id);
		this.newelement.style.position = 'absolute';
    this.newelement.className = "GNMenuItem";

    this.newelement.img = $ce('img');
    this.newelement.img.setAttribute('id',id+'img');
		this.newelement.img.style.position = 'absolute';
		$ac(this.newelement, this.newelement.img);
		
    this.newelement.ImageName = "topbar_nav_" + Text + ".gif";   
    this.newelement.ImageNameOver = "topbar_nav_" + Text + "_over.gif"; 
    this.newelement.ImageNameSelect = "topbar_nav_" + Text + "_on.gif";
    
    this.OBJImage = new Image;
    this.OBJImage.src = "./" + TARGET + "/images/" + this.newelement.ImageName;    
    
    this.newelement.img.src = "./" + TARGET + "/images/" + this.newelement.ImageName;

    this.newelement.img.style.top = Top;
 		this.newelement.style.zindex = 0;
 		this.newelement.menutype=0;
 		this.newelement.unselectable = true;
		this.newelement.img.alt = Text.substring(0,1).toUpperCase() + Text.substring(1);
 		this.selected = false;
 		this.IsSelectable = true;
 		this.HasSubItems = false;
 		this.ScreenName = "";
 		this.ShowSideMenu = true;
 		
 		//MenuSubItemContainer
 		
 		this.SubItemContainer = $ce('div');
 		this.SubItemContainer.setAttribute('id',id+'SubItemContainer');
 		this.SubItemContainer.className= 'GNMenuSubItemContainer NotVisible';

 		this.SubItemContainer.LastPosition = 0;
 		$ac(this.newelement,this.SubItemContainer);

 		this.SubItemContainerTable = $ce('table');
 		this.SubItemContainerTable.setAttribute('id',this.SubItemContainer.id+'SubItemContainerTable');

 		this.SubItemContainerTable.cellSpacing = 0;
 		this.SubItemContainerTable.cellPadding = 0;
 		this.SubItemContainerTable.border=0;
 		
 		$ac(this.SubItemContainer,this.SubItemContainerTable);
 		
 		if (MouseOver == 1)
 	  {
      Event.observe ( this.newelement.img , 'mouseover' , GNgui.GNMenuItem.prototype.MouseOver.bindAsEventListener(this));    
      Event.observe ( this.newelement.img , 'mouseout' ,  GNgui.GNMenuItem.prototype.MouseOut.bindAsEventListener(this));    
      Event.observe ( this.newelement.img , 'mousedown' , GNgui.GNMenuItem.prototype.MouseDown.bindAsEventListener(this));
      Event.observe ( this.newelement.img , 'mouseup' ,   GNgui.GNMenuItem.prototype.MouseUp.bindAsEventListener(this));
    }
    Event.observe ( this.newelement.img , 'click' , GNgui.GNMenuItem.prototype.MouseClick.bindAsEventListener(this));
    
    Gutenberg.Subscribe ( "MenuSelected" , GNgui.GNMenuItem.prototype.MenuSelected.bindAsEventListener(this));
  },

	ID : function()
	{
		return this.newelement.id;
	},
	
	IMGID : function()
	{
		return this.newelement.img.id;
	},
	
	PositionSubContainer : function()
  {
    $el(this.SubItemContainer.id, $el(this.newelement.img.id) + (this.OBJImage.width / 3));
  },
	
	Show : function()
	{
		this.newelement.style.visibility = 'inherit';
	},
	
	Hide : function()
	{
		//this.newelement.style.visibility = 'hidden';
	},
	
	MenuSelected : function( MenuName )
	{
	  if (RightMenu != null && MenuName != 'MenuMonitoring' && MenuName != 'MenuHelp' && MenuName != 'MenuSearch')
	  {
		  RightMenu.Hide();
	  }
	  else
	  {
		  RightMenu.Show();
	  }
	  
	  if (Permissions.CheckMenuPermissions("Monitoring Maps"))
		{
	    MapSearchMenuOptions.Hide();

	    if (MenuName != 'MenuMonitoring' && MenuName != 'MenuHelp')
	    {
			  $e('MapSearchTextBox').style.display = 'none';
			  $e('MapSearchOptions').style.display = 'none';
			  $e('MenuSearchimg').style.display = 'none';
	    }
	    else
	    {
			  $e('MapSearchTextBox').style.display = 'block';
			  $e('MapSearchOptions').style.display = 'block';
			  $e('MenuSearchimg').style.display = 'block';
	    }
	  }

	  if ( MenuName == this.newelement.id )
	  {
	    if ( this.IsSelectable )
	    {
	      this.newelement.img.src = "./" + TARGET + "/images/" + this.newelement.ImageNameSelect;
	      this.selected = true;
	    }
	  }
	  else
	  {
	    this.newelement.img.src = "./" + TARGET + "/images/" + this.newelement.ImageName;
	    this.selected = false;
  	  this.SubItemContainer.className = "GNMenuSubItemContainer NotVisible";
	  }
	},
		
	MouseOver : function()
	{
		if ( this.selected == false )
    {
	    this.newelement.img.src = "./" + TARGET + "/images/" + this.newelement.ImageNameOver;
	   }
	   
	   return false;
	},
	
	MouseOut : function()
	{
    if ( this.selected == false)
	  {
	    this.newelement.img.src = "./" + TARGET + "/images/" + this.newelement.ImageName;
	  }
   
	  return false;
	},
	
	MouseDown : function()
	{
	  this.newelement.img.src = "./" + TARGET + "/images/" + this.newelement.ImageNameSelect;
	},
	
	MouseUp : function()
	{

	},
	
	MouseClick : function ()
	{		 
	  Gutenberg.PublishNow ("MenuSelected",this.newelement.id);
	  
	  if ( this.ScreenName != "" )
	  {
	    Gutenberg.PublishNow ( "ShowScreen",this.ScreenName);
	  }
	  if ( this.OnClick != null)
	  {
  	  this.OnClick();
  	  return false;
  	}
  	
  	if ( this.HasSubItems )
  	{
  	  this.SubItemContainer.className = "GNMenuSubItemContainer Visible";

  	}
	},
	
	Selectable : function ( value)
	{
	  this.IsSelectable = value;
	},
		
	AddSubItem : function ( Text )
	{
    this.HasSubItems = true;  

	  var e = new GNgui.GNMenuSubItem(this.SubItemContainerTable.id, this.SubItemContainer.id, Text);
 		
		return e;
	},
	
	AssociateScreen : function ( ScreenName )
	{
	  this.ScreenName = ScreenName;
	}
}
